fix direct pairing probe timeout and speed up QR scanning

This commit is contained in:
zhy200308
2026-08-12 11:26:59 +08:00
parent f9e25819ee
commit eccd93266e
6 changed files with 111 additions and 24 deletions
@@ -4,9 +4,51 @@ import org.junit.Assert.*
import org.junit.Test
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorCompletionService
import java.util.concurrent.Executors
import java.util.zip.CRC32
class ProtocolTest {
@Test
fun probeCompletionWaitsForARealResultInsteadOfConsumingAnEmptyPoll() {
val pool = Executors.newSingleThreadExecutor()
try {
val completion = ExecutorCompletionService<String?>(pool)
completion.submit(Callable {
Thread.sleep(380)
"http://192.168.137.1:39393"
})
assertEquals(
"http://192.168.137.1:39393",
awaitFirstNonNull(completion, submitted = 1, timeoutMs = 800),
)
} finally {
pool.shutdownNow()
}
}
@Test
fun probeCompletionKeepsWaitingAfterAnEarlierAddressFails() {
val pool = Executors.newFixedThreadPool(2)
try {
val completion = ExecutorCompletionService<String?>(pool)
completion.submit(Callable { null })
completion.submit(Callable {
Thread.sleep(30)
"http://192.168.137.1:39393"
})
assertEquals(
"http://192.168.137.1:39393",
awaitFirstNonNull(completion, submitted = 2, timeoutMs = 500),
)
} finally {
pool.shutdownNow()
}
}
@Test
fun routeCandidatesOnlyKeepEndpointsOnTheActiveSubnet() {
val endpoints = listOf(