AzimoLabs / fastlane-plugin-automated-test-emulator-run

Plugin dedicated for Android platform. Wraps gradle task/shell command used for launching instrumented tests. Provides start of as many AVDs with various configs as needed before test run, waits for boot, kills emulators and deletes them from hdd after tests are finished or disturbed.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Emulator launch freezes on linux

OSemenovBoyarka opened this issue · comments

Hi, we use your plugin for a while on MacOS build server with Jenkins and it works really great!
However, recently, we've decided to add linux based (Ubuntu 16.04) slave machine to distribute load from main build server.

Issue is first emulator launch (we use two emulators for our tests) command freezes whole build. It seems trailing & doesn't work and emulator process doesn't go background to subshell. Emulator itself boots normally

It shows only following:

[11:09:49]: $ /home/android-build-server/Android/Sdk/tools/emulator -port 5558 -avd UI-Test-API25-Nexus-5X  -gpu auto -skin 1080x1920 &>/tmp/emulator_output20170328-12236-1tcx549&
[11:09:49]: ▸ sh: 1: glxinfo: not found
[11:09:50]: ▸ sh: 1: glxinfo: not found
[11:09:55]: ▸ pulseaudio: pa_context_connect() failed
[11:09:55]: ▸ pulseaudio: Reason: Connection refused
[11:09:55]: ▸ pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver

The same command, launched in regular terminal works like a charm (goes to background and returns 0 exit code).

Maybe, it would be more stable to use ruby processes/threads instead of subshell to avoid such issues?

Hey @SemenovAlexander!
Thank you for your feedback.

Indeed we shared version of plugin that we used for our own needs and we use MacOS only.

It's hard for me to say something as I we do not use Ubuntu and I can't reproduce this issue so easily.

Can you elaborate more about "ruby processes/threads instead of subshell"?
Do you have any idea, that you know, would fix the issue?

From my perspective you need to communicate win Android SDK binaries via shell so what's the difference if I call it from various threads if it still needs to be shell - and its shell that is running and managing processes, plugin is only sending commands.

Other thing that comes to my head is that those AVD are launched simultaneously and maybe Ubuntu is less tolerant for this?
Can you check if you can launch single AVD instead of two?

I am willing to help.

@FisherKK Thanks for such quick response!

Yeap, I've also thought about two adb instances clashes each other, but running single emulator is the same. Line "Waiting AVD to boot..." doesn't appear.

Before using your plugin, we've wrote small ruby method and attached it just as another Fastfile, it's quite limited and has a lot of hardcode, but key point is using Process.fork to launch emualtor
https://gist.github.com/SemenovAlexander/c1e74f73402ab0ab511c57e404fe7cd0#file-androidemulatorfastfile-L26

Like so - it works fine, one issue here - that emulator doesn't get killed, when shell is closed, so we kill it with adb emu kill at the end.

For now we've reverted to this approach and all works fine.

Thats interesting and helpful information.

Seems like not much work to do. I would need to wrap launch commands in this and it would help I guess.

I am killing emulators with adb emu kill too. If I get some free time (I think tomorrow or today after my work time) I will try to apply this and check if it doesn't crash anything on my side. I hope it will fix it for you.

From the other side I am waiting for Google to fix issues with new emulator binaries which started since Build Tools 25.0.2 Emulators tend to launch as "unauthorized" and you can't do anything with them until you restart ADB. It's blocker for tools like this.

Thanks for that!

As for Unauthorized issue, we've updated build tools from 24.x to 25.3.1 at once, and have no issues with emulator across >100 launches in couple days.

May, they have fixed this already?

Huh, are you sure you didn't mean SDK Tools? I had 25.3.1 too (just saw that 26.0.0 are available) for Android SDK Build-Tools (new binary -> avdmanager is included there) I have 25.0.2 as latest version and I can't download anything newer.

Yes, I'm pretty sure, they've added new dependency Android Emulator, I have now 25.3.1 on all machines and yes, update available to 26.0.0, but I'm afraid to update that since it works now :)

Sorry, about confusing Build Tools, it should be Android Emulator

Btw, forgot to mention, with this new Android Emulator you should now launch emulator from emulator/emulator directory, not from tools/emulator, as release notes mention.
https://developer.android.com/studio/releases/emulator.html

screen shot 2017-03-28 at 13 00 56

Well I need to make update in plugin anyway then :P

Heh, I have updated to 26.0.0 and I can say that "unauthorized" has disappeared but AVD creation time went up rly much.

Check out this log (it's not from plugin it's other tool I am working on):

