From 5a6cd8a99045087efc0f523ed8083bec434784bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Tue, 23 Jan 2024 17:07:36 +0000 Subject: [PATCH] Test staggering the GatewaySyncService tests tearDown --- .../EndpointPreRegistrationServiceTest.kt | 4 --- .../GatewaySyncServiceParcelCollectionTest.kt | 25 +++++++++++-------- .../GatewaySyncServiceParcelDeliveryTest.kt | 19 +++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/EndpointPreRegistrationServiceTest.kt b/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/EndpointPreRegistrationServiceTest.kt index 214a125d..537b8748 100644 --- a/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/EndpointPreRegistrationServiceTest.kt +++ b/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/EndpointPreRegistrationServiceTest.kt @@ -14,7 +14,6 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Before -import org.junit.Ignore import org.junit.Rule import org.junit.Test import tech.relaycorp.gateway.App @@ -57,7 +56,6 @@ class EndpointPreRegistrationServiceTest { } @Test - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") fun requestPreRegistration() = runTest(coroutineContext) { val serviceIntent = Intent( getApplicationContext(), @@ -101,7 +99,6 @@ class EndpointPreRegistrationServiceTest { } @Test - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") fun invalidRequestIsIgnored() { val serviceIntent = Intent( getApplicationContext(), @@ -116,7 +113,6 @@ class EndpointPreRegistrationServiceTest { } @Test - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") fun errorReturnedWhenGatewayIsNotRegisteredYet() = runTest(coroutineContext) { internetGatewayPreferences.setRegistrationState(RegistrationState.ToDo) diff --git a/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelCollectionTest.kt b/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelCollectionTest.kt index b8d223e2..03bdb826 100644 --- a/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelCollectionTest.kt +++ b/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelCollectionTest.kt @@ -4,10 +4,13 @@ import android.content.Context import android.content.Intent import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.rule.ServiceTestRule +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.take +import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.runTest +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Before @@ -29,6 +32,7 @@ import tech.relaycorp.relaynet.messages.Parcel import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath import javax.inject.Inject +import kotlin.coroutines.CoroutineContext class GatewaySyncServiceParcelCollectionTest { @@ -44,20 +48,22 @@ class GatewaySyncServiceParcelCollectionTest { @Inject lateinit var storeParcel: StoreParcel + private val coroutineContext + get() = UnconfinedTestDispatcher() + @Before fun setUp() { AppTestProvider.component.inject(this) - serviceRule.bindService( - Intent( - getApplicationContext(), - GatewaySyncService::class.java, - ), - ) + serviceRule.bindService(Intent(getApplicationContext(), GatewaySyncService::class.java)) + } + + @After + fun tearDown() { + Thread.sleep(3000) // Wait for netty to properly stop, to avoid a RejectedExecutionException } @Test - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") - fun parcelCollection_receiveParcel() = runTest { + fun parcelCollection_receiveParcel() = runTest(coroutineContext) { val parcel = ParcelFactory.buildSerialized() val storeResult = storeParcel.store(parcel, RecipientLocation.LocalEndpoint) assertTrue(storeResult is StoreParcel.Result.Success) @@ -81,8 +87,7 @@ class GatewaySyncServiceParcelCollectionTest { } @Test(expected = ServerConnectionException::class) - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") - fun parcelCollection_invalidHandshake() = runTest { + fun parcelCollection_invalidHandshake() = runTest(coroutineContext) { val parcel = ParcelFactory.buildSerialized() val storeResult = storeParcel.store(parcel, RecipientLocation.LocalEndpoint) assertTrue(storeResult is StoreParcel.Result.Success) diff --git a/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelDeliveryTest.kt b/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelDeliveryTest.kt index 3f36d157..7538575d 100644 --- a/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelDeliveryTest.kt +++ b/app/src/androidTest/java/tech/relaycorp/gateway/background/endpoint/GatewaySyncServiceParcelDeliveryTest.kt @@ -1,14 +1,14 @@ package tech.relaycorp.gateway.background.endpoint -import android.content.Context import android.content.Intent import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.rule.ServiceTestRule +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Before -import org.junit.Ignore import org.junit.Rule import org.junit.Test import tech.relaycorp.gateway.data.database.StoredParcelDao @@ -27,6 +27,7 @@ import tech.relaycorp.relaynet.testing.pki.PDACertPath import tech.relaycorp.relaynet.wrappers.x509.Certificate import java.time.ZonedDateTime import javax.inject.Inject +import kotlin.time.Duration.Companion.seconds class GatewaySyncServiceParcelDeliveryTest { @@ -45,16 +46,15 @@ class GatewaySyncServiceParcelDeliveryTest { @Before fun setUp() { AppTestProvider.component.inject(this) - serviceRule.bindService( - Intent( - getApplicationContext(), - GatewaySyncService::class.java, - ), - ) + serviceRule.bindService(Intent(getApplicationContext(), GatewaySyncService::class.java)) + } + + @After + fun tearDown() { + Thread.sleep(3000) // Wait for netty to properly stop, to avoid a RejectedExecutionException } @Test - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") fun parcelDelivery_validParcel() = runTest { setGatewayCertificate(PDACertPath.PRIVATE_GW) val recipientId = "0deadbeef" @@ -78,7 +78,6 @@ class GatewaySyncServiceParcelDeliveryTest { } @Test(expected = RejectedParcelException::class) - @Ignore("Failing on CI with RejectedExecutionException since ktor v2") fun parcelDelivery_invalidParcel() = runTest { val fiveMinutesAgo = ZonedDateTime.now().minusMinutes(5) val recipientId = "0deadbeef"