Detox icon indicating copy to clipboard operation
Detox copied to clipboard

(WIP) Detox init timeout with Android API 32

Open d4vidi opened this issue 1 year ago • 3 comments

What happened?

A follow-up on the discussions in #3342.

It seems that there are issues with API 32. Most likely, 33 has those as well. We need to check.

What was the expected behaviour?

API 32 should work just as 28 and 29 do.

Was it tested on latest Detox?

  • [X] I have tested this issue on the latest Detox release and it still reproduces.

Did your test throw out a timeout?

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version: React Native version: Node version: Device model: Android version: Test-runner (select one): jest-circus / jest+jasmine / mocha / other

Detox logs

Detox logs
paste logs here!

Device logs

Device logs
paste logs here!

More data, please!

No response

d4vidi avatar Aug 17 '22 11:08 d4vidi

@d4vidi I have similar problems than described in https://github.com/wix/Detox/issues/3071 with android-31, android-32 and android-33 (android-30 works fine). Detox version is 19.7.1. In #3071 it is mentioned "If the emulator is already up and running when starting detox, tests are executed as expected.". Is it documented somewhere how to start emulator first and only after this Detox? When I try this I get "Running multiple emulators with the same AVD". I have stackoverflow question about it, without no reply. I would appreciate if someone from Detox team would reply to that? https://stackoverflow.com/questions/73319635/how-to-configure-detox-to-be-able-to-use-android-emulator-running-already

jaheikki avatar Sep 08 '22 09:09 jaheikki

@jaheikki you might like this:

https://github.com/ankidroid/Anki-Android/blob/58341e381a5773dd86744fa2d549ffa4da226b50/.github/workflows/tests_emulator.yml#L80-L148

  • caches / handles caching for emulator snapshots
  • handles "no cache" / cold boot case by starting + warming up the emulator + then taking snapshot if needed
  • starts emulator from snapshot (which is now guaranteed to exist)
  • runs your thing (could be detox)

That's a pure Android project but we have run that workflow 11,399 times at last count (!) and it's mostly non-flaky / as fast as I know how to make it. It is not android 31/32/33 but the strategy should be sound, for starting up an emulator and having it be high-performance for use (because of the warmup) in the normal case.

mikehardy avatar Sep 20 '22 13:09 mikehardy

I'll note that if you chose the ATD device types it should be that much faster, I haven't experimented with them much as they don't support firebase dynamic links and that's a requirement of mine so they are not as interesting to me. Possibly also of interest if people are testing these things - a gist that lays out an emulator performance testing framework, and has the results from last time I ran it, attempting to determine what was flaky what was not, what was fast, what was not https://gist.github.com/mikehardy/f076172f3b28826898c55dc03fe202de

mikehardy avatar Sep 20 '22 13:09 mikehardy

@d4vidi @mikehardy I was able to use work around for using Android API 31 and above with Detox. So making emulator running before Detox as described in #3071 (see my update on https://stackoverflow.com/questions/73319635/how-to-configure-detox-to-be-able-to-use-android-emulator-running-already). But it requires also the 'adb reverse tcp:8081 tcp:8081' to hit the bundler as described in #2899. Is this the best work around for the #3560 at the moment? Of cource I would prefer getting official fix for this issue if it is released in near future?

jaheikki avatar Sep 27 '22 08:09 jaheikki

I frequently need to do adb reverse without detox these days. Why? Unknown, but easy to script. I no longer carry any patches for detox vs official release personally

mikehardy avatar Sep 27 '22 11:09 mikehardy

I landed the feature for reversing TCP ports into Detox 20 preview: Soon an alpha version will be released: 20.0.11-prerelease.0, I guess.

Meanwhile, you could add await device.reverseTcpPort(8081) right before your device.launchApp(). 🤷 .

As for why it might happen more often, I have a theory or two:

  1. aside from the fact you have that problem, you often spawn clean devices (with no reversed port)
  2. the problem itself might be due to the altered default bundler URL: see how to change and also see the defaults for localhost:

  1. you might have something like preferences.edit().putString("debug_http_host", "localhost:8081").apply(); in your Android native code and that it works worse than 10.0.2.2:8081 (which automatically forwards everything to your localhost on Android emulators – contrary to localhost where you need to reverse the ports)

😌 hope that helps

noomorph avatar Sep 27 '22 11:09 noomorph

The problem is being investigated in https://github.com/wix/Detox/issues/3636

jonathanmos avatar Oct 19 '22 07:10 jonathanmos