Detox: Detox fails unless Android emulator is running prior to test execution - Exceeded timeout of 300000ms while handling jest-circus "setup" event
What happened?
I followed the Detox setup guide for a simple React Native test app I am working on. I managed to setup an Android Emulator which is compatible with Detox, and my first test works great!
The only issue is that my Android Emulator must be running before I execute my detox test
command. Otherwise, running detox test
launches my Android Emulator and hangs. The error message is Exceeded timeout of 300000ms while handling jest-circus "setup" event
.
What was the expected behaviour?
Running detox test
for an Emulator config should:
- - attach to the corresponding Emulator if it is already running and execute tests
- - launch the corresponding Emulator if it is not running and execute tests
Was it tested on latest Detox?
- I have tested this issue on the latest Detox release and it still reproduces.
Did your test throw out a timeout?
- I have followed the instructions under Identifying which synchronization mechanism causes us to wait too much.
Help us reproduce this issue!
- Generate a new React Native app
- Follow the Detox Setup Guide for creating a first test on an Android Emulator with Jest, creating an Android Emulator config
- Execute
detox test
for the Android Emulator config while the Emulator is not active - The Emulator should launch, but the app will not launch on the Emulator and execution should hang and eventually timeout
In what environment did this happen?
Detox version: 19.6.5 React Native version: 0.66.3 Node version: 16.13.0 Device model: Pixel 5 (emulator) Android version: API 32 Test-runner: jest-circus
Detox logs
Detox logs
11:46:19.836 detox[33000] DEBUG: [ALLOCATE_DEVICE] Trying to allocate a device based on "Pixel_5_API_32"
11:46:19.837 detox[33000] DEBUG: [EXEC_CMD, #2] "/Users/myUserName/Library/Android/sdk/platform-tools/adb" devices
11:46:20.030 detox[33000] DEBUG: [EXEC_SUCCESS, #2] List of devices attached
11:46:20.031 detox[33000] DEBUG: [ALLOCATE_DEVICE] Settled on emulator-13184
11:46:20.032 detox[33000] DEBUG: [SPAWN_CMD] /Users/myUserName/Library/Android/sdk/emulator/emulator -verbose -no-audio -no-boot-anim -port 13184 @Pixel_5_API_32
11:46:39.690 detox[33000] ERROR: Exceeded timeout of 20000ms while handling jest-circus "setup" event
11:46:39.725 detox[33000] ERROR: Aborted detox.init() execution, and now running detox.cleanup()
HINT: Most likely, your test runner is tearing down the suite due to the timeout error
Device logs
Device logs
{"name":"detox","hostname":"myHostName.local","pid":33133,"__filename":"EmulatorAllocationHelper.js","level":20,"event":"ALLOCATE_DEVICE","msg":"Settled on emulator-15278","time":"2022-04-21T16:49:07.933Z","v":0}
{"name":"detox","hostname":"myHostName.local","pid":33133,"__filename":"launchEmulatorProcess.js","fn":"boot","level":20,"event":"SPAWN_CMD","msg":"/Users/myUserName/Library/Android/sdk/emulator/emulator -verbose -no-audio -no-boot-anim -port 15278 @Pixel_5_API_32","time":"2022-04-21T16:49:07.934Z","v":0}
{"name":"detox","hostname":"myHostName.local","pid":33133,"level":50,"msg":"Exceeded timeout of 20000ms while handling jest-circus \"setup\" event","time":"2022-04-21T16:49:27.775Z","v":0}
{"name":"detox","hostname":"myHostName.local","pid":33133,"__filename":"ArtifactsManager.js","level":10,"event":"ARTIFACTS_LIFECYCLE","fn":"onBeforeCleanup","msg":"artifactsManager.onBeforeCleanup()","time":"2022-04-21T16:49:27.803Z","v":0}
More data, please!
I’ve tried creating a number of Android Emulators on various devices and APIs to see if the issue persists. This issue persists on Android Emulators for each of the Pixel models (1-5) and for the last several APIs (28-32).
Also, adding --retries 2
to the end of my test script does not alleviate the issue. The process still times out on the first attempt and hangs without retrying.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 25 (3 by maintainers)
I’m encountering this issue as well using AOSP API 32. The detox init ends up timing out in the same scenario (app not launched prior to detox test), therefore the tests fail.
Despite the workaround of launching the emulator manually, I’d suggest this to be re-evaluated as a potential bug (instead of a question), and the issue re-opened.
There is definitely a bug here. Should not be closed. It’s very difficult and confusing to find the reason of this problem on CI for example…
@capezzbr @MoOx @rikur @gabrieldonadel @zacharyweidenbach @ghitier @jd20 @dklymenk @BrentWardOx @sangliquidus I’ve released a fix for this issue in the latest detox version (20.0.3) - please try it and see if this issue is now solved for you
@d4vidi
Detox’s ability to create a new simulator instance in CI before running the test seems to be the issue, or at least somewhere near the bullseye of the issue. The
Exceeded timeout of 300000ms while handling jest-circus "setup" event
only seems to occur on the very first tests that are attempted with multiple workers. I can achieve a successful test run of my full testing suite if I do the following:This step reliably fails for all three tests with the timeout error:
xcrun simctl list
to confirm that detox created the new devices:If there is a more elegant way to preemptively create the simulator devices for the number of workers I intend to use (usually only 3 because github actions macOS containers run on boxes with only 3 cores), I can do that instead as a workaround until I find a better solution.
@d4vidi Another data point, for your consideration, this is also happening for my team with iOS running in github actions, presenting in the same was as @gabrieldonadel described here: https://github.com/wix/Detox/issues/3342#issuecomment-1183429492
It seems to be correlated with the
--workers
cli argument being greater than 1.The following test fails with
TypeError: _detox.device.getPlatform is not a function
ThegetPlatform
is invoked within the setup file linked viasetupFilesAfterEnv
in the Jest config. Detox is not properly instantiated in the global scope because of the timeout with the jest-circus “setup” event. This only seems to happen once over the lifetime of the test run, and detox is able to recover and start the next test. And frustratingly, it only seems to happen in CI. In our case, we are using themacos-12
container on github actions, in a very similar manner as react-native-firebase, although we use Jest instead of Mocha.I would post this in the new thread you linked, but that seems dedicated to the issue as it pertains to Android API 32. This seems to be a concurrency issue/race condition that tends to only present in the very resource constrained environment like the virtual containers in CI.
EDIT: I have tried using retries to alleviate the issue, but the
--retries
is just a passthrough to the Jest retry configuration. And from what I can see, a retry does not run through the environment setup step again, so what happens is a guaranteed failure no matter the amount of retries.@d4vidi Here is a link to the new issue per your request: https://github.com/wix/Detox/issues/3574
Getting the same error. API 32 and Detox 19.7.1
@BrentWardOx Give API28 a try. I found that anything above that has that issue.
I am running into a similar issue, but only with a release build.
In debug mode detox starts the emulator, pushes the build and all the tests pass. In release mode detox starts the emulator, but doesn’t install the detox build and the test subsequently times out.
Similarly to the OP, if I start the emulator in advance, the app installs and the tests pass.