Skip to content

fix: enhance removeAbortFilter to handle late async abort events in CI#27732

Merged
cmd-ob merged 1 commit into
mainfrom
fix/ci-abort-adb
Mar 20, 2026
Merged

fix: enhance removeAbortFilter to handle late async abort events in CI#27732
cmd-ob merged 1 commit into
mainfrom
fix/ci-abort-adb

Conversation

@cmd-ob

@cmd-ob cmd-ob commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes two recurring CI failures affecting Android and iOS E2E smoke suites.

Fix 1: Mockttp Aborted errors failing tests after filter removal

Root cause: CI logs showed abort events firing ~180ms after removeAbortFilter() was called and Jest's original handlers
were restored:

17:47:54.898 Abort filter removed — suppressed 0 mockttp "Aborted" error(s)
17:47:55.082 Aborted at IncomingMessage.failWithAbortError ← 184ms later

The existing 500ms drain inside stop() did not help because it runs before removeAbortFilter(). On loaded CI runners (4 CPUs
at 100%), the Node.js event loop delays abort events from destroyed sockets beyond the drain window. By the time
removeAbortFilter() restored Jest's handlers, the queued events fired straight into Jest as test failures.

Fix: removeAbortFilter() is now async and waits 500ms before restoring Jest's handlers (MockServerE2E.ts).
withFixtures now awaits the call (FixtureHelper.ts). Abort events observed at up to ~200ms fire during the 500ms hold window
and are suppressed by the still-active filter.

Fix 2: Android adb: device 'emulator-XXXX' not found crashing tests

Root cause: On CI, emulators occasionally go offline between tests (still booting, brief crash-recovery).
setupAndroidPortForwarding had no retry logic — any adb reverse failure was immediately rethrown, propagating through
startResourceWithRetryhandleLocalNodeswithFixtures and killing the test before it started.

Failed to set up Android port forwarding for anvil:
adb: device 'emulator-10342' not found
Failed to start anvil after 0 attempts
Error in withFixtures: Command failed: adb -s emulator-10342 reverse tcp:8545 tcp:55324

Fix: setupAndroidPortForwarding now retries up to 3 times (2s apart) when the error indicates the device is transiently
unreachable (not found, device offline, unauthorized). Persistent failures still fail the test after exhausting retries.

Files changed

File Change
tests/api-mocking/MockServerE2E.ts removeAbortFilter() made async with 500ms pre-restore delay
tests/framework/fixtures/FixtureHelper.ts await mockServerInstance.removeAbortFilter()
tests/framework/fixtures/FixtureUtils.ts Retry loop (3×, 2s) in setupAndroidPortForwarding for device-offline errors

Changelog

CHANGELOG entry:

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Medium risk because it changes E2E fixture cleanup timing (adds an awaited 500ms delay) and introduces retry behavior around adb reverse, which can mask persistent device issues if misclassified but is limited to specific error strings and test infrastructure.

Overview
Reduces flaky E2E CI failures by making MockServerE2E.removeAbortFilter() async and delaying restoration of Jest handlers by 500ms, then updating withFixtures cleanup to await it so late mockttp "Aborted" events don’t fail tests.

Improves Android stability by adding a 3-attempt (2s backoff) retry loop around adb reverse in setupAndroidPortForwarding when devices are transiently unreachable (e.g., "not found"/"device offline"/"unauthorized"), while keeping non-transient failures fatal.

Written by Cursor Bugbot for commit e136696. This will update automatically on new commits. Configure here.

@cmd-ob cmd-ob requested a review from a team as a code owner March 20, 2026 11:52
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-qa QA team label Mar 20, 2026
@github-actions github-actions Bot added size-M risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeConfirmations, SmokeWalletPlatform, SmokeAccounts, SmokeNetworkAbstractions, SmokeTrade, SmokeRamps
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 82%
click to see 🤖 AI reasoning details

E2E Test Selection:

The three changed files are all E2E test infrastructure/framework files — no app code is modified:

  1. MockServerE2E.ts: removeAbortFilter() made async with a 500ms hold to suppress late abort events that fire after cleanup on CI. This prevents spurious test failures from async socket teardown.

  2. FixtureHelper.ts: Updated to await the now-async removeAbortFilter() — a correctness fix ensuring cleanup properly waits.

  3. FixtureUtils.ts: setupAndroidPortForwarding() refactored to add retry logic (3 attempts, 2s delay) for transient adb reverse failures when the Android emulator is still initializing on CI. The functional behavior is unchanged on success paths.

These changes affect the withFixtures() test harness which is the foundation for virtually all E2E tests. The changes are stabilizing fixes (reducing flakiness), not behavioral changes to app code. However, since they touch shared infrastructure:

  • The async change to removeAbortFilter() could theoretically cause test hangs if the Promise doesn't resolve
  • The retry logic in setupAndroidPortForwarding() adds delays that could affect test timing on Android

A representative cross-section of test tags is selected to validate the framework changes work correctly across different test scenarios (confirmations, wallet platform, accounts, network, trade, ramps). This covers tests that use MockServer, Android port forwarding, and the full withFixtures lifecycle. Tags like SmokeNetworkExpansion, SmokeMultiChainAPI, SmokeIdentity, SmokePerps, SmokePredictions, SmokeCard, and FlaskBuildTests are omitted as they are more specialized and the infrastructure changes are not specific to their flows.

Performance Test Selection:
These changes are purely to E2E test infrastructure (MockServerE2E, FixtureHelper, FixtureUtils). No app code, UI components, controllers, state management, or rendering logic was modified. There is no performance impact on the app itself.

View GitHub Actions results

@cmd-ob cmd-ob added no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed no changelog required No changelog entry is required for this change labels Mar 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
16 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown

@cmd-ob cmd-ob enabled auto-merge March 20, 2026 12:30
@cmd-ob cmd-ob added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit 4a96b6e Mar 20, 2026
128 of 132 checks passed
@cmd-ob cmd-ob deleted the fix/ci-abort-adb branch March 20, 2026 12:51
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 20, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no changelog required No changelog entry is required for this change no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-qa QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants