Skip to content

Commit

Permalink
Separate platform networking tests cases into separate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rorbech committed Aug 8, 2024
1 parent 0405bd9 commit 578f693
Showing 1 changed file with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,55 @@ class PlatformNetworkingTests {
private val TIMEOUT = 10.seconds

@Test
fun syncRoundTrip() = runBlocking {
setOf(false, true).forEach { platformNetworking ->
TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer, builder = {
it.usePlatformNetworking(platformNetworking)
}).use { app ->
val selector = org.mongodb.kbson.ObjectId().toString()
fun syncRoundTrip_coreNetworking() = runBlocking {
roundTrip(platformNetworking = false)
}

@Test
fun syncRoundTrip_platformNetworking() = runBlocking {
roundTrip(platformNetworking = true)
}

// Setup logger to capture WebSocketClient log messages
val logger = CustomLogCollector()
RealmLog.add(logger)
RealmLog.setLevel(LogLevel.ALL, LogCategory.Realm.Sdk)
private suspend fun roundTrip(platformNetworking: Boolean) {
TestApp(this::class.simpleName, DefaultFlexibleSyncAppInitializer, builder = {
it.usePlatformNetworking(platformNetworking)
}).use { app ->
val selector = org.mongodb.kbson.ObjectId().toString()

Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)).use { uploadRealm ->
Realm.open(createSyncConfig(app.createUserAndLogIn(), selector)).use { realm ->
uploadRealm.write {
copyToRealm(
SyncObjectWithAllTypes().apply {
stringField = selector
// Setup logger to capture WebSocketClient log messages
val logger = CustomLogCollector()
RealmLog.add(logger)
RealmLog.setLevel(LogLevel.DEBUG, LogCategory.Realm.Sdk)

Realm.open(createSyncConfig(app.createUserAndLogIn(), selector))
.use { uploadRealm ->
Realm.open(createSyncConfig(app.createUserAndLogIn(), selector))
.use { realm ->
uploadRealm.write {
copyToRealm(
SyncObjectWithAllTypes().apply {
stringField = selector
}
)
}
uploadRealm.syncSession.uploadAllLocalChanges(TIMEOUT)
withTimeout(TIMEOUT) {
realm.query<SyncObjectWithAllTypes>().asFlow().first {
it.list.size == 1
}.list.first().also {
assertEquals(selector, it.stringField)
}
)
}
uploadRealm.syncSession.uploadAllLocalChanges(TIMEOUT)
withTimeout(TIMEOUT) {
realm.query<SyncObjectWithAllTypes>().asFlow().first {
it.list.size == 1
}.list.first().also {
assertEquals(selector, it.stringField)
}
}
}
}
assertTrue(
if (platformNetworking) {
logger.logs.any { it.contains("\\[Websocket.*\\] onOpen".toRegex()) }
} else {
logger.logs.none { it.contains("\\[Websocket.*\\] onOpen".toRegex()) }
},
"Failed to verify log statements for : platformNetworking=$platformNetworking"
)
RealmLog.remove(logger)
}
assertTrue(

Check failure on line 73 in packages/test-sync/src/jvmTest/kotlin/io/realm/kotlin/test/mongodb/jvm/PlatformNetworkingTests.kt

View workflow job for this annotation

GitHub Actions / Unit Test Results - Sync JVM MacOS arm64

io.realm.kotlin.test.mongodb.jvm.PlatformNetworkingTests ► syncRoundTrip_coreNetworking[jvm]

Failed test found in: ./packages/test-sync/build/test-results/jvmTest/TEST-io.realm.kotlin.test.mongodb.jvm.PlatformNetworkingTests.xml Error: java.lang.AssertionError: Failed to verify log statements for : platformNetworking=false
Raw output
java.lang.AssertionError: Failed to verify log statements for : platformNetworking=false
	at org.junit.Assert.fail(Assert.java:89)
	at kotlin.test.junit.JUnitAsserter.fail(JUnitSupport.kt:56)
	at kotlin.test.Asserter$DefaultImpls.assertTrue(Assertions.kt:652)
	at kotlin.test.junit.JUnitAsserter.assertTrue(JUnitSupport.kt:30)
	at kotlin.test.Asserter$DefaultImpls.assertTrue(Assertions.kt:662)
	at kotlin.test.junit.JUnitAsserter.assertTrue(JUnitSupport.kt:30)
	at kotlin.test.AssertionsKt__AssertionsKt.assertTrue(Assertions.kt:44)
	at kotlin.test.AssertionsKt.assertTrue(Unknown Source)
	at io.realm.kotlin.test.mongodb.jvm.PlatformNetworkingTests.roundTrip(PlatformNetworkingTests.kt:73)
	at io.realm.kotlin.test.mongodb.jvm.PlatformNetworkingTests.access$roundTrip(PlatformNetworkingTests.kt:27)
	at io.realm.kotlin.test.mongodb.jvm.PlatformNetworkingTests$roundTrip$1.invokeSuspend(PlatformNetworkingTests.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:25)
	at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:24)
	at io.realm.kotlin.test.mongodb.jvm.PlatformNetworkingTests.syncRoundTrip_coreNetworking(PlatformNetworkingTests.kt:32)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:108)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:57)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52)
	at jdk.internal.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
if (platformNetworking) {
logger.logs.any { it.contains("\\[Websocket.*\\] onOpen".toRegex()) }
} else {
logger.logs.none { it.contains("\\[Websocket.*\\] onOpen".toRegex()) }
},
"Failed to verify log statements for : platformNetworking=$platformNetworking"
)
}
}

Expand Down

0 comments on commit 578f693

Please sign in to comment.