Skip to content

Shadow: ✅ improve E2E test reliability on BrowserStack (v1)#89

Open
allspain wants to merge 3 commits into
shadow/4494/v1-basefrom
shadow/4494/v1
Open

Shadow: ✅ improve E2E test reliability on BrowserStack (v1)#89
allspain wants to merge 3 commits into
shadow/4494/v1-basefrom
shadow/4494/v1

Conversation

@allspain
Copy link
Copy Markdown
Owner

Shadow Review — PR #4494 v1

Source: DataDog/browser-sdk#4494
Commit: 6ad64642884f006f2e99e172679f051209bb4eb9
Timestamp: 2026-04-16T15:07:52Z


Original PR Description

Motivation

E2E tests running on BrowserStack have been flaky due to high network latency between the remote browser and the local test server. Several issues compounded this:

  • The idle wait duration was fixed at 500ms regardless of actual latency, causing waitForServersIdle() to return before all requests had arrived
  • Requests sent by the browser could still be in-flight when waitForServersIdle() was called, making it return immediately despite pending network activity
  • The browser was issuing spurious /favicon.ico requests that added noise to server idle tracking

Changes

  • Measure browser-to-server latency once per worker before tests run, and use Math.max(500, latency * 1.5) as the idle wait duration
  • waitForServersIdle() now waits idleWaitDuration ms upfront to let in-flight requests arrive before checking idle state
  • Add a dedicated /flush route (replaces /ok?duration=200) that delays 200ms and returns HTML — used when navigating away to flush SDK events, including session replay Web Worker segments
  • Suppress spurious /favicon.ico requests by embedding an empty favicon in all test pages
  • Skip redundant flushEvents() in teardown when the page is already on /flush
  • Stop the CI test run after the first failure (post-retries) to save time

Test instructions

Run the E2E tests on BrowserStack and verify that previously flaky tests pass consistently.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

In BrowserStack, the browser runs remotely and the round-trip latency to
the test server can be significant. A fixed idle wait duration may not be
sufficient to catch all in-flight requests. We now measure the latency
once per worker before tests run and use `Math.max(500, latency * 1.5)`
as the idle wait duration.
…avicon requests

- waitForServersIdle() now waits idleWaitDuration ms before checking idle
  state, so in-flight browser requests have time to reach the server before
  idle is declared
- replace /ok?duration=200 with a dedicated /flush route that delays 200ms
  and returns HTML with an empty favicon, preventing spurious favicon requests
  during event flushing
- skip teardown flushEvents() when already on /flush to avoid redundant work
- add empty favicon link to all test pages to suppress /favicon.ico requests
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