android-test: Seemingly random 'process crashed' for the instrumentation runner

Description

What appears to randomly process crashes of the test runner. I understand this may not be the best example on how to present the issue (without the full code), but I was unable to reproduce this on a fresh project 😦

Steps to Reproduce

In our app, the test is really simple. When I run it from the IDE it runs almost 100% correctly, from command line via ./gradlew connectedProductionDebugAndroidTest -i

it often fails with the error provided below.

class MyTest {

    private val mockViewModel = mockk<FeedViewModel>(relaxed = true, relaxUnitFun = true)

    @get:Rule
    val mockInjectionRule = MockInjectionRule {
        every { it.myViewModel() } returns mockViewModel
        every { mockViewModel.shouldDoSomething() } returns false
    }

    @Test
    fun myFragment_titleDisplays() {
        launchFragmentInContainer(themeResId = R.style.AppTheme) { MyFragment() }

        onView(withText(R.string.title))
                .check(ViewAssertions.matches(isDisplayed()))
                .check(matches(withParent(withId(R.id.toolbar))))
        onView(withId(R.id.action_settings))
                .check(matches(isDisplayed()))
    }
}

Expected Results

Tests run/pass

Actual Results

Tests pass on average 7/10 times, when they fail, this is logged in Logcat

        ActivityManager  I  Start proc 23437:com.android.chrome:sandboxed_process0/u0i50 for webview_service Ïd
                            ebug/org.chromium.content.app.SandboxedProcessService0
                         W  Slow operation: 57ms so far, now at startProcess: starting to update pids map
                         W  Slow operation: 57ms so far, now at startProcess: done updating pids map
         dboxed_process  W  Unexpected CPU variant for X86 using defaults: x86
         ercentral.debu  I  Background concurrent copying GC freed 161195(5MB) AllocSpace objects, 5(88KB) LOS objects, 36% free, 10MB/1
                            6MB, paused 1.468ms total 178.354ms
        ActivityManager  W  Slow operation: 70ms so far, now at attachApplicationLocked: after mServices.attachApplicationLocked
 cr_ChildProcessService  I  Creating new ChildProcessService pid=23437
        ActivityManager  I  Process com.examplepackage.debug (pid 23395) has died: fore TOP
                 Zygote  I  Process 23395 exited due to signal (11)
        InputDispatcher  W  channel '81514ff com.examplepackage.debug/androidx.fragment.app.testing.FragmentScenario$EmptyFragmen
                            tActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
                         E  channel '81514ff com.examplepackage.debug/androidx.fragment.app.testing.FragmentScenario$EmptyFragmen
                            tActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
        libprocessgroup  W  kill(-23395, 9) failed: No such process
                         I  Successfully killed process cgroup uid 10097 pid 23395 in 4ms
 cr_ChildProcessService  I  Destroying ChildProcessService pid=23437
          WindowManager  I  WIN DEATH: Window{81514ff u0 com.examplepackage.debug/androidx.fragment.app.testing.FragmentScenario$
                            EmptyFragmentActivity}
                         D  HostConnection::get() New Host Connection established 0xe9c0a840, tid 1973
        InputDispatcher  W  Attempted to unregister already unregistered input channel '81514ff com.examplepackage.debug/androidx
                            .fragment.app.testing.FragmentScenario$EmptyFragmentActivity (server)'
         gralloc_ranchu  D  gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
         dboxed_process  I  System.exit called, status: 0
         AndroidRuntime  I  VM exiting with result code 0, cleanup skipped.
                         D  HostConnection::get() New Host Connection established 0xe9c0a840, tid 1973
         gralloc_ranchu  D  gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
                         D  HostConnection::get() New Host Connection established 0xe9c0a840, tid 1973
         gralloc_ranchu  D  gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
                 Zygote  I  Process 23437 exited cleanly (0)
                         D  HostConnection::get() New Host Connection established 0xe9c0a840, tid 1973
   GnssLocationProvider  I  WakeLock acquired by sendMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$SvSta
                            tusInfo@453db8e)
         gralloc_ranchu  D  gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
   GnssLocationProvider  I  WakeLock released by handleMessage(REPORT_SV_STATUS, 0, com.android.server.location.GnssLocationProvider$SvS
                            tatusInfo@453db8e)
         SurfaceFlinger  W  couldn't log to binary event log: overflow.
        ActivityManager  W  Force removing ActivityRecord{82ebca5 u0 com.examplepackage.debug/androidx.fragment.app.testing.Fragm
                            entScenario$EmptyFragmentActivity t300}: app died, no saved state
                         W  Crash of app com.examplepackage.debug running instrumentation ComponentInfo{com.examplepackage
                            .debug.test/com.examplepackage.myapp.CustomTestRunner}
                         I  Force stopping com.examplepackage.debug appid=10097 user=0: finished inst

                            Process com.android.chrome:sandboxed_process0 (PID: 23437) ended

        ActivityManager  I  Killing 23437:com.android.chrome:sandboxed_process0/u0a97i50 (adj 0): isolated not needed
        libprocessgroup  W  Failed to open process cgroup uid 99050 pid 23437: No such file or directory
