fix: isolate maintenance handler test filesystem state#1703
Open
toddhainsworth wants to merge 1 commit into
Open
fix: isolate maintenance handler test filesystem state#1703toddhainsworth wants to merge 1 commit into
toddhainsworth wants to merge 1 commit into
Conversation
Resolve MAINTENANCE_FILE_PATH lazily and give each test suite its own temp directory so parallel Jest workers no longer race on a shared maintenance file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
graphql-mesh-server's maintenance handler tests are flaky. They surfaced in the release workflow run #26996333785, wherewhitelist.test.ts › should handle GET methodreturned{ whitelist: [] }instead of the seeded allowlist. A re-run of that same workflow now passes — confirming it was non-deterministic, not a real regression.Root cause
jest.mock-env.tssetsMAINTENANCE_FILE_PATH = cwd()for every suite, andlib/file.tsreads/writes${MAINTENANCE_FILE_PATH}/maintenance.{enabled,disabled}. Sowhitelist.test.tsandmaintenance.test.tsoperate on one shared file. Jest runs test files in parallel workers, so theirbeforeEachblocks (eachrmSync+ rewrite the file) race across processes:whitelistwrites the file with the seeded allowlistmaintenance(other worker) removes it and recreates it as{ whitelist: [], sites: ... }whitelist's GET reads the file → empty → assertion failsA torn read (one worker reading mid-write by the other) is a second signature of the same race.
Fix
lib/file.tsnow resolvesMAINTENANCE_FILE_PATHlazily (getPaths()) instead of freezing it into module-levelconsts at import time, so each suite can point it at its own directory. It also throws a clear error if the path is unset rather than silently writing toundefined/maintenance.*.whitelist.test.tsandmaintenance.test.tseach create a uniquemkdtempSyncdirectory and setMAINTENANCE_FILE_PATHto it;afterAllremoves it. No shared state between suites.lib/file.test.tslocks in lazy resolution + directory isolation as a regression guard.Verification
nx lint graphql-mesh-server: clean.Includes a patch changeset for
@aligent/cdk-graphql-mesh-server.