forked from Blendman974/faceclaw
Less-sensitive disconnect detection to avoid reconnect loops under BLE contention
This commit is contained in:
1 parent
7d8f03ffe5
commit
7684403491
6 files changed
+128
-6
No files matched your search
@@ -464,6 +464,59 @@ class GlassesSessionCoreTest {
|
||||
s.core.disconnect()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aCfwAckSlowerThanHalfASecondIsNotReplayed() {
|
||||
val s = Session()
|
||||
s.link.muted.add("image")
|
||||
s.startAndAwaitLayout()
|
||||
s.core.configureCompositorScreen(64, 32)
|
||||
s.core.configureSurface("s", 0, 0, 64, 32, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE)
|
||||
try {
|
||||
s.submitFrame(3, 0x20, 1)
|
||||
assertTrue(waitUntil(5_000) { s.link.cfwMessages().size == 1 })
|
||||
// Well past the old 500 ms deadline, but inside the 3 s ack window.
|
||||
s.platform.offsetMs += 1_500
|
||||
sleepMs(400)
|
||||
assertFalse(s.host.hasLog("CFW recovery"), s.host.logs().takeLast(10).toString())
|
||||
assertEquals(1, s.link.cfwMessages().size)
|
||||
// The late ack still completes the frame.
|
||||
val first = s.link.writes.first { it.sid == CfwTransport.SID && it.kind == "image" }
|
||||
val message = assertNotNull(s.core.monitor.withLock { s.core.inFlightMessages.firstOrNull { it.magic == first.magic } })
|
||||
for (lens in 1..2) {
|
||||
s.core.onNotification(LEFT, BleProtocol.NOTIFY_CHAR_UUID, cfwAck(first.magic, lens, message.message.size, message.cfwChecksum))
|
||||
}
|
||||
assertTrue(waitUntil(3_000) { s.displayedMatchesDesired() })
|
||||
} finally {
|
||||
s.core.close()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cfwAckDeadlinesFollowTheirOwnArmsWritesAndAcks() {
|
||||
val core = Session().core
|
||||
fun cfw(magic: Int, leftArm: Boolean) = OutboundMessage(
|
||||
"image", "m$magic", CfwTransport.SID, 0, magic, byteArrayOf(1), CfwMessageWindow.ACK_STALL_MS, 0, leftArm)
|
||||
val left = cfw(1, true)
|
||||
val right = cfw(2, false)
|
||||
core.monitor.withLock {
|
||||
for (message in listOf(left, right)) {
|
||||
message.sentAtMs = 1_000
|
||||
message.ackDeadlineAtMs = 4_000
|
||||
core.inFlightMessages.addLast(message)
|
||||
}
|
||||
core.lastArmCfwAckAtMs[0] = 2_000
|
||||
core.lastArmWriteAtMs[1] = 5_000
|
||||
core.refreshCfwAckDeadlinesLocked()
|
||||
}
|
||||
assertEquals(5_000L, left.ackDeadlineAtMs)
|
||||
assertEquals(5_500L, right.ackDeadlineAtMs)
|
||||
// Any CFW ack from an arm counts as that arm's progress, matched or not.
|
||||
val before = core.now()
|
||||
core.onNotification(LEFT, BleProtocol.NOTIFY_CHAR_UUID, cfwAck(77, 1, 1, 0))
|
||||
assertTrue(core.monitor.withLock { core.lastArmCfwAckAtMs[0] } >= before)
|
||||
assertEquals(0L, core.monitor.withLock { core.lastArmCfwAckAtMs[1] })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reconnectBackoffGrowsAndRestartsAfterAStableSession() {
|
||||
val core = Session().core
|
||||
|
||||
@@ -212,6 +212,18 @@ class ProtocolTest {
|
||||
assertTrue(CfwMessageWindow.canSend(listOf(eviction), upload))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cfwAckDeadlineWaitsWhileEitherWritesOrAcksProgress() {
|
||||
// Sent at 1000 into an idle arm: 3 s from the send.
|
||||
assertEquals(4_000L, CfwMessageWindow.ackDeadline(1_000, 1_000, 0))
|
||||
// An ack from the arm restarts the 3 s ack window.
|
||||
assertEquals(5_500L, CfwMessageWindow.ackDeadline(1_000, 1_000, 2_500))
|
||||
// Writes still completing keep it waiting past the ack window, 500 ms at a time.
|
||||
assertEquals(6_700L, CfwMessageWindow.ackDeadline(1_000, 6_200, 2_500))
|
||||
// An ack from before the send doesn't shorten anything.
|
||||
assertEquals(4_000L, CfwMessageWindow.ackDeadline(1_000, 1_000, 900))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun orderedCompletionAndWholeWindowRecovery() {
|
||||
val head = message()
|
||||
|
||||
Reference in new issue
Block a user