fix(): Index integration tests flackyness (#13953)
* fix(): Index integration tests flackyness * fix * Create twenty-eels-remain.md * fix * fix * fix * fix * finalize * finalize * finalize * finalize * finalize * finalize * chore: empty commit * finalize * finalize * chore: empty commit * finalize * finalize
This commit is contained in:
1 parent
c6556d1256
commit
9d9d0397a8
14 files changed
+112
-89
No files matched your search
@@ -6,6 +6,7 @@
|
||||
export interface WaitForIndexOptions {
|
||||
timeout?: number
|
||||
pollInterval?: number
|
||||
isLink?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,19 +19,22 @@ export async function waitForIndexedEntities(
|
||||
entityIds: string[],
|
||||
options: WaitForIndexOptions = {}
|
||||
): Promise<void> {
|
||||
const { timeout = 120000, pollInterval = 100 } = options
|
||||
const { timeout = 30000, pollInterval = 250 } = options
|
||||
const startTime = Date.now()
|
||||
|
||||
// Normalize the entity name to match partition table naming convention
|
||||
const normalizedName = entityName.toLowerCase().replace(/[^a-z0-9_]/g, "_")
|
||||
const normalizedName = !options.isLink
|
||||
? entityName.toLowerCase().replace(/[^a-z0-9_]/g, "_")
|
||||
: `link${entityName.toLowerCase()}`
|
||||
const partitionTableName = `cat_${normalizedName}`
|
||||
const normalizedEntityName = options.isLink ? `Link${entityName}` : entityName
|
||||
|
||||
while (Date.now() - startTime < timeout) {
|
||||
try {
|
||||
// Query the index_data table to check if all entities are indexed
|
||||
const result = await dbConnection.raw(
|
||||
`SELECT id FROM index_data WHERE name = ? AND id = ANY(?) AND staled_at IS NULL`,
|
||||
[entityName, entityIds]
|
||||
`SELECT id FROM index_data WHERE id = ANY(?) AND staled_at IS NULL`,
|
||||
[entityIds]
|
||||
)
|
||||
|
||||
const indexedIds = result.rows
|
||||
@@ -62,15 +66,15 @@ export async function waitForIndexedEntities(
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
// Continue polling on database errors
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, pollInterval))
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
console.error(
|
||||
`Entities [${entityIds.join(
|
||||
", "
|
||||
)}] of type '${entityName}' were not fully replicated to partition table within ${timeout}ms`
|
||||
)}] of type '${normalizedEntityName}' were not fully replicated to partition table within ${timeout}ms`
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user