wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.2k stars 1.92k forks source link

Deadlock during start with new architecture on iOS #4506

Open TimotheeIsnard opened 4 months ago

TimotheeIsnard commented 4 months ago

What happened?

Hello, I have a React Native app that I test on iOS, on both the old and new RN architecture, and when starting the app with the new architecture enabled Detox freezes while trying to first enable synchronization.
There is no freeze on the old RN architecture.

I tried --debug-synchronization, but it has nothing to say, since Detox seems to block internally before reaching the app code.
By adding logs and following in a debugger, I found that the freeze comes from the waitForReactNativeLoadWithCompletionHandler function in DetoxSync.

I opened a PR in DetoxSync that fixes the deadlock for me, but there may be other ways to solve the freeze, so I wanted to make a bug report here anyways (also, this repo seems more active)
DetoxSync PR: https://github.com/wix-incubator/DetoxSync/pull/74

What was the expected behaviour?

Detox should start on iOS with the new architecture enabled.

Was it tested on latest Detox?

Did your test throw out a timeout?

Help us reproduce this issue!

The freeze reproduces 100% of the time, if I do either a regular await device.launchApp(), or a manual:

  const detoxArgs = {
    launchArgs: {
      detoxEnableSynchronization: 0,
      'DTXEnableVerboseSyncSystem': 'YES',
      'DTXEnableVerboseSyncResources': 'YES'
    },
  };
  await device.launchApp(detoxArgs);

  console.log('Device launched, enabling sync again soon...');
  await new Promise((r) => setTimeout(r, 5000));
  console.log('Device launched, enabling sync again');
  await device.enableSynchronization();

In what environment did this happen?

Detox version: 20.22.2 React Native version: 0.73 Has Fabric (React Native's new rendering system) enabled: Yes Node version: 22.2.0 Device model: iPhone 15 simulator iOS version: 17.5 macOS version: Sonoma 14.5 Xcode version: 15.4 (15F31d) Test-runner (select one): jest

Detox logs

Detox logs (in attachment due to 65kB github comment limit): detox_loglevel_trace.txt

Device logs

No response

More data, please!

Output of xcrun simctl spawn booted log stream --level debug --style compact | tee detoxlog: detox_xcrun_log.tar.gz (13 MB uncompressed)

Sky commented 5 days ago

It looks like this is causing similar issue as here: https://github.com/wix/Detox/issues/3949 @TimotheeIsnard could you share steps on how to apply your patch locally?

I tried to:

  1. unpack ./node_modules/detox/Detox-ios-src.tbz
  2. rename Detox-ios-src folder to ios
  3. apply your changes to DetoxSync sources
  4. run ./scripts/pack_ios.sh which created new frameworks and archived them
  5. run detox rebuild-framework-cache
  6. rebuild app with detox build (this is probably not needed since Detox framework is injected during app launch)

But this did not helped and it's still stuck waiting after app launched. RN 0.75.4 with New Arch enabled. Detox 20.27.4. Also having similar issue on Android.

TimotheeIsnard commented 4 days ago

Hey there. Sorry to hear there are more of us out there having Detox deadlocks :)
We're current using our own private fork of Detox in CI to workaround these upstream issues.

Here's how I build and run a custom Detox on my react native app/lib for iOS, in case it can help:


Git clone detox, then:

git submodule update --init --recursive
lerna bootstrap

# (ignore this for iOS, this is for Android only)
cd detox/android
# ./gradlew clean detox:publish -Dversion=20.20.0 # Replace by cur ver number 

In your react-native app's root folder, do a regular yarn install at the root (with the regular upstream detox in package.json), then:

rm example/node_modules/detox -r && ln -s /YOUR_LOCAL_FOLDER_HERE/Detox/detox example/node_modules/detox

For ios in your react native app's folder:

rm -r ~/Library/Detox/ && yarn detox build-framework-cache

Then I can do yarn detox build/yarn detox test as usual my RN app's repository, and now the app JS/content load can happen in any order, without deadlocking on startup.

Sky commented 4 days ago

@TimotheeIsnard thanks for sharing those steps. Just to confirm do you have any other patches in your private forks or only those you added to https://github.com/wix-incubator/DetoxSync/pull/74 ? Also does Detox work for you on Android with New Architecture enabled? And what are your current versions of RN and Detox?

TimotheeIsnard commented 3 days ago

That's the only patch we have at the moment. It does work for us on Android with new arch (including fabric). There is still some random flakyness on some configs (mostly Android, more on older API levels), but that's just Detox, and it's <1%. We can generally workaround the unreliable random failures without patching Detox itself.

Currently we're running RN 0.73.6, Detox 20.23 (haven't updated our fork since 7345e6c7da950d2b46e050aaa152fc2d64ab3e15)
We test on both old and new architecture, with both old and new Android versions, plus iOS.

asamaranayake commented 3 days ago

Im still getting this issue Any idea how to fix this