Skip to content
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

Adding disk buffering, part 3 #194

Merged
merged 16 commits into from
Jan 12, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding tests
LikeTheSalad committed Dec 15, 2023
commit 452ed068a4be90e70f2c4645874447c8098c2874
Original file line number Diff line number Diff line change
@@ -88,6 +88,34 @@ class PeriodicWorkServiceTest {
assertThat(secondRunExecuted).isTrue()
}

@Test
fun `Remove delegated work from further executions`() {
val firstRunLatch = CountDownLatch(1)
val secondRunLatch = CountDownLatch(1)
var timesExecutedFirstWork = 0
var timesExecutedSecondWork = 0

// First run right away
service.enqueue {
timesExecutedFirstWork++
firstRunLatch.countDown()
}
service.start()
service.enqueue {
timesExecutedSecondWork++
secondRunLatch.countDown()
}
firstRunLatch.await()
assertThat(timesExecutedFirstWork).isEqualTo(1)
assertThat(timesExecutedSecondWork).isEqualTo(0)

// Second run after delay
fastForwardBySeconds(DELAY_BETWEEN_EXECUTIONS_IN_SECONDS)
secondRunLatch.await(1, TimeUnit.SECONDS)
assertThat(timesExecutedFirstWork).isEqualTo(1)
assertThat(timesExecutedSecondWork).isEqualTo(1)
}

private fun fastForwardBySeconds(seconds: Long) {
ShadowLooper.idleMainLooper(seconds, TimeUnit.SECONDS)
}