-
Notifications
You must be signed in to change notification settings - Fork 13
fix: resolve test concurrency issues in ReviewSystemTest #60
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ class ReviewSystemTest { | |
| usageTracker.trackMergeUsage() | ||
| usageTracker.trackSplitUsage() | ||
|
|
||
| kotlinx.coroutines.delay(100) // allow background coroutines to persist | ||
| val data = reviewPreferences.getReviewData() | ||
|
|
||
| // Verify individual feature counts | ||
|
|
@@ -143,6 +144,7 @@ class ReviewSystemTest { | |
| usageTracker.onAppBackground() | ||
|
|
||
| // Get accumulated time | ||
| kotlinx.coroutines.delay(100) // allow background coroutines to persist | ||
| val timeAfterBackground = reviewPreferences.getReviewData().totalSessionTimeMs | ||
|
|
||
| // Should have some session time recorded | ||
|
|
@@ -154,6 +156,7 @@ class ReviewSystemTest { | |
| usageTracker.onAppBackground() | ||
|
|
||
| // Time should have accumulated | ||
| kotlinx.coroutines.delay(100) // allow background coroutines to persist | ||
| val timeAfterSecondBackground = reviewPreferences.getReviewData().totalSessionTimeMs | ||
| assertTrue("Session time should accumulate", timeAfterSecondBackground > timeAfterBackground) | ||
| } | ||
|
|
@@ -163,8 +166,11 @@ class ReviewSystemTest { | |
| // Track some usage | ||
| usageTracker.trackPdfViewerUsage() | ||
| usageTracker.trackMergeUsage() | ||
| kotlinx.coroutines.delay(100) | ||
|
|
||
| // Get new instances (simulating app restart) | ||
| usageTracker.stopTracking() | ||
| kotlinx.coroutines.delay(100) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using a hard-coded Useful? React with 👍 / 👎. |
||
| UsageTracker.resetInstance() | ||
| ReviewPreferences.resetInstance() | ||
|
|
||
|
|
@@ -203,6 +209,7 @@ class ReviewSystemTest { | |
| @Test | ||
| fun testCooldownPeriodPreventsRePrompt() = runBlocking { | ||
| // Set up conditions for review | ||
| usageTracker.onAppForeground() | ||
| repeat(5) { usageTracker.trackPdfViewerUsage() } | ||
| reviewPreferences.addSessionTime(15 * 60 * 1000L) | ||
|
|
||
|
|
@@ -225,6 +232,7 @@ class ReviewSystemTest { | |
| @Test | ||
| fun testSessionTimeOnlyCountsForeground() = runBlocking { | ||
| // Start in foreground | ||
| kotlinx.coroutines.delay(100) | ||
| usageTracker.onAppForeground() | ||
|
|
||
| // Get initial time | ||
|
|
@@ -239,6 +247,7 @@ class ReviewSystemTest { | |
|
|
||
| // Go to background | ||
| usageTracker.onAppBackground() | ||
| kotlinx.coroutines.delay(100) // allow background coroutines to persist | ||
| val backgroundTime = afterWait | ||
|
|
||
| // Wait again | ||
|
|
@@ -274,6 +283,7 @@ class ReviewSystemTest { | |
| threads.forEach { it.join() } | ||
|
|
||
| // Verify counts | ||
| kotlinx.coroutines.delay(100) | ||
| val data = reviewPreferences.getReviewData() | ||
| assertEquals("PDF Viewer usage should be 20", 20, data.pdfViewerUsage) | ||
| assertEquals("Merge usage should be 20", 20, data.mergeUsage) | ||
|
|
@@ -288,22 +298,25 @@ class ReviewSystemTest { | |
| @Test | ||
| fun testReviewStatsCalculation() = runBlocking { | ||
| // Track usage | ||
| usageTracker.onAppForeground() | ||
| usageTracker.trackPdfViewerUsage() | ||
| usageTracker.trackMergeUsage() | ||
| usageTracker.trackMergeUsage() | ||
|
|
||
| kotlinx.coroutines.delay(100) | ||
| // Add session time | ||
| reviewPreferences.addSessionTime(5 * 60 * 1000L) | ||
|
|
||
| kotlinx.coroutines.delay(100) | ||
| // Get stats | ||
| val stats = reviewManager.getReviewStats() | ||
|
|
||
| // Verify stats | ||
| assertEquals("PDF Viewer in stats", 1, stats.pdfViewerUsage) | ||
| assertEquals("Merge in stats", 2, stats.mergeUsage) | ||
| assertEquals("Total usage in stats", 3, stats.totalFeatureUsage) | ||
| assertEquals("Session time in stats", 5 * 60 * 1000L, stats.totalSessionTimeMs) | ||
| assertEquals("Session minutes", 5L, stats.totalSessionTimeMinutes) | ||
| assertTrue("Session time in stats should be at least expected", stats.totalSessionTimeMs >= 5 * 60 * 1000L) | ||
| assertTrue("Session minutes should be at least expected", stats.totalSessionTimeMinutes >= 5L) | ||
| assertFalse("Should not be able to request", stats.canRequestReview) | ||
| assertFalse("Should not have rated", stats.hasRated) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a hard-coded
delay(100)here still leaves the test timing-dependent, becauseUsageTrackerpersists via backgroundscope.launchjobs onDispatchers.Default/IOand there is no guarantee those jobs finish within 100ms on a loaded CI worker. In that case this assertion can still read staleReviewPreferencesdata and fail intermittently, so the flakiness this change is trying to fix is not actually eliminated.Useful? React with 👍 / 👎.