New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ShadowPausedLooper
to not use cached looperMode
in unPause
method
#9069
base: master
Are you sure you want to change the base?
Conversation
@warnyul Do you have evidence that it doesn't work as your expectation? |
@utzcoz With jUnit 4 I do not have evidence, because in that case line 63 solves this issue in SandboxManager.java. Because the key contains the I am only experiencing this issue with jUnit5, because I reuse the |
b09431b
to
c63b5f1
Compare
cc @brettchabot Are you trying to reuse the same sandbox for some tests that use PAUSED looper mode (the default) and some tests that use INSTRUMENTATION_TEST looper mode? I am not sure if that is supported right now. @brettchabot would know more. There are certain key parameters in Robolectric that will result in a new sandbox will be created. Looper mode is one of these. There is an LRU caching mechanism for sandboxes that tries to reuse sandboxes if possible. robolectric/robolectric/src/main/java/org/robolectric/internal/SandboxManager.java Lines 87 to 104 in 81831fc
So in the JUnit4 version of Robolectric, if a test runs with PAUSED looper mode, and then a subsequent test runs with INSTRUMENTATION_TEST looper mode, a new sandbox will be created. |
@hoisie Yes, I am trying to reuse the same sandbox. I have some test and it seems working: RobolectricExtensionLooperModeSelfTest In this case I just cleared the cached looper mode with reflection: https://github.com/apter-tech/junit5-robolectric-extension/pull/59/files#diff-f70ad8af7998e9e21db351e4d56ed03a59eef332f56919716375605a09e1a889R73 |
…method `unPause` is called from `resetLooperToInitialState` where the cached looper mode maybe already cleared. Use LooperMode from the registry instead.
c63b5f1
to
a406659
Compare
Overview
The
unPause
is called fromresetLooperToInitialState
, which means the cached looper mode might already have been reset. I think inunPause
the looper mode should get from the registry.Proposed Changes
Use
ConfigurationRegistry.get(LooperMode.Mode.class)
instead oflooperMode()
in theunPause
method.