Skip to content

Commit

Permalink
Test staggering the GatewaySyncService tests tearDown
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Jan 23, 2024
1 parent 609a0d9 commit 5a6cd8a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +56,6 @@ class EndpointPreRegistrationServiceTest {
}

@Test
@Ignore("Failing on CI with RejectedExecutionException since ktor v2")
fun requestPreRegistration() = runTest(coroutineContext) {
val serviceIntent = Intent(
getApplicationContext<Context>(),
Expand Down Expand Up @@ -101,7 +99,6 @@ class EndpointPreRegistrationServiceTest {
}

@Test
@Ignore("Failing on CI with RejectedExecutionException since ktor v2")
fun invalidRequestIsIgnored() {
val serviceIntent = Intent(
getApplicationContext<Context>(),
Expand All @@ -116,7 +113,6 @@ class EndpointPreRegistrationServiceTest {
}

@Test
@Ignore("Failing on CI with RejectedExecutionException since ktor v2")
fun errorReturnedWhenGatewayIsNotRegisteredYet() = runTest(coroutineContext) {
internetGatewayPreferences.setRegistrationState(RegistrationState.ToDo)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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<Context>(),
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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {

Expand All @@ -45,16 +46,15 @@ class GatewaySyncServiceParcelDeliveryTest {
@Before
fun setUp() {
AppTestProvider.component.inject(this)
serviceRule.bindService(
Intent(
getApplicationContext<Context>(),
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"
Expand All @@ -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"
Expand Down

0 comments on commit 5a6cd8a

Please sign in to comment.