Verify config saves survive cancellation of their submitting scope

This commit is contained in:
evgeny committed 2026-10-27 17:35:26 +01:00
1 parent 44f6d8a5bc
commit 02ec6a50a5
2 files changed
+13 -4

No files matched your search

@@ -9,6 +9,7 @@ import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@@ -52,8 +53,11 @@ class ConfigFileStoreTest {
val first = store.submit("blocked") { entered.countDown(); check(release.await(2, TimeUnit.SECONDS)) }
try {
assertTrue(entered.await(2, TimeUnit.SECONDS))
val save = store.submit("save") { replace(file, "complete") }
val screen = launch(start = CoroutineStart.UNDISPATCHED) { save.await() }
lateinit var save: Deferred<Unit>
val screen = launch(start = CoroutineStart.UNDISPATCHED) {
save = store.submit("save") { replace(file, "complete") }
save.await()
}
screen.cancelAndJoin()
assertFalse(save.isCancelled)
release.countDown()
@@ -5,6 +5,8 @@ import com.utun.chat.data.ConfigProvider
import com.utun.chat.data.ServerEntry
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.launch
import kotlinx.coroutines.cancelAndJoin
import java.util.concurrent.atomic.AtomicBoolean
@@ -62,8 +64,11 @@ fun main(args: Array<String>): Unit = runBlocking {
save.await()
check(provider.loadServersFromConfig().await().single().port == 3344)
val intent = provider.saveServersToConfig(listOf(ServerEntry("intent", "probe", "127.0.0.1", "tcp", 4455)))
val screen = launch { intent.await() }
lateinit var intent: Deferred<Unit>
val screen = launch(start = CoroutineStart.UNDISPATCHED) {
intent = provider.saveServersToConfig(listOf(ServerEntry("intent", "probe", "127.0.0.1", "tcp", 4455)))
intent.await()
}
screen.cancelAndJoin()
intent.await()
check(provider.loadServersFromConfig().await().single().port == 4455)