fix direct pairing probe timeout and speed up QR scanning
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user