@@ -11,12 +11,15 @@ import kotlinx.coroutines.delay
1111import kotlinx.coroutines.launch
1212import kotlinx.coroutines.runBlocking
1313import org.junit.After
14- import org.junit.Assert.*
14+ import org.junit.Assert.assertEquals
15+ import org.junit.Assert.assertFalse
16+ import org.junit.Assert.assertTrue
1517import org.junit.Before
1618import org.junit.Test
1719import java.security.cert.X509Certificate
1820import java.util.Collections
1921import java.util.concurrent.Semaphore
22+ import java.util.logging.Logger
2023
2124class UserDecisionRegistryTest {
2225
@@ -26,6 +29,7 @@ class UserDecisionRegistryTest {
2629
2730 private val testCert = TestCertificates .testCert
2831
32+ private val logger = Logger .getGlobal()
2933
3034 @Before
3135 fun setUp () {
@@ -53,6 +57,33 @@ class UserDecisionRegistryTest {
5357 })
5458 }
5559
60+ @Test
61+ fun testCheck_MultipleDecisionsForSameCert_noPendingDecisionsAfterCancel () {
62+ val getUserDecision: suspend (X509Certificate ) -> Boolean = { _ ->
63+ delay(3000 ) // block for a while
64+ true
65+ }
66+
67+ runBlocking(Dispatchers .Default ) {
68+ val job = launch { registry.check(testCert, this , getUserDecision) }
69+ delay(1000 )
70+ job.cancel() // Cancel the job
71+ delay(1000 )
72+ }
73+
74+ // pendingDecisions should be empty
75+ synchronized(registry.pendingDecisions) {
76+ logger.info(" Before assert: " + registry.pendingDecisions.toString())
77+ assertFalse(registry.pendingDecisions.containsKey(testCert))
78+ }
79+
80+ // Do another check
81+ // runs forever if pendingDecisions is not empty; succeeds otherwise
82+ assertTrue(runBlocking(Dispatchers .Default ) {
83+ registry.check(testCert, this , getUserDecision)
84+ })
85+ }
86+
5687 @Test
5788 fun testCheck_MultipleDecisionsForSameCert_Negative () {
5889 val canSendFeedback = Semaphore (0 )
0 commit comments