nowinandroid
nowinandroid copied to clipboard
Fix Windows unit test failing because of DataStore threading issue
This PR fixes issues on Windows environments, where DataStore threading is known to be buggy. A fix has been awaited for months now, but still remains... Replacing the default DataStore implementation with an in-memory fake avoids having to deal with file synchronization that lead to the issue.
Here is an example of such errors that appears on Windows env:
> Task :core:datastore:testDemoDebugUnitTest
com.google.samples.apps.nowinandroid.core.datastore.NiaPreferencesDataSourceTest > userShouldHideOnboarding_unfollowsLastTopic_shouldHideOnboardingIsFalse FAILED
java.io.IOException: Unable to rename C:\Users\RUNNER~1\AppData\Local\Temp\junit11942129073694190937\user_preferences_test.pb.tmp.This likely means that there are multiple instances of DataStore for this file. Ensure that you are only creating a single instance of datastore for this file.
It fixes both of these issues that can be closed:
- https://github.com/android/nowinandroid/issues/98
- https://github.com/android/nowinandroid/issues/1242
Here is a before/after (red/green) on a Windows env in GHA:
- https://github.com/SimonMarquis/nowinandroid/pull/21/commits
@dturner I don't know exactly how many Windows users there are in the wild building this project but I'm pretty sure it's not zero (I'm one of them). It'd great to fix unit tests for them :)
@dturner I don't know exactly how many Windows users there are in the wild building this project but I'm pretty sure it's not zero (I'm one of them). It'd great to fix unit tests for them :)
It is definitely not zero. I am one of the developers using Windows to build this project. : )
@dturner PTAL 🙏
I'll fix the badging issue in another PR.
- https://github.com/android/nowinandroid/pull/1648