ConcurrentModificationException
Here's the stack trace:
java.util.ConcurrentModificationException at java.util.ArrayList$Itr.next(ArrayList.java:831) at org.yaml.snakeyaml.representer.BaseRepresenter.representSequence(BaseRepresenter.java:132) at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentList.representData(SafeRepresenter.java:173) at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:94) at org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer.java:125) at okreplay.TapeRepresenter.representJavaBeanProperty(TapeRepresenter.java:40) at org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:83) at org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Representer.java:49) at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:105) at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:64) at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:242) at org.yaml.snakeyaml.Yaml.dump(Yaml.java:221) at okreplay.YamlTapeLoader.writeTo(YamlTapeLoader.java:75) at okreplay.YamlTapeLoader.writeTape(YamlTapeLoader.java:52) at okreplay.Recorder.stop(Recorder.java:68) at okreplay.RecorderRule$apply$1.evaluate(RecorderRule.kt:44) at okreplay.PermissionRule$apply$1.evaluate(PermissionRule.kt:18) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
Hmm interesting. Are you running tests in parallel or something like that?
I don't believe that's what triggered this because it happened when I was testing a class with a single test, but we do run our tests in parallel.
I am experiencing the same issue, just 2 tests, one after the other.
I am facing the same issue as well when running a single test or multiple tests. Did you guys figure out any reason?
I have observed that it fails only when I record more than one test cases under the same instrumentation instance. If I enabled androidTestOrchestrator and record each test case under a new instrumentation instance then I don't get the exception anymore.
Setup:
- Orchestrator enabled
- Single UI test
Observations:
RECORDING PHASE (TapeModes: READ_WRITE ,WRITE_SEQUENTIAL, WRITE_ONLY)
- Takes about 2-3 minutes for that single test to start recording
- Tapes recording fail with
ConcurrentModificationExceptionoccasionally while for others they fail most of the time
TESTING PHASE (TapeModes: READ_WRITE)
- Takes about 2-3 minutes for that single test to start running
- GC is running non-stop for @OkReplay annotation tests
- Sometimes getting
java.lang.RuntimeException: android.os.DeadObjectException FATAL EXCEPTION: AndroidTestOrchestratorbut sometimes the tests pass
ConcurrentModificationException can be thrown because your app is still making network requests after UI test has finished executing. You can work around it by using an Espresso idling resource for OkHttp like this one or writing your own.