wordpress-mobile / WordPress-Android

WordPress for Android
http://android.wordpress.org
GNU General Public License v2.0
2.97k stars 1.32k forks source link

[Screenshots] Hilt crash in `JPScreenshotTest` #17129

Open AliSoftware opened 2 years ago

AliSoftware commented 2 years ago

Parent: #17128

On some occasions, I get a Hilt crash when running the JPScreenshotTest

Reproducibility

This crash does not happen consistently (flaky), but still happens more often than not.

I haven't noticed this crash on the WPScreenshotTest yet; either I was very lucky, or there's something that makes it work in WPScreenshotTest but not in JPScreenshotTest that could give a hint at how to fix this?

Stacktrace

Example when running bundle exec fastlane screenshots app:jetpack locale:fr-FR (though I've seen it happen when running the test directly from Android Studio too)

[10:12:05]: $ /Users/olivierhalligon/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell am instrument --no-window-animation -w \
-e testLocale fr-FR \
--no-hidden-api-checks \
-e appendTimestamp false \
-e class org.wordpress.android.ui.screenshots.JPScreenshotTest \
com.jetpack.android.test/org.wordpress.android.WordPressTestRunner
[10:12:10]: ▸ org.wordpress.android.ui.screenshots.JPScreenshotTest:
[10:12:10]: ▸ Process crashed while executing jPScreenshotTest(org.wordpress.android.ui.screenshots.JPScreenshotTest):
[10:12:10]: ▸ java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
[10:12:10]: ▸   at dagger.hilt.internal.Preconditions.checkState(Preconditions.java:83)
[10:12:10]: ▸   at dagger.hilt.android.internal.testing.TestApplicationComponentManager.generatedComponent(TestApplicationComponentManager.java:96)
[10:12:10]: ▸   at org.wordpress.android.WordPressTest_Application.generatedComponent(WordPressTest_Application.java:28)
[10:12:10]: ▸   at dagger.hilt.EntryPoints.get(EntryPoints.java:59)
[10:12:10]: ▸   at org.wordpress.android.WordPress.component(WordPress.kt:26)
[10:12:10]: ▸   at org.wordpress.android.push.GCMMessageService.onCreate(GCMMessageService.java:42)
[10:12:10]: ▸   at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532)
[10:12:10]: ▸   at android.app.ActivityThread.access$1300(ActivityThread.java:199)
[10:12:10]: ▸   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
[10:12:10]: ▸   at android.os.Handler.dispatchMessage(Handler.java:106)
[10:12:10]: ▸   at android.os.Looper.loop(Looper.java:193)
[10:12:10]: ▸   at android.app.ActivityThread.main(ActivityThread.java:6669)
[10:12:10]: ▸   at java.lang.reflect.Method.invoke(Native Method)
[10:12:10]: ▸   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
[10:12:10]: ▸   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
[10:12:10]: ▸ Process crashed while executing jPScreenshotTest(org.wordpress.android.ui.screenshots.JPScreenshotTest):
[10:12:10]: ▸ java.lang.RuntimeException: Unable to create service org.wordpress.android.push.GCMMessageService: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
[10:12:10]: ▸   at android.app.ActivityThread.handleCreateService(ActivityThread.java:3544)
[10:12:10]: ▸   at android.app.ActivityThread.access$1300(ActivityThread.java:199)
[10:12:10]: ▸   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
[10:12:10]: ▸   at android.os.Handler.dispatchMessage(Handler.java:106)
[10:12:10]: ▸   at android.os.Looper.loop(Looper.java:193)
[10:12:10]: ▸   at android.app.ActivityThread.main(ActivityThread.java:6669)
[10:12:10]: ▸   at java.lang.reflect.Method.invoke(Native Method)
[10:12:10]: ▸   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
[10:12:10]: ▸   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
[10:12:10]: ▸ Caused by: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
[10:12:10]: ▸   at dagger.hilt.internal.Preconditions.checkState(Preconditions.java:83)
[10:12:10]: ▸   at dagger.hilt.android.internal.testing.TestApplicationComponentManager.generatedComponent(TestApplicationComponentManager.java:96)
[10:12:10]: ▸   at org.wordpress.android.WordPressTest_Application.generatedComponent(WordPressTest_Application.java:28)
[10:12:10]: ▸   at dagger.hilt.EntryPoints.get(EntryPoints.java:59)
[10:12:10]: ▸   at org.wordpress.android.WordPress.component(WordPress.kt:26)
[10:12:10]: ▸   at org.wordpress.android.push.GCMMessageService.onCreate(GCMMessageService.java:42)
[10:12:10]: ▸   at android.app.ActivityThread.handleCreateService(ActivityThread.java:3532)
[10:12:10]: ▸   ... 8 more
[10:12:10]: ▸ INSTRUMENTATION_RESULT: shortMsg=Process crashed.
[10:12:10]: ▸ INSTRUMENTATION_CODE: 0
irfano commented 1 year ago

I investigated this issue. I probably ran the test more than 100 times, but I could get the exception once. Test rules order looks correct. From the logs, I see that the issue is that the application is being created before HiltAndroidRule. I can't see why this exception is thrown only on JPScreenshotTest, it could be thrown on other classes too.

This is a very flaky test. @AliSoftware, if you see the same exception on other classes, please note here. It would be a great clue for the solution.