android-test: java.lang.RuntimeException: androidx.test.services.shellexecutor.ClientNotConnected

Description

Instrumentation test randomly failing. When running espresso tests on our CI machine (which runs tests on Firebase Test Lab) we occasionally get the following crash and then the tests stop:

FATAL EXCEPTION: AndroidTestOrchestrator
Process: androidx.test.orchestrator, PID: 8463
java.lang.RuntimeException: androidx.test.services.shellexecutor.ClientNotConnected
	at androidx.test.services.shellexecutor.ShellExecutorImpl.executeShellCommandSync(ShellExecutorImpl.java:60)
	at androidx.test.orchestrator.AndroidTestOrchestrator.execShellCommandSync(AndroidTestOrchestrator.java:532)
	at androidx.test.orchestrator.AndroidTestOrchestrator.access$700(AndroidTestOrchestrator.java:127)
	at androidx.test.orchestrator.AndroidTestOrchestrator$2.run(AndroidTestOrchestrator.java:360)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
	at java.lang.Thread.run(Thread.java:818)
Caused by: androidx.test.services.shellexecutor.ClientNotConnected
	at androidx.test.services.shellexecutor.ShellCommandClient.execOnServer(ShellCommandClient.java:97)
	at androidx.test.services.shellexecutor.ShellCommandClient.execOnServerSync(ShellCommandClient.java:135)
	at androidx.test.services.shellexecutor.ShellExecutorImpl.executeShellCommandSync(ShellExecutorImpl.java:56)
	... 6 more

It’s never the same test causing the problem. Not sure it matters but it’s only when testing on Nexus5X emulator for API versions 23 / 24. Tests on other emulators / API versions all pass fine.

Steps to Reproduce

none

Expected Results

Tests should continue and complete

Actual Results

Crash.

AndroidX Test and Android OS Versions

 junitVersion = '4.12'
androidXJunitVersion = '1.1.1-alpha01'
androidXTestRunnerVersion = '1.1.2-alpha01'
androidXTestRulesVersion = '1.1.2-alpha01'
androidXTestOrchestratorVersion = '1.1.2-alpha01'
espressoCoreVersion = '3.1.2-alpha01'
espressoContribVersion = '3.1.2-alpha01'
espressoIdlingVersion = '3.1.2-alpha01'

Link to a public git repo demonstrating the problem:

none

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 14
  • Comments: 21

Commits related to this issue

Most upvoted comments

We also have this issue but we always had clearPackageData enabled like mentioned by @tobrun I’m not sure if that’s the cause.

Is there anything we can do to help proceed investigation of this issue?

@athkalia this started happening on all of our test emulators (including API28). I think what was happening was that we were hitting the default 15 min timeout for Firebase Test Lab. Depending on how you trigger your tests you may need to increase the timeout

https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run#--timeout

When we bumped to 30 mins, everything was fine.

If you look in your system logcat, I expect that you will find that androidx.test.services was killed. Check for low memory issues; that’s usually the culprit.

What’s happening there is that the code run as an Instrumentation is publishing a service handle to the SpeakEasy service running in androidx.test.services, and the test orchestrator is expecting to get that handle from SpeakEasy so it can run shell commands in the instrumented process (with all of its privileges). If androidx.test.services is killed and restarted between the start of instrumentation and the start of the test, it loses the handle published by the Instrumentation.

@hamen It seems Firebase introduced a bug to TestLab when they updated their dependencies. The bug was introduced in firebase-iid and firebase-messaging dependencies. If you are using either of these dependencies, you must update them to 20.2.3 or later. Messaging is already at 20.2.4

Nope, sorry 😕

I believe the maximum value is 60 minutes. So maybe you can try bumping it to 35 minutes and see if that helps. The give away for me was when I actually went and looked at the firebase console. I saw this banner that said your test has timed out or expired. I didn’t see any actual indication in the logs though.