sentry-react-native: Detox tests timing out after setting up Performance Monitoring

Environment

How do you use Sentry? sentry.io

Which SDK and version? "@sentry/react-native": "^3.1.1"

Steps to Reproduce

  1. Following instructions for Performance Monitoring
  2. Run tests on debug/release

App

function App() {
  return (
    <Provider store={store}>
      <ProviderApp />
    </Provider>
  );
}

export default wrap(App);

Config

export const ReactNavigationInstrumentation = new Sentry.ReactNavigationInstrumentation({
  routeChangeTimeoutMs: 20000,
});

if (!disableSentry) {
  Sentry.init({
    dsn: process.env.SENTRY_DSN,
    environment: process.env.ENV,
    enableNative: process.env.JEST || disableSentry ? false : true,

    autoSessionTracking: true,
    enableAutoSessionTracking: true,
    sessionTrackingIntervalMillis: 10000,
    integrations: [
      new Sentry.ReactNativeTracing({
        idleTimeout: 5000,
        routingInstrumentation: ReactNavigationInstrumentation,
        tracingOrigins: ['localhost', /^\//, /^https:\/\//],
      }),
    ],
    tracesSampleRate: 0.2, // maybe set this to 100% if __DEV__
  });
}

Expected Result

Tests should pass.

Actual Result

detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] WARN:  [PENDING_REQUESTS] The app has not responded to the network requests below:
  (id = 80) invoke: {"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxAssertion"},"method":"assertMatcher","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"androidx.test.espresso.Espresso"},"method":"onView","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForTestId","args":["email-signin-input"]}}]}},{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForSufficientlyVisible","args":[]}}]}

That might be the reason why the test "My Apps Tests Test using common interface" has timed out.

detox[36483] INFO:  My Apps Tests: Test using common interface [FAIL]

detox[36483] INFO:  [APP_STATUS] App synchronization debug: 
The app is busy, due to: 
         - Enqueued timers
detox[36483] ERROR: [Client.js/ERROR] The pending request #-49642 ("cleanup") has been rejected due to the following error:

The tester has not received a response within 5000ms timeout to the message:

Cleanup {
  type: 'cleanup',
  params: [Object],
  messageId: -49642
}
 FAIL  __tests__/e2e/tests/NavBarTest.tv.e2e.ts (400.848 s)

Tests work if the config is commented out

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I had the same issue. This is because performance tracing sets up a timer mechanism to measure the users behaviour, which breaks the sync mechanism of detox.

What helped me was to conditionally disable the tracing integration on JS side like this:

Sentry.init({
    dsn: ***,
    tracesSampleRate: 0.2,
    environment: __DEV__ ? 'dev' : 'prod',
    enableAutoSessionTracking: true,
    enableNative: process.env.JEST_WORKER_ID ? false : true,
    integrations: __DEV__
      ? undefined
      : [
          new Sentry.ReactNativeTracing({
            idleTimeout: 5000,
            routingInstrumentation,
            tracingOrigins: ['localhost', /^\//, /^https:\/\//],
        ],
  });

I think this is the right solution as you typically would not want tracing in your e2e tests or dev build.

I solved this by disabling stall tracking. You can do so conditionally if you only run tests locally (but ideally this is bound to some other environment variable):

Sentry.init({
  // ...
  integrations:       [
    new Sentry.ReactNativeTracing({
      // ...
      // Disable stall tracking while testing
      // https://github.com/wix/Detox/blob/master/docs/Troubleshooting.Synchronization.md#settimeout-and-setinterval
      // (Sentry will call setTimeout(checkIfStalled, 0) causing Detox to wait forever
      enableStallTracking:        !__DEV__,
    }),
  ],
  debug: __DEV__,
});

For reference, this is how you can track down a wild timer (add this to your root index.js/ts file to monkey-patch setTimeout globally in the app):

// in your project root index.js
let n = 0;
const setTimeoutOrg = setTimeout;
setTimeout = (...args) => {
  n++;
  const id = setTimeoutOrg(...args);
  console.log('timer started', id);
  if (n > 200) { // set this to a value high enough that you can get to your relevant screen but low enough that you don't have to wait forever
    throw new Error('Abort, abort! Look at the stack trace displayed in the app.');
  }
  return id;
};

@marandaneto This is still happening. I just spent a couple days tracking down what was causing our Detox tests to hang. After removing react native tracing instrumentation, our tests now pass successfully. I was able to track down that the timers are being set in the stall tracking: https://github.com/getsentry/sentry-react-native/blob/main/src/js/tracing/stalltracking.ts

I’d be happy to work on a PR with a bit of assistance. For now my solution is detect when it is an e2e test run and not include tracing instrumentation in my integrations.

@marandaneto setting one up now - will edit this comment once up.