Test restart readiness recovery and explicit UTF-8 database cleanup
This commit is contained in:
1 parent
f162724a93
commit
9aa645e2f1
3 files changed
+57
No files matched your search
@@ -8,6 +8,7 @@ import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
@@ -198,4 +199,51 @@ class CoreStartupTest {
|
||||
assertEquals("foreground denied", result?.message)
|
||||
assertTrue(logs.any { "stopSelf rejected" in it })
|
||||
}
|
||||
|
||||
@Test fun restartClosesOldReadinessAndCancelledWaiterDoesNotCancelRecovery() = runBlocking {
|
||||
nativeReady = true; start(); config.complete("config"); startup.awaitReady()
|
||||
nativeReady = false; startup.restarting()
|
||||
val retired = waiter(); val active = waiter()
|
||||
assertFalse(active.isCompleted); retired.cancel()
|
||||
nativeReady = true; startup.coreStarted()
|
||||
assertEquals(2, active.await()); assertTrue(retired.isCancelled)
|
||||
assertEquals(0, failures); assertEquals(1, submitted.size)
|
||||
}
|
||||
|
||||
@Test fun awaitClosesReadinessBeforeDelayedStoppedEventArrives() = runBlocking {
|
||||
nativeReady = true; start(); config.complete("config"); startup.awaitReady()
|
||||
nativeReady = false
|
||||
val pending = waiter(); assertFalse(pending.isCompleted)
|
||||
startup.coreStopped()
|
||||
nativeReady = true; startup.coreStarted()
|
||||
assertEquals(2, pending.await()); assertEquals(0, failures)
|
||||
}
|
||||
|
||||
@Test fun unexpectedCoreLossFailsRecoveryWaitersAndStopsTheService() = runBlocking {
|
||||
val owner = coordinator(timeout = 20)
|
||||
nativeReady = true; owner.start({ "config" }) { true }; owner.awaitReady()
|
||||
nativeReady = false; owner.coreStopped()
|
||||
val error = withTimeout(2_000) { runCatching { owner.awaitReady() }.exceptionOrNull() }
|
||||
withTimeout(2_000) { failed.await() }
|
||||
assertTrue(error is IllegalStateException); assertTrue(error!!.message!!.contains("recovery timeout"))
|
||||
assertEquals(1, failures)
|
||||
}
|
||||
|
||||
@Test fun serviceStopCancelsPendingRecoveryWithoutASecondFailure() = runBlocking {
|
||||
val owner = coordinator(timeout = 20)
|
||||
nativeReady = true; owner.start({ "config" }) { true }; owner.awaitReady()
|
||||
nativeReady = false; owner.restarting(); owner.stop()
|
||||
assertTrue(runCatching { owner.awaitReady() }.exceptionOrNull() is IllegalStateException)
|
||||
delay(40); nativeReady = true; owner.coreStarted()
|
||||
assertEquals(1, readyCalls); assertEquals(0, failures)
|
||||
}
|
||||
|
||||
@Test fun recoveryMonitorFailurePropagatesWithoutEscapingItsCoroutine() = runBlocking {
|
||||
nativeReady = true; start(); config.complete("config"); startup.awaitReady()
|
||||
nativeReady = false; startup.restarting()
|
||||
val pending = waiter(); readinessError = IllegalStateException("recovery monitor failed")
|
||||
nativeReady = true; startup.coreStarted()
|
||||
assertEquals("recovery monitor failed", runCatching { pending.await() }.exceptionOrNull()?.message)
|
||||
assertEquals(1, failures)
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,5 @@ JVM проверяет корректность вызовов JNI; ART и Andro
|
||||
Тот же запуск проверяет регистрацию/замену настоящего Java event callback, доставку payload,
|
||||
исключение обработчика с последующей успешной доставкой и сохранение чужого pending exception.
|
||||
Gradle запускает проверку как `:app:testJniUtf8` перед `:app:testDebugUnitTest` на Linux.
|
||||
Проверяются также повторные config callbacks, attach/detach native-потока и удаление БД
|
||||
по явно переданному пути с кириллицей/emoji через настоящий JNI entry point.
|
||||
@@ -78,6 +78,13 @@ int main(void) {
|
||||
Java_com_utun_chat_data_NativeLib_nativeSetEventCallback(env, NULL, NULL); CHECK(!(*env)->ExceptionCheck(env));
|
||||
jni_on_event(13, NULL, 0); CHECK(!(*env)->ExceptionCheck(env));
|
||||
(*env)->DeleteLocalRef(env, replacement); (*env)->DeleteLocalRef(env, sink); (*env)->DeleteLocalRef(env, sink_class);
|
||||
CHECK(!mkdir("база😀", 0700));
|
||||
FILE* database = fopen("база😀/chats.db", "wb"); CHECK(database && fputs("owned database", database) >= 0 && !fclose(database));
|
||||
jstring directory = jni_text(env, "база😀"); CHECK(directory);
|
||||
CHECK(Java_com_utun_chat_data_NativeLib_nativeClearDatabase(env, NULL, directory) == JNI_TRUE);
|
||||
CHECK(access("база😀/chats.db", F_OK) && errno == ENOENT);
|
||||
CHECK(Java_com_utun_chat_data_NativeLib_nativeClearDatabase(env, NULL, directory) == JNI_TRUE);
|
||||
(*env)->DeleteLocalRef(env, directory); CHECK(!rmdir("база😀"));
|
||||
jstring empty = jni_text(env, ""); CHECK(empty && !(*env)->GetStringLength(env, empty));
|
||||
(*env)->DeleteLocalRef(env, empty); (*env)->DeleteLocalRef(env, exception);
|
||||
(*env)->DeleteLocalRef(env, embedded); (*env)->DeleteLocalRef(env, original);
|
||||
|
||||
Reference in new issue
Block a user