Skip to content

test(air): fix flaky TestSyncEmails_DoesNotHoldRuntimeLockAcrossFetch CI failure#120

Open
qasim-nylas wants to merge 1 commit into
mainfrom
tw-5785-fix-flaky-syncemails-test
Open

test(air): fix flaky TestSyncEmails_DoesNotHoldRuntimeLockAcrossFetch CI failure#120
qasim-nylas wants to merge 1 commit into
mainfrom
tw-5785-fix-flaky-syncemails-test

Conversation

@qasim-nylas

Copy link
Copy Markdown
Collaborator

What

Bumps the completion deadline in TestSyncEmails_DoesNotHoldRuntimeLockAcrossFetch from 20s → 90s (internal/air/handlers_email_cache_runtime_test.go:598).

Why

The test starts syncEmails in a goroutine, verifies the runtime lock is not held across the remote fetch (via the lockReleased probe), then waits for the goroutine to finish. That final wait raced a hard-coded 20s wall-clock deadline.

Under the full go test ./... -race suite on a saturated GitHub runner (keyring ~96s, nylas ~120s, air/cache ~24s all overlapping under the race detector's ~10x slowdown), the post-fetch sync goroutine gets CPU-starved past 20s, so the timer fired and failed the test — even though the sync completes correctly. It reproduced twice on post-merge main CI (run 1, run 2) then passed on retry with zero code changes — classic load-dependent flake. Locally it finishes in ~3s.

The fix

The test's real assertion (lock not held across the fetch) is already verified earlier by lockReleased — that passed in both failures. The deadline only exists to reap the goroutine before cleanup closes the cache DB. Bumping to 90s gives ~30x headroom over the real ~3s runtime, well clear of any realistic runner starvation.

Testing

  • go test ./internal/air/ -run TestSyncEmails_DoesNotHoldRuntimeLockAcrossFetch -race — passes (~3.4s).

Related docs

None — test-only change, no user-facing command, flag, or behavior is affected.

TestSyncEmails_DoesNotHoldRuntimeLockAcrossFetch raced a 20s wall-clock
deadline against the post-fetch sync goroutine finishing. Under the full
-race suite on a saturated CI runner the goroutine gets starved past 20s,
so the timer fired and failed the test even though the sync completes
correctly (~3s locally). The test's real assertion (lock not held across
the fetch) is verified earlier via the lockReleased probe; this deadline
only reaps the goroutine before cleanup. Bump to 90s for headroom.
@qasim-nylas qasim-nylas requested a review from AaronDDM July 10, 2026 13:04

@AaronDDM AaronDDM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants