mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Retry held sessions with paced resumes, settle rollbacks and late answers, and end read-backs without a marker
This commit is contained in:
1 parent
0cd42b7217
commit
c46bb72631
5 files changed
+229
-28
No files matched your search
@@ -111,6 +111,8 @@ class SessionService : Service() {
|
||||
private var suspendOperationPending = false
|
||||
private var pipTask = false
|
||||
private var suspendAttemptFailed = false
|
||||
private val resumeRecovery = SuspendRecovery()
|
||||
private val retryResume = Runnable { updateSuspendPolicy() }
|
||||
private var freezePending = false
|
||||
private var freezeCancelled = false
|
||||
private var pendingSteamGameId: String? = null
|
||||
@@ -380,6 +382,8 @@ class SessionService : Service() {
|
||||
suspendOperationPending = false
|
||||
freezePending = false
|
||||
suspendAttemptFailed = false
|
||||
resumeRecovery.reset()
|
||||
mainHandler.removeCallbacks(retryResume)
|
||||
suspendController = null
|
||||
SessionState.micAvailable = false
|
||||
SessionState.micEnabled = false
|
||||
@@ -2180,7 +2184,10 @@ class SessionService : Service() {
|
||||
controller.cancelFreeze()
|
||||
}
|
||||
if (shouldSuspend && SessionState.suspended && !suspendOperationPending) SessionState.resumeRequested = false
|
||||
if (suspendOperationPending || suspendAttemptFailed || shouldSuspend == SessionState.suspended) return
|
||||
// A session still held after a failed suspend or resume is released by paced resumes, whatever the latch.
|
||||
val recovering = suspendAttemptFailed && SessionState.suspended && !shouldSuspend &&
|
||||
resumeRecovery.due(SystemClock.elapsedRealtime())
|
||||
if (suspendOperationPending || (suspendAttemptFailed && !recovering) || shouldSuspend == SessionState.suspended) return
|
||||
val gen = sessionGen
|
||||
suspendOperationPending = true
|
||||
SessionEvents.record(if (shouldSuspend) "session.suspend_requested" else "session.resume_requested", mapOf(
|
||||
@@ -2206,6 +2213,7 @@ class SessionService : Service() {
|
||||
if (success) {
|
||||
SessionState.suspended = true
|
||||
SessionState.resumeFailed = false
|
||||
resumeRecovery.reset()
|
||||
SessionEvents.transition(SessionPhase.SUSPENDED, "session.suspended")
|
||||
releaseLocks()
|
||||
refreshNotification()
|
||||
@@ -2242,6 +2250,9 @@ class SessionService : Service() {
|
||||
if (success) {
|
||||
SessionState.suspended = false
|
||||
SessionState.resumeFailed = false
|
||||
suspendAttemptFailed = false
|
||||
resumeRecovery.reset()
|
||||
mainHandler.removeCallbacks(retryResume)
|
||||
SessionEvents.transition(SessionEvents.resumePhase(), "session.resumed")
|
||||
refreshNotification()
|
||||
} else {
|
||||
@@ -2249,6 +2260,7 @@ class SessionService : Service() {
|
||||
SessionState.resumeFailures++
|
||||
SessionState.resumeFailed = true
|
||||
Log.w(TAG, "could not confirm that the session resumed")
|
||||
resumeRecovery.failed(SystemClock.elapsedRealtime())?.let { mainHandler.postDelayed(retryResume, it) }
|
||||
}
|
||||
updateSuspendPolicy()
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ internal class SessionSuspendController(
|
||||
// Asked to spill and not yet released by a resume count they saw: acknowledged or not, each may park its process.
|
||||
private var spillAsked = emptyList<ProcessRecord>()
|
||||
private var counterUnpublished = false
|
||||
// Spilled targets whose positive answer was taken (and its acknowledgement removed).
|
||||
private var spillWritten = emptyList<ProcessRecord>()
|
||||
|
||||
// A failed freeze that could not return every process to running: only a resume releases them.
|
||||
@Volatile var rollbackPending = false
|
||||
@@ -115,7 +117,9 @@ internal class SessionSuspendController(
|
||||
frozen = records.values.toList()
|
||||
if (complete && frozenSince == null) frozenSince = nowNanos()
|
||||
if (!complete) {
|
||||
if (restoreSafely(frozen)) frozen = emptyList()
|
||||
// A spilled process is back only once its helper has read it back: until then a resume retries.
|
||||
val running = startedAlive()
|
||||
if (restoreSafely(frozen) && awaitRestored(running)) frozen = emptyList()
|
||||
runAudio(resumeAudio)
|
||||
}
|
||||
rollbackPending = !complete && frozen.isNotEmpty()
|
||||
@@ -135,7 +139,7 @@ internal class SessionSuspendController(
|
||||
val records = frozen
|
||||
val advancedTo = advanceClock()
|
||||
runAudio(resumeAudio)
|
||||
val running = (spilledTargets + spillAsked).filterNot { isGone(it) }
|
||||
val running = startedAlive()
|
||||
val resumed = restoreSafely(records)
|
||||
if (resumed) {
|
||||
frozen = emptyList()
|
||||
@@ -153,7 +157,10 @@ internal class SessionSuspendController(
|
||||
closing = true
|
||||
submit({
|
||||
advanceClock()
|
||||
val running = startedAlive()
|
||||
if (restoreSafely(frozen)) frozen = emptyList()
|
||||
// the teardown asks the guests to exit, which a process still reading back cannot answer
|
||||
if (frozen.isEmpty()) awaitRestored(running, whileClosing = true)
|
||||
completion()
|
||||
executor.shutdown()
|
||||
}, completion)
|
||||
@@ -367,6 +374,7 @@ internal class SessionSuspendController(
|
||||
val unanswered = targets.filter { acks[it] == null && ackFile(control, "ack", it).exists() && !isGone(it) }
|
||||
spillAsked = spillAsked.filterNot { acks[it] == 0L || acks[it] == SPILL_CANCELLED }
|
||||
spilledTargets = (spilledTargets + written + unanswered).distinct()
|
||||
spillWritten = (spillWritten + written).distinct()
|
||||
pagedOutTargets = (pagedOutTargets + targets.filter { acks[it] == 0L }).distinct()
|
||||
targets.filterNot { it in unanswered }.forEach { ackFile(control, "ack", it).delete() }
|
||||
spilled(written.size, total, memoryKb(targets).first, nowMillis() - start)
|
||||
@@ -385,6 +393,7 @@ internal class SessionSuspendController(
|
||||
val lateZram = settledTargets.filter { readAck(ackFile(control, "ack", it)) == 0L && !isGone(it) }
|
||||
pagedOutTargets = (pagedOutTargets + lateZram).distinct()
|
||||
spillAsked = spillAsked.filterNot { it in settledTargets }
|
||||
spillWritten = spillWritten.filterNot { it in settledTargets }
|
||||
settledTargets.forEach {
|
||||
ackFile(control, "restored", it).delete()
|
||||
ackFile(control, "ack", it).delete()
|
||||
@@ -403,6 +412,15 @@ internal class SessionSuspendController(
|
||||
// put in place whole, so a failed write leaves the one before.
|
||||
private fun bumpResume(): Boolean {
|
||||
val control = zramControl?.takeIf { it.isFile } ?: return spillAsked.isEmpty()
|
||||
// A late answer of 0 or a cancellation already let its process go: it needs no count.
|
||||
val answered = spillAsked.filter {
|
||||
val ack = readAck(ackFile(control, "ack", it))
|
||||
ack == 0L || ack == SPILL_CANCELLED
|
||||
}
|
||||
if (answered.isNotEmpty()) {
|
||||
spilledTargets = spilledTargets.filterNot { it in answered }
|
||||
release(control, answered)
|
||||
}
|
||||
val counter = resumeFile(control)
|
||||
val ok = try {
|
||||
val next = resumeCount(control) + 1
|
||||
@@ -421,15 +439,15 @@ internal class SessionSuspendController(
|
||||
// True when every spilled process has its memory back (or was gone already). Ones still reading stay
|
||||
// tracked, so a later resume waits for them again. One of [running] that ends without its memory back fails
|
||||
// this resume.
|
||||
private fun awaitRestored(running: Collection<ProcessRecord> = emptyList()): Boolean {
|
||||
private fun awaitRestored(running: Collection<ProcessRecord> = emptyList(), whileClosing: Boolean = false): Boolean {
|
||||
val control = zramControl ?: return true
|
||||
val targets = spilledTargets
|
||||
if (targets.isEmpty()) return true
|
||||
val start = nowMillis()
|
||||
val waiting = targets.toMutableList()
|
||||
val untraced = HashMap<ProcessRecord, Long>()
|
||||
try {
|
||||
while (!closing && nowMillis() - start < RESTORE_TIMEOUT_MS) {
|
||||
waiting.removeAll { settled(control, it) }
|
||||
while (targets.isNotEmpty() && (whileClosing || !closing) && nowMillis() - start < RESTORE_TIMEOUT_MS) {
|
||||
waiting.removeAll { settled(control, it) || detached(control, it, untraced) }
|
||||
if (waiting.isEmpty()) break
|
||||
sleep(PAGE_OUT_POLL_MS)
|
||||
}
|
||||
@@ -438,15 +456,38 @@ internal class SessionSuspendController(
|
||||
}
|
||||
val lost = running.filter { record ->
|
||||
val ack = readAck(ackFile(control, "ack", record))
|
||||
record in targets && isGone(record) && readAck(ackFile(control, "restored", record)) == null &&
|
||||
ack != 0L && ack != SPILL_CANCELLED
|
||||
isGone(record) && readAck(ackFile(control, "restored", record)) == null && ack != 0L && ack != SPILL_CANCELLED
|
||||
}
|
||||
if (targets.isNotEmpty()) {
|
||||
release(control, targets.filterNot { it in waiting })
|
||||
spilledTargets = waiting.toList()
|
||||
restored(targets.size, waiting.size, memoryKb(targets).first, nowMillis() - start)
|
||||
}
|
||||
release(control, targets.filterNot { it in waiting })
|
||||
spilledTargets = waiting.toList()
|
||||
restored(targets.size, waiting.size, memoryKb(targets).first, nowMillis() - start)
|
||||
return waiting.isEmpty() && lost.isEmpty()
|
||||
}
|
||||
|
||||
// A process that wrote its spill is traced by its helper until the read-back ends; one that stays untraced
|
||||
// and alive for a while has its memory back even if the helper could not write its marker (a helper that
|
||||
// dies first has its owner killed).
|
||||
private fun detached(control: File, record: ProcessRecord, untraced: MutableMap<ProcessRecord, Long>): Boolean {
|
||||
if (record !in spillWritten && (readAck(ackFile(control, "ack", record)) ?: 0L) <= 0L) return false
|
||||
val current = try { readProcess(record.pid) } catch (_: IOException) { null }
|
||||
if (current == null || current.started != record.started || current.tracer != 0) {
|
||||
untraced.remove(record)
|
||||
return false
|
||||
}
|
||||
return nowMillis() - untraced.getOrPut(record) { nowMillis() } >= MARKER_GRACE_MS
|
||||
}
|
||||
|
||||
// Started or written spills of processes alive now: one of them that ends without its memory back is lost.
|
||||
private fun startedAlive(): List<ProcessRecord> {
|
||||
val control = zramControl ?: return emptyList()
|
||||
return (spilledTargets + spillAsked.filter { ackFile(control, "ack", it).exists() }).distinct().filter {
|
||||
val ack = readAck(ackFile(control, "ack", it))
|
||||
ack != 0L && ack != SPILL_CANCELLED && !isGone(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun pageOut(control: File, records: MutableMap<Pair<Int, Long>, ProcessRecord>, root: Int, helpers: List<Int>) {
|
||||
addSnapshot(records, root, helpers)
|
||||
val targets = preloaded(records.values)
|
||||
@@ -649,6 +690,7 @@ internal class SessionSuspendController(
|
||||
const val SPILL_CANCELLED = -2L
|
||||
const val SPILL_TIMEOUT_MS = 30_000L
|
||||
const val RESTORE_TIMEOUT_MS = 30_000L
|
||||
const val MARKER_GRACE_MS = 1_000L
|
||||
const val PAGE_OUT_POLL_MS = 100L
|
||||
const val PAGE_OUT_START_MS = 2_000L
|
||||
const val PAGE_OUT_TIMEOUT_MS = 12_000L
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
// Paced resume retries for a session that is still held after a failed suspend or resume.
|
||||
internal class SuspendRecovery(
|
||||
private val maxAttempts: Int = 5,
|
||||
private val firstDelayMs: Long = 5_000L,
|
||||
) {
|
||||
private var attempts = 0
|
||||
private var nextAt = 0L
|
||||
|
||||
fun due(now: Long): Boolean = attempts < maxAttempts && now >= nextAt
|
||||
|
||||
// The delay before the next attempt is due, or null when no attempt is left.
|
||||
fun failed(now: Long): Long? {
|
||||
attempts++
|
||||
if (attempts >= maxAttempts) return null
|
||||
val delay = firstDelayMs shl (attempts - 1)
|
||||
nextAt = now + delay
|
||||
return delay
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
attempts = 0
|
||||
nextAt = 0L
|
||||
}
|
||||
}
|
||||
@@ -234,6 +234,7 @@ class SessionSuspendControllerTest {
|
||||
assertTrue(it)
|
||||
assertEquals(listOf(1 to 0), fixture.restores)
|
||||
assertEquals(4_000_000L, fixture.gameResident)
|
||||
assertEquals(1, fixture.readBacks)
|
||||
assertTrue(fixture.game.threads.none { thread -> thread.state == 't' || thread.state == 'T' })
|
||||
called = true
|
||||
}
|
||||
@@ -249,11 +250,82 @@ class SessionSuspendControllerTest {
|
||||
fixture.startLateSpill()
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals(listOf(1 to 0), fixture.restores)
|
||||
assertEquals(0, fixture.readBacks)
|
||||
assertEquals(4_000_000L, fixture.gameResident)
|
||||
assertTrue(fixture.pagedIn.isEmpty())
|
||||
assertFalse(File(fixture.control.parentFile, ".dd-zram.ack.$GAME").exists())
|
||||
assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' })
|
||||
}
|
||||
|
||||
@Test fun aHelperThatReadsBackBeforeTheContinueStillResumes() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { assertTrue(it) }
|
||||
fixture.restoreDelayMs = 0L
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertTrue(fixture.releasedBeforeContinue)
|
||||
assertEquals(listOf(1 to 0), fixture.restores)
|
||||
assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' })
|
||||
}
|
||||
|
||||
@Test fun aLateSpillWithoutAnAcknowledgementFailsTheResumeUntilItsHelperLetsGo() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.handlerReplaced = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { }
|
||||
fixture.ackFails = true
|
||||
fixture.startLateSpill()
|
||||
fixture.restoreDelayMs = 5_000L
|
||||
fixture.controller.resume { assertFalse(it) }
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
fixture.advance(5_000L)
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals(1, fixture.readBacks)
|
||||
assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' })
|
||||
}
|
||||
|
||||
@Test fun aReadBackWhoseMarkerCouldNotBeWrittenEndsWhenTheHelperLetsGo() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.game.tracer = HELPER
|
||||
fixture.sync()
|
||||
fixture.markerFails = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { assertTrue(it) }
|
||||
val start = fixture.now
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertTrue(fixture.now - start < 5_000L)
|
||||
fixture.controller.freeze { assertTrue(it) }
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
}
|
||||
|
||||
@Test fun aLateFallbackDoesNotNeedTheCountWritten() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.spillSilent = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { }
|
||||
fixture.spillSilent = false
|
||||
fixture.spillFallsBack = true
|
||||
fixture.advance(1_000L)
|
||||
File(fixture.control.parentFile, ".dd-zram.resume.new").mkdirs()
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals(1, fixture.pagedIn.size)
|
||||
assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' })
|
||||
}
|
||||
|
||||
@Test fun aCancelledFreezeWhoseRestoreDoesNotFinishLeavesTheRollbackPending() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.restoreDelayMs = 60_000L
|
||||
fixture.afterSleep = { if (fixture.spills.isNotEmpty()) fixture.controller.cancelFreeze() }
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { assertFalse(it) }
|
||||
assertTrue(fixture.controller.rollbackPending)
|
||||
assertEquals(listOf(1 to 1), fixture.restores)
|
||||
fixture.afterSleep = null
|
||||
fixture.restoreDelayMs = 0L
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertFalse(fixture.controller.rollbackPending)
|
||||
}
|
||||
|
||||
@Test fun aSpilledGuestThatEndsWhileReadingBackFailsTheResume() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
@@ -779,13 +851,18 @@ class SessionSuspendControllerTest {
|
||||
val restores = mutableListOf<Pair<Int, Int>>()
|
||||
val resumeAtContinue = mutableListOf<String?>()
|
||||
var lateSpillSeesTheCount = false
|
||||
var markerFails = false
|
||||
var readBacks = 0
|
||||
val gameResident get() = gameResidentKb
|
||||
private var spilling = false
|
||||
private var spilledBase: String? = null
|
||||
private var restoring = false
|
||||
private var restoredPending = false
|
||||
private var gameStopPending = false
|
||||
private var continuedAt = -1L
|
||||
private var countSeenAt = -1L
|
||||
private var gameContinued = false
|
||||
var releasedBeforeContinue = false
|
||||
var ackFails = false
|
||||
private val resume = File(tmp, ".dd-zram.resume")
|
||||
private var continuing = false
|
||||
val controller = SessionSuspendController(
|
||||
@@ -808,6 +885,7 @@ class SessionSuspendControllerTest {
|
||||
|
||||
private fun signal(pid: Int, signal: Int) {
|
||||
signals += SentSignal(pid, signal)
|
||||
helperStep()
|
||||
val request = if (signal == URG) File(control.parentFile, "${control.name}.hold").takeIf { it.isFile }?.readText() else null
|
||||
if (signal == URG) held += request
|
||||
val group = groups.first { it.pid == pid }
|
||||
@@ -833,7 +911,7 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
continuing = true
|
||||
if (pid == GAME) gameStopPending = false
|
||||
if (pid == GAME && parked && continuedAt < 0) continuedAt = now
|
||||
if (pid == GAME) gameContinued = true
|
||||
// a spilled guest stays in its tracing stop until its helper has read the memory back
|
||||
if (!(pid == GAME && (blockGameContinue || parked))) group.threads.forEach { if (it.state != 'Z') it.state = 'S' }
|
||||
}
|
||||
@@ -854,7 +932,7 @@ class SessionSuspendControllerTest {
|
||||
private val parked get() = spilling || restoring
|
||||
|
||||
private fun releaseGame() {
|
||||
continuedAt = -1L
|
||||
countSeenAt = -1L
|
||||
game.threads.forEach { if (it.state != 'Z') it.state = if (gameStopPending) 'T' else 'S' }
|
||||
}
|
||||
|
||||
@@ -864,7 +942,30 @@ class SessionSuspendControllerTest {
|
||||
fun startLateSpill() {
|
||||
handlerReplaced = false
|
||||
spilling = true
|
||||
File(control.parentFile, "${control.name}.ack.$GAME").writeText("")
|
||||
if (!ackFails) File(control.parentFile, "${control.name}.ack.$GAME").writeText("")
|
||||
}
|
||||
|
||||
// The helper reads back as soon as it sees a new count, SIGCONT or not; it detaches first and publishes
|
||||
// its marker on a later step.
|
||||
private fun helperStep() {
|
||||
val count = resume.takeIf { it.isFile }?.readText()?.trim() ?: "0"
|
||||
if (restoredPending) {
|
||||
restoredPending = false
|
||||
if (!markerFails) File(control.parentFile, "${control.name}.restored.$GAME").writeText("120")
|
||||
}
|
||||
if (!restoring || count == spilledBase) return
|
||||
if (countSeenAt < 0) {
|
||||
countSeenAt = now
|
||||
gameContinued = false
|
||||
}
|
||||
if (now - countSeenAt < restoreDelayMs) return
|
||||
restoring = false
|
||||
readBacks++
|
||||
gameResidentKb = 4_000_000L
|
||||
if (markerFails) game.tracer = 0
|
||||
if (!gameContinued) releasedBeforeContinue = true
|
||||
releaseGame()
|
||||
restoredPending = true
|
||||
}
|
||||
|
||||
private fun sleep(millis: Long) {
|
||||
@@ -881,22 +982,12 @@ class SessionSuspendControllerTest {
|
||||
gameResidentKb = 0L
|
||||
ack.writeText("0")
|
||||
} else {
|
||||
ack.writeText(gameResidentKb.toString())
|
||||
if (!ackFails) ack.writeText(gameResidentKb.toString())
|
||||
gameResidentKb = 0L
|
||||
restoring = true
|
||||
}
|
||||
}
|
||||
// the helper detaches first and publishes its marker after
|
||||
if (restoredPending) {
|
||||
restoredPending = false
|
||||
File(control.parentFile, "${control.name}.restored.$GAME").writeText("120")
|
||||
}
|
||||
if (restoring && count != spilledBase && continuedAt >= 0 && now - continuedAt >= restoreDelayMs) {
|
||||
restoring = false
|
||||
gameResidentKb = 4_000_000L
|
||||
releaseGame()
|
||||
restoredPending = true
|
||||
}
|
||||
helperStep()
|
||||
if (pagingOut && !handlerReplaced) {
|
||||
File(control.parentFile, "${control.name}.ack.$GAME").apply { if (!exists()) writeText("") }
|
||||
}
|
||||
@@ -986,5 +1077,6 @@ class SessionSuspendControllerTest {
|
||||
const val CONT = 18
|
||||
const val URG = 23
|
||||
const val RESTORE_DELAY_MS = 300L
|
||||
const val HELPER = 300
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class SuspendRecoveryTest {
|
||||
@Test fun theFirstAttemptIsDueAtOnceAndLaterOnesBackOff() {
|
||||
val recovery = SuspendRecovery(maxAttempts = 3, firstDelayMs = 1_000L)
|
||||
assertTrue(recovery.due(0L))
|
||||
assertEquals(1_000L, recovery.failed(0L))
|
||||
assertFalse(recovery.due(999L))
|
||||
assertTrue(recovery.due(1_000L))
|
||||
assertEquals(2_000L, recovery.failed(1_000L))
|
||||
assertFalse(recovery.due(2_999L))
|
||||
assertTrue(recovery.due(3_000L))
|
||||
}
|
||||
|
||||
@Test fun attemptsAreBoundedUntilAResumeSucceeds() {
|
||||
val recovery = SuspendRecovery(maxAttempts = 2, firstDelayMs = 1_000L)
|
||||
recovery.failed(0L)
|
||||
assertNull(recovery.failed(1_000L))
|
||||
assertFalse(recovery.due(1_000_000L))
|
||||
recovery.reset()
|
||||
assertTrue(recovery.due(0L))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user