[13:56:10] - DeviceManager: AVD with name 'Test-Emulator-API23-Nexus-5-0' already exists and will be re-created.
[13:56:10] - ShellHelper: Executing shell command: /Users/F1sherKK/Library/Android/sdk/tools/bin/avdmanager delete avd -n Test-Emulator-API23-Nexus-5-0
[13:56:11] - Deleting file /Users/F1sherKK/.android/avd/Test-Emulator-API23-Nexus-5-0.ini
[13:56:11] - Deleting folder /Users/F1sherKK/.android/avd/Test-Emulator-API23-Nexus-5-0.avd
[13:56:11] - 
[13:56:11] - AVD 'Test-Emulator-API23-Nexus-5-0' deleted.
[13:56:11] - ShellHelper: Executing shell command: echo "no" | /Users/F1sherKK/Library/Android/sdk/tools/bin/avdmanager create avd --name "Test-Emulator-API23-Nexus-5-0" --package "system-images;android-23;google_apis;x86_64" --device "Nexus 5X"  --abi google_apis/x86_64 
[13:56:26] - DeviceManager: 'config.ini' file was specified in AVD schema of device 'emulator-5556 in location '~/Android/AVD_Snapshots/Nexus_5X_API_23/config.ini'. Applying...
[13:56:26] - DeviceManager: AVD with name 'Test-Emulator-API23-Nexus-5-1' already exists and will be re-created.
[13:56:26] - ShellHelper: Executing shell command: /Users/F1sherKK/Library/Android/sdk/tools/bin/avdmanager delete avd -n Test-Emulator-API23-Nexus-5-1
[13:56:28] - Deleting file /Users/F1sherKK/.android/avd/Test-Emulator-API23-Nexus-5-1.ini
[13:56:28] - Deleting folder /Users/F1sherKK/.android/avd/Test-Emulator-API23-Nexus-5-1.avd
[13:56:28] - 
[13:56:28] - AVD 'Test-Emulator-API23-Nexus-5-1' deleted.
[13:56:28] - ShellHelper: Executing shell command: echo "no" | /Users/F1sherKK/Library/Android/sdk/tools/bin/avdmanager create avd --name "Test-Emulator-API23-Nexus-5-1" --package "system-images;android-23;google_apis;x86_64" --device "Nexus 5X"  --abi google_apis/x86_64 
[13:57:35] - DeviceManager: 'config.ini' file was specified in AVD schema of device 'emulator-5558 in location '~/Android/AVD_Snapshots/Nexus_5X_API_23/config.ini'. Applying...
[13:57:35] - DeviceManager: AVD with name 'Test-Emulator-API23-Nexus-5-2' already exists and will be re-created.
[13:57:35] - ShellHelper: Executing shell command: /Users/F1sherKK/Library/Android/sdk/tools/bin/avdmanager delete avd -n Test-Emulator-API23-Nexus-5-2
[13:57:36] - Deleting file /Users/F1sherKK/.android/avd/Test-Emulator-API23-Nexus-5-2.ini
[13:57:36] - Deleting folder /Users/F1sherKK/.android/avd/Test-Emulator-API23-Nexus-5-2.avd
[13:57:36] - 
[13:57:36] - AVD 'Test-Emulator-API23-Nexus-5-2' deleted.
[13:57:36] - ShellHelper: Executing shell command: echo "no" | /Users/F1sherKK/Library/Android/sdk/tools/bin/avdmanager create avd --name "Test-Emulator-API23-Nexus-5-2" --package "system-images;android-23;google_apis;x86_64" --device "Nexus 5X"  --abi google_apis/x86_64 
[13:59:22] - DeviceManager: 'config.ini' file was specified in AVD schema of device 'emulator-5560 in location '~/Android/AVD_Snapshots/Nexus_5X_API_23/config.ini'. Applying..

First AVD: 15 sec
Second AVD: 67 sec
Third AVD: 134 sec ???!

The same happens if I invoke raw commands in terminal, not from any script. I wonder if I should create ticket for it. Something seems to stack in background and next AVD takes much longer to create than previous one.

I can confirm this, tried to update to 26.0.0 on dev machine and first time I've tried to create AVDs times were something like yours.
However, I've noticed a lot of duplicated AVDs, left from previous launches. I've deleted them - and all seems to work fine

Well, as you can see in log I am deleting AVD and waiting for shell feedback with "action complete message" before I attempt to create an AVD - so for sure I am not making a copy of existing one there. Weird.

Hello @SemenovAlexander

I have changed emulator binary loc to emulator/ from tools/.
Furthermore I have wrapped launch AVD shell commands in Process.fork. It works on my side, tell me how it goes for you :)

New version is 1.4.1.

Yes, it works fine for me too now. Thanks a lot!