Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci_verify_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ jobs:
if-no-files-found: ignore
retention-days: 7

unit-tests:
name: Unit tests
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: gradle

- name: Set up Android SDK
uses: android-actions/setup-android@v3

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Run unit tests
run: ./gradlew test --no-daemon --stacktrace

- name: Upload test reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-reports-${{ github.run_number }}
path: '**/build/reports/tests/**'
if-no-files-found: ignore
retention-days: 7

build:
name: Assemble debug
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.job
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Before
Expand Down Expand Up @@ -36,7 +37,12 @@ class DataStorePreferencesRepositoryTest {
PreferenceDataStoreFactory.create(scope = scope) { file }
return runBlocking { block(DataStorePreferencesRepository(store)) }
} finally {
// Cancelling is not enough: DataStore only releases its exclusive connection to the file
// once the scope's job has actually completed. Without joining, the next withRepository
// can open a second DataStore on the same file and fail with "There are multiple
// DataStores active for the same file" — a race that only shows up on slower machines.
scope.cancel()
runBlocking { scope.coroutineContext.job.join() }
}
}

Expand Down
Loading
Loading