fix: guard session clock logger lifecycle

This commit is contained in:
Kurt Himebauch committed 2026-11-05 14:00:30 -05:00
1 parent 5805631be5
commit ee0d8d9997
2 files changed
+23 -5

No files matched your search

@@ -27,7 +27,17 @@ class ClockLogComponentTest {
clocks = ClockLogComponent(log).also { it.attach(context); it.start() }
val deadline = System.currentTimeMillis() + 5_000
while (!log.readText().contains("| battery") && System.currentTimeMillis() < deadline) Thread.sleep(20)
val sample = log.readLines().last()
assertTrue(sample, sample.endsWith("| battery 41.2 C"))
assertTrue(log.readText(), log.readText().contains("| battery 41.2 C"))
context.sendStickyBroadcast(Intent(Intent.ACTION_BATTERY_CHANGED).putExtra(BatteryManager.EXTRA_TEMPERATURE, 423))
val updatedDeadline = System.currentTimeMillis() + 5_000
while (!log.readText().contains("| battery 42.3 C") && System.currentTimeMillis() < updatedDeadline) Thread.sleep(20)
assertTrue(log.readText(), log.readText().contains("| battery 42.3 C"))
}
@Test fun stoppedComponentCannotStartFromAnEarlierSnapshot() {
val context = RuntimeEnvironment.getApplication()
val log = tmp.newFile("stopped-clocks.log")
clocks = ClockLogComponent(log).also { it.attach(context); it.stop(); it.start() }
assertTrue(log.readText(), log.length() == 0L)
}
}