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:
committed by
GitHub
parent
c6556d1256
commit
9d9d0397a8
@@ -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`
|
||||
)
|
||||
}
|
||||
|
||||
@@ -872,6 +872,8 @@ medusaIntegrationTestRunner({
|
||||
}),
|
||||
])
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
|
||||
const { result: fullOrder } = await getOrderDetailWorkflow(
|
||||
appContainer
|
||||
).run({
|
||||
|
||||
@@ -112,15 +112,15 @@ medusaIntegrationTestRunner({
|
||||
testSuite: ({ getContainer, dbConnection, api, dbConfig }) => {
|
||||
let appContainer
|
||||
|
||||
beforeAll(() => {
|
||||
appContainer = getContainer()
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
process.env.ENABLE_INDEX_MODULE = "false"
|
||||
})
|
||||
|
||||
describe("Index engine - Query.index", () => {
|
||||
beforeAll(() => {
|
||||
appContainer = getContainer()
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
process.env.ENABLE_INDEX_MODULE = "false"
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
})
|
||||
@@ -134,7 +134,7 @@ medusaIntegrationTestRunner({
|
||||
name: "Medusa Brand",
|
||||
})
|
||||
|
||||
await link.create({
|
||||
const [createdLink] = await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: products.find((p) => p.title === "Extra product").id,
|
||||
},
|
||||
@@ -166,6 +166,14 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
),
|
||||
waitForIndexedEntities(dbConnection, "Brand", [brand.id]),
|
||||
waitForIndexedEntities(
|
||||
dbConnection,
|
||||
"ProductProductBrandBrand",
|
||||
[createdLink.id],
|
||||
{
|
||||
isLink: true,
|
||||
}
|
||||
),
|
||||
])
|
||||
|
||||
const resultset = await fetchAndRetry(
|
||||
@@ -584,7 +592,7 @@ medusaIntegrationTestRunner({
|
||||
name: "Medusa Brand",
|
||||
})
|
||||
|
||||
await link.create({
|
||||
const [createdLink] = await link.create({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id: products.find((p) => p.title === "Extra product").id,
|
||||
},
|
||||
@@ -616,6 +624,14 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
),
|
||||
waitForIndexedEntities(dbConnection, "Brand", [brand.id]),
|
||||
waitForIndexedEntities(
|
||||
dbConnection,
|
||||
"ProductProductBrandBrand",
|
||||
[createdLink.id],
|
||||
{
|
||||
isLink: true,
|
||||
}
|
||||
),
|
||||
])
|
||||
|
||||
const resultset = await fetchAndRetry(
|
||||
@@ -636,6 +652,7 @@ medusaIntegrationTestRunner({
|
||||
waitSeconds: 1.5,
|
||||
}
|
||||
)
|
||||
|
||||
expect(resultset.data.length).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user