Skip to content

test(index): stabilize flaky enum-filter query.index integration test#16120

Open
arhxam wants to merge 1 commit into
medusajs:developfrom
arhxam:fix/flaky-index-enum-filter-test
Open

test(index): stabilize flaky enum-filter query.index integration test#16120
arhxam wants to merge 1 commit into
medusajs:developfrom
arhxam:fix/flaky-index-enum-filter-test

Conversation

@arhxam

@arhxam arhxam commented Jul 19, 2026

Copy link
Copy Markdown

Summary

What — What changes are introduced in this PR?

Stabilizes the intermittently-failing integration test integration-tests/modules/__tests__/index/query-index.spec.tsIndex engine - Query.index › should use query.index to filter enum field by aligning its final query retry budget with the index-sync wait budget already used in the same test.

Why — Why are these changes relevant or necessary?

This test fails intermittently on develop with the retry helper's Validation failed. Retry..., which intermittently blocks unrelated PRs (see #15967, e.g. the approved/automerge-labeled #15856). It is a test-side index-sync race under CI load, not a product bug.

Root cause: the productbrand link is created after the products have already been indexed, which triggers an asynchronous re-index of the linked product. waitForIndexedEntities(...) only waits for the Brand and ProductProductBrandBrand (link) rows to be replicated — it does not wait for that product re-index to be reflected in the catalog. Unlike the sibling brand test (should use query.index to query the index module and hydrate the data), whose filter has an $or fallback on title and can therefore return rows even before the link is queryable, this test's filter (status: "published" + brand: { status: "active" }) strictly depends on the link being queryable. So query.index returns an empty set until the re-index lands. Under CI load that window can exceed the previous 7.5s retry budget (retries: 5 × waitSeconds: 1.5), causing the flake.

How — How have these changes been implemented?

Bumped only this test's fetchAndRetry budget from { retries: 5, waitSeconds: 1.5 } (7.5s) to { retries: 10, waitSeconds: 3 } (30s) so the query retry window matches the 30s waitForIndexedEntities timeout used elsewhere in the same test, and added a comment documenting the race. No production code is touched.

Testing — How have these changes been tested, or how can the reviewer test the feature?

Test-only change. It extends the retry window for a query that is already expected to eventually succeed, so it cannot mask a real regression — the assertions (resultset.data.length === 1) are unchanged. Reviewers can run:

yarn jest integration-tests/modules/__tests__/index/query-index.spec.ts -t "filter enum field"


Checklist

  • I have added a changeset for this PR — not applicable: this is a test-only change and does not result in a new version of Medusa (per CONTRIBUTING).
  • The changes are covered by relevant tests — this change stabilizes the existing test.
  • I have verified the change is consistent with the sibling tests in the same file.

Fixes #15967

The "should use query.index to filter enum field" test intermittently
fails on develop with the retry helper's "Validation failed. Retry...",
blocking unrelated PRs.

The product<->brand link is created after the products are already
indexed, so it triggers an asynchronous re-index of the linked product.
waitForIndexedEntities only waits for the brand and link rows, not for
that product re-index to be reflected in the catalog. Unlike the sibling
brand test (whose filter has an OR title fallback), this filter strictly
depends on the link being queryable, so it returns an empty set until the
re-index lands. Under CI load that window can exceed the 7.5s retry
budget (5 x 1.5s). Align the budget with the 30s waitForIndexedEntities
timeout used in the same test.

Fixes medusajs#15967
@arhxam
arhxam requested a review from a team as a code owner July 19, 2026 02:11
@changeset-bot

changeset-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ac69287

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@medusa-os-bot

medusa-os-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

Thanks for the contribution! Initial automated review looks good.

Test-only change (1 file, 14 lines) that raises the fetchAndRetry budget for the enum-filter query.index test from 7.5s to 30s to match the 30s waitForIndexedEntities default (verified in integration-tests/helpers/wait-for-index.ts), addressing an index-sync race under CI load. PR template is complete; assertions are unchanged so it cannot mask a regression. No production code touched, and no security/perf/bug concerns. Missing changeset is acceptable for a test-only change. The explanatory comment does not embed an issue/PR number.

Triggered by: new PR opened

@shahednasser

Copy link
Copy Markdown
Member

Thank you for your contribution @arhxam but there's another flaky test that you can see on your PR (see here). Can you fix that as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky test: query-index.spec.ts "filter enum field" fails intermittently on develop

2 participants