--
--
                         E  channel '81514ff com.examplepackage.debug/androidx.fragment.app.testing.FragmentScenario$EmptyFragmen
                            tActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
        libprocessgroup  W  kill(-23395, 9) failed: No such process
                         I  Successfully killed process cgroup uid 10097 pid 23395 in 4ms
 cr_ChildProcessService  I  Destroying ChildProcessService pid=23437
          WindowManager  I  WIN DEATH: Window{81514ff u0 com.examplepackage.debug/androidx.fragment.app.testing.FragmentScenario$
                            EmptyFragmentActivity}

AndroidX Test and Android OS Versions

debugImplementation ("androidx.fragment:fragment-testing:1.1.0-alpha08") {
    exclude group: "androidx.test", module: "core"
}

androidTestImplementation 'androidx.test.ext:junit:1.1.1-beta01'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
androidTestImplementation "androidx.arch.core:core-testing:2.0.0"
androidTestUtil 'androidx.test:orchestrator:1.1.1'

Emulator is API 28 Nexus 5, animations turned off.

Link to a public git repo demonstrating the problem:

N/A

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 30
  • Comments: 29 (1 by maintainers)

Most upvoted comments

Using an x64 emulator solved the problem for me, as cristan commented here: https://github.com/mockk/mockk/issues/466#issuecomment-734758479

I agree with @NitroG42 .

I have migrated the few UI tests I had written to on a new mobile app project Mockito believing it would be way more stable thanks to its history and active development.

At first, it seemed the crashs were completely gone, but at some point they did reappear, still at random with the dreadful message from InputDispatcher and occasional SIGSEGV.

On the Android TV project we have (which is way more advanced), the handful tests I developped, which required a lot more mocking, tended to crash a lot more (still on the emulator).

When migrating to Mockito, I noticed the same issues and restrictions:

  • minimum API 28 (Android P)
  • “the mocking agent could not be attached to the JVMTI” -> added android:extractNativeLibs="true" as a workaround in the test manifest
  • attempting to run on lower API printed the same logs than MockK.

So, if I understand correctly, MockK & Mockito uses the same APIs (from Android Test Instrumentation?) to perform mocking in Android UI tests.

While Mockito seemed, at first, a lot more stable, the crash eventually did reappear, for the same reasons. Could it be possible neither of them are the culprit?

Finally, I noticed that manually rebooting the emulators greatly reduced the random crash. Surely because it resets all the memory allocations, right?

@brettchabot could you help? Do you have any idea what could be the real issue?

I had exactly the same issue. In my case it was com.linkedin.dexmaker:dexmaker-mockito-inline causing the random crashes. For details see my answer on stackoverflow:

I have exactly the same issue and I also believe MockK could be behind it. I have posted the issue on SO: https://stackoverflow.com/questions/63059986/android-ui-tests-with-espresso-mockk-crash-with-sigsegv

Looking at OP crash log, I found one common error message:

channel ‘81514ff com.examplepackage.debug/androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity (server)’ ~ Channel is unrecoverably broken and will be disposed!

In my case, this log message is always right before the crash, usually alongside a SIGSEGV.

I am using Espresso to write a login + pwd to test a LoginActivity and I use MockK to mock all the Repositories / Services logic in a MVP architecture. Also, none of this has happened on my physical devices.

Same here, also mockk 1.9.3 and launchFragment 1.2.0. Running clean before the test seems to solve the issue.