Skip to content

chore: Wait for pending NAPI invokes before cleaning up test fixtures - #356

Open
Ziinc wants to merge 1 commit into
mainfrom
claude/unhandled-db-error-tests-4qg8zq
Open

chore: Wait for pending NAPI invokes before cleaning up test fixtures#356
Ziinc wants to merge 1 commit into
mainfrom
claude/unhandled-db-error-tests-4qg8zq

Conversation

@Ziinc

@Ziinc Ziinc commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes a race condition in integration tests where fixture directories were being deleted while asynchronous NAPI invoke() calls were still in flight, causing unhandled rejection errors.

Key Changes

  • Added pendingInvokes counter and waitForPendingInvokes() function to track in-flight NAPI calls in test/setup.integration.ts
  • Modified the mocked invoke() function to increment/decrement the pending counter and notify when all calls settle
  • Updated afterAll() cleanup in test/utils.tsx to wait for all pending invokes to complete before deleting fixture directories

Implementation Details

  • The counter tracks NAPI invocations that haven't yet resolved or rejected
  • A callback mechanism (onAllSettled) allows cleanup code to be notified when the pending count reaches zero
  • The waitForPendingInvokes() function includes a 5-second timeout to prevent tests from hanging indefinitely
  • This addresses the issue where UI polling operations (e.g., sidebar workspace-status fetch) continue running after test completion and attempt to access deleted database files
    https://claude.ai/code/session_01R26mLwvqdKS9chdR9iDmQZ

Fixture-copy directories were being removed in afterAll once all tests in
a file finished, but nothing waited for the underlying invoke() calls to
actually settle first. A component's untracked background fetch (e.g. the
workspace sidebar's status poll) can still be reading a repo's local.db
after its test finishes, so deleting the directory too early makes that
call reject with an "unable to open database file" error nothing catches
anymore -- an unhandled rejection (seen in discard-changes.test.tsx).

Track pending invoke() calls in the test harness and drain them before
cleanup removes the directories.
@Ziinc Ziinc changed the title Wait for pending NAPI invokes before cleaning up test fixtures chore: Wait for pending NAPI invokes before cleaning up test fixtures Aug 26, 2026
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