Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make detox setup and teardown global #2193

Closed
d4vidi opened this issue Jul 8, 2020 · 5 comments
Closed

Make detox setup and teardown global #2193

d4vidi opened this issue Jul 8, 2020 · 5 comments
Assignees
Labels
domain: internal domain: optimization Improves Detox's run-time or resource utilization type: enhancement ⚡️

Comments

@d4vidi
Copy link
Collaborator

d4vidi commented Jul 8, 2020

Today, in Jest environments, we initialize Detox from scratch in each and every suite-run from within the context of our circus Environment class. As a rule, initialization includes launching emulators/simulators, when needed.

This approach creates some drawbacks, as things like prebooting and preconfiguring test emulators, cannot be centrally controlled. We generally want to have Detox init split into two use cases:

  1. Global init, potentially integrated into Jest's global-setup phase.
  2. Per-suite init, which - for example, locks-on on a specific device.

Teardown should be addressed equivalently, of course.

Until we introduce this change, the following fixes/enhancements shall remain blocked:

  • In Test butler app apk #2188, we've created a technical debt where in some cases, util-binary APK's (e.g. test-butler's) cannot overwrite currently installed version of the same APK's, when upgrading them. The reason is that there was no single place to preinstall these APK's, and - so as to avoid reinstalling them again and again in the beginning of each suite (can be painfully time consuming), we instead chose to refrain from installing if the package already exists on the device.

  • Also in Test butler app apk #2188 (or actually Switch to downloading test-butler APK in jest's global-setup #2194), we've applied a manual resolution of the device type using internal detox API (see https://github.com/wix/Detox/pull/2194/files#diff-a984eb86f26b819ce6f51b8a8fe9226bR4). A preliminary global init, would allow for the device's type to be available at a stage as early as this (e.g. using device.getPlatform()).

  • Device cleanup using the --cleanup arg isn't properly supported in parallel-execution environments (--cleanup flag fails subsequent tests after first successful suite due to emulator crash #1975 refers to that): instead of tearing down the emulators once when the whole suite ends, it does this in the end of each suite. The runtime penalty here is huge. In internal projects, we've instructed devs to manually apply a killall in scripts, but that doesn't scale.

  • For the sake of native animations' disabling on Android, we apply the necessary configuration via adb in each init, and thus in the beginning of each suite. This is another time-waster, as it should only be done once as part of the global setup.

  • Device launch implementation is overly complex, and cannot be simplified. Since centralized prebooting is not possible, we are forced - at least on Android, at prelaunch, to allocated a unique adb port, outside the recommended range, and run emulators synthetically - preguessing their port-based name (e.g. emulator-12345), which is bad practice. A much more simple solution would be to just launch an emulator, having the system allocate its port, and that's that.

@yungkittty
Copy link

yungkittty commented Feb 10, 2021

Thanks for the tutorial btw.

The section dedicated to Test Butler here is very unclear on how to actually integrate it in our android app (ie react-native).

Few things that I would have liked to know :

I. How to add a test runner :

  1. Edit this file
  2. Create this file
  3. Create this file (very helpful for debugging)

II. How to automatically download Test Butler APK

  1. Create this file
  2. Edit this file

III. What to follow from the Test Butler documentation and what from yours

I don't think it's very clear.

I hope my feedback can help you to improve the documentation in the futur ❤️

@d4vidi d4vidi added the domain: optimization Improves Detox's run-time or resource utilization label Apr 8, 2021
@badsyntax
Copy link
Contributor

@d4vidi Regarding the --cleanup arg, when you mention "we've instructed devs to manually apply a killall in scripts, but that doesn't scale.", can you provide an example of this? I'm not entirely sure how to manually kill the detox server

@noomorph noomorph self-assigned this Apr 15, 2021
@d4vidi
Copy link
Collaborator Author

d4vidi commented Apr 18, 2021

Hey @badsyntax! You are not required to kill the detox server. Rather, this was referring to the killing of the running emulators. For example, on CI builds that run tests on Android emulators, and immediately thereafter on iOS simulators, you'd wish to clean up the environment before the iOS suite starts running (namely, killing all locally-hosted, currently running Google emulators).
One way to do this, is to run this in a script you preregister in Jest as its global-teardown script:

killall qemu-system-x86_64 || true
# OR:
killall qemu-system-x86 || true
# OR:
killall qemu-system-x86_64-headless || true

(don't take me up on the exact syntax... you get the gist).

@badsyntax
Copy link
Contributor

Thanks for the clarification @d4rky-pl

@d4vidi
Copy link
Collaborator Author

d4vidi commented Jul 14, 2021

Closing in favour of #2894!

@d4vidi d4vidi closed this as completed Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: internal domain: optimization Improves Detox's run-time or resource utilization type: enhancement ⚡️
Projects
None yet
Development

No branches or pull requests

4 participants