Skip to content

Commit f89463c

Browse files
committed
Remove runCancellableScopeTest and runCancellableScopeTestWithTestScope, we can use TestScope.backgroundScope instead.
1 parent b9c9706 commit f89463c

File tree

7 files changed

+68
-101
lines changed

7 files changed

+68
-101
lines changed

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/roomdirectory/RustRoomDirectoryListTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryList
1313
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustRoomDescription
1414
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRoomDirectorySearch
1515
import io.element.android.libraries.matrix.test.A_ROOM_ID_2
16-
import io.element.android.tests.testutils.runCancellableScopeTestWithTestScope
1716
import kotlinx.coroutines.CoroutineScope
1817
import kotlinx.coroutines.ExperimentalCoroutinesApi
1918
import kotlinx.coroutines.test.StandardTestDispatcher
2019
import kotlinx.coroutines.test.TestScope
2120
import kotlinx.coroutines.test.runCurrent
21+
import kotlinx.coroutines.test.runTest
2222
import org.junit.Test
2323
import org.matrix.rustcomponents.sdk.RoomDirectorySearch
2424
import org.matrix.rustcomponents.sdk.RoomDirectorySearchEntryUpdate
2525

2626
@OptIn(ExperimentalCoroutinesApi::class)
2727
class RustRoomDirectoryListTest {
2828
@Test
29-
fun `check that the state emits the expected values`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
29+
fun `check that the state emits the expected values`() = runTest {
3030
val fakeRoomDirectorySearch = FakeRoomDirectorySearch()
3131
val mapper = RoomDescriptionMapper()
32-
val sut = testScope.createRustRoomDirectoryList(
32+
val sut = createRustRoomDirectoryList(
3333
roomDirectorySearch = fakeRoomDirectorySearch,
34-
scope = cancellableScope,
34+
scope = backgroundScope,
3535
)
3636
// Let the mxCallback be ready
37-
testScope.runCurrent()
37+
runCurrent()
3838
sut.state.test {
3939
sut.filter("", 20)
4040
fakeRoomDirectorySearch.emitResult(

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/roomdirectory/RustRoomDirectoryServiceTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
package io.element.android.libraries.matrix.impl.roomdirectory
99

1010
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustClient
11-
import io.element.android.tests.testutils.runCancellableScopeTestWithTestScope
1211
import kotlinx.coroutines.test.StandardTestDispatcher
12+
import kotlinx.coroutines.test.runTest
1313
import org.junit.Test
1414

1515
class RustRoomDirectoryServiceTest {
1616
@Test
17-
fun test() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
17+
fun test() = runTest {
1818
val client = FakeRustClient()
1919
val sut = RustRoomDirectoryService(
2020
client = client,
21-
sessionDispatcher = StandardTestDispatcher(testScope.testScheduler),
21+
sessionDispatcher = StandardTestDispatcher(testScheduler),
2222
)
23-
sut.createRoomDirectoryList(cancellableScope)
23+
sut.createRoomDirectoryList(backgroundScope)
2424
}
2525
}

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/roomlist/RoomListFactoryTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ package io.element.android.libraries.matrix.impl.roomlist
99

1010
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustRoomList
1111
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustRoomListService
12-
import io.element.android.tests.testutils.runCancellableScopeTest
12+
import kotlinx.coroutines.test.runTest
1313
import org.junit.Test
1414
import kotlin.coroutines.EmptyCoroutineContext
1515

1616
class RoomListFactoryTest {
1717
@Test
18-
fun `createRoomList should work`() = runCancellableScopeTest {
18+
fun `createRoomList should work`() = runTest {
1919
val sut = RoomListFactory(
2020
innerRoomListService = FakeRustRoomListService(),
21-
sessionCoroutineScope = it,
21+
sessionCoroutineScope = backgroundScope,
2222
)
2323
sut.createRoomList(
2424
pageSize = 10,

libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/roomlist/RustRoomListServiceTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ import com.google.common.truth.Truth.assertThat
1111
import io.element.android.libraries.matrix.api.roomlist.RoomListService
1212
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeRustRoomListService
1313
import io.element.android.libraries.matrix.impl.room.RoomSyncSubscriber
14-
import io.element.android.tests.testutils.runCancellableScopeTestWithTestScope
1514
import io.element.android.tests.testutils.testCoroutineDispatchers
1615
import kotlinx.coroutines.CoroutineScope
1716
import kotlinx.coroutines.ExperimentalCoroutinesApi
1817
import kotlinx.coroutines.test.StandardTestDispatcher
1918
import kotlinx.coroutines.test.TestScope
2019
import kotlinx.coroutines.test.runCurrent
20+
import kotlinx.coroutines.test.runTest
2121
import org.junit.Test
2222
import org.matrix.rustcomponents.sdk.RoomListServiceSyncIndicator
2323
import org.matrix.rustcomponents.sdk.RoomListService as RustRoomListService
2424

2525
@OptIn(ExperimentalCoroutinesApi::class)
2626
class RustRoomListServiceTest {
2727
@Test
28-
fun `syncIndicator should emit the expected values`() = runCancellableScopeTestWithTestScope { testScope, cancellableScope ->
28+
fun `syncIndicator should emit the expected values`() = runTest {
2929
val roomListService = FakeRustRoomListService()
30-
val sut = testScope.createRustRoomListService(
31-
sessionCoroutineScope = cancellableScope,
30+
val sut = createRustRoomListService(
31+
sessionCoroutineScope = backgroundScope,
3232
roomListService = roomListService,
3333
)
3434
// Give time for mxCallback to setup
35-
testScope.runCurrent()
35+
runCurrent()
3636
sut.syncIndicator.test {
3737
assertThat(awaitItem()).isEqualTo(RoomListService.SyncIndicator.Hide)
3838
roomListService.emitRoomListServiceSyncIndicator(RoomListServiceSyncIndicator.SHOW)

services/analytics/impl/src/test/kotlin/io/element/android/services/analytics/impl/DefaultAnalyticsServiceTest.kt

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import io.element.android.services.analyticsproviders.api.AnalyticsProvider
2424
import io.element.android.services.analyticsproviders.test.FakeAnalyticsProvider
2525
import io.element.android.tests.testutils.lambda.lambdaRecorder
2626
import io.element.android.tests.testutils.lambda.value
27-
import io.element.android.tests.testutils.runCancellableScopeTest
2827
import kotlinx.coroutines.CompletableDeferred
2928
import kotlinx.coroutines.CoroutineScope
3029
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -37,31 +36,31 @@ import org.junit.Test
3736

3837
class DefaultAnalyticsServiceTest {
3938
@Test
40-
fun `getAvailableAnalyticsProviders return the set of provider`() = runCancellableScopeTest {
39+
fun `getAvailableAnalyticsProviders return the set of provider`() = runTest {
4140
val providers = setOf(
4241
FakeAnalyticsProvider(name = "provider1", stopLambda = { }),
4342
FakeAnalyticsProvider(name = "provider2", stopLambda = { }),
4443
)
4544
val sut = createDefaultAnalyticsService(
46-
coroutineScope = it,
45+
coroutineScope = backgroundScope,
4746
analyticsProviders = providers
4847
)
4948
val result = sut.getAvailableAnalyticsProviders()
5049
assertThat(result).isEqualTo(providers)
5150
}
5251

5352
@Test
54-
fun `when consent is not provided, capture is no op`() = runCancellableScopeTest {
55-
val sut = createDefaultAnalyticsService(it)
53+
fun `when consent is not provided, capture is no op`() = runTest {
54+
val sut = createDefaultAnalyticsService(backgroundScope)
5655
sut.capture(anEvent)
5756
}
5857

5958
@Test
60-
fun `when consent is provided, capture is sent to the AnalyticsProvider`() = runCancellableScopeTest {
59+
fun `when consent is provided, capture is sent to the AnalyticsProvider`() = runTest {
6160
val initLambda = lambdaRecorder<Unit> { }
6261
val captureLambda = lambdaRecorder<VectorAnalyticsEvent, Unit> { _ -> }
6362
val sut = createDefaultAnalyticsService(
64-
coroutineScope = it,
63+
coroutineScope = backgroundScope,
6564
analyticsStore = FakeAnalyticsStore(defaultUserConsent = true),
6665
analyticsProviders = setOf(
6766
FakeAnalyticsProvider(
@@ -76,17 +75,17 @@ class DefaultAnalyticsServiceTest {
7675
}
7776

7877
@Test
79-
fun `when consent is not provided, screen is no op`() = runCancellableScopeTest {
80-
val sut = createDefaultAnalyticsService(it)
78+
fun `when consent is not provided, screen is no op`() = runTest {
79+
val sut = createDefaultAnalyticsService(backgroundScope)
8180
sut.screen(aScreen)
8281
}
8382

8483
@Test
85-
fun `when consent is provided, screen is sent to the AnalyticsProvider`() = runCancellableScopeTest {
84+
fun `when consent is provided, screen is sent to the AnalyticsProvider`() = runTest {
8685
val initLambda = lambdaRecorder<Unit> { }
8786
val screenLambda = lambdaRecorder<VectorAnalyticsScreen, Unit> { _ -> }
8887
val sut = createDefaultAnalyticsService(
89-
coroutineScope = it,
88+
coroutineScope = backgroundScope,
9089
analyticsStore = FakeAnalyticsStore(defaultUserConsent = true),
9190
analyticsProviders = setOf(
9291
FakeAnalyticsProvider(
@@ -101,17 +100,17 @@ class DefaultAnalyticsServiceTest {
101100
}
102101

103102
@Test
104-
fun `when consent is not provided, trackError is no op`() = runCancellableScopeTest {
105-
val sut = createDefaultAnalyticsService(it)
103+
fun `when consent is not provided, trackError is no op`() = runTest {
104+
val sut = createDefaultAnalyticsService(backgroundScope)
106105
sut.trackError(anError)
107106
}
108107

109108
@Test
110-
fun `when consent is provided, trackError is sent to the AnalyticsProvider`() = runCancellableScopeTest {
109+
fun `when consent is provided, trackError is sent to the AnalyticsProvider`() = runTest {
111110
val initLambda = lambdaRecorder<Unit> { }
112111
val trackErrorLambda = lambdaRecorder<Throwable, Unit> { _ -> }
113112
val sut = createDefaultAnalyticsService(
114-
coroutineScope = it,
113+
coroutineScope = backgroundScope,
115114
analyticsStore = FakeAnalyticsStore(defaultUserConsent = true),
116115
analyticsProviders = setOf(
117116
FakeAnalyticsProvider(
@@ -126,10 +125,10 @@ class DefaultAnalyticsServiceTest {
126125
}
127126

128127
@Test
129-
fun `setUserConsent is sent to the store`() = runCancellableScopeTest {
128+
fun `setUserConsent is sent to the store`() = runTest {
130129
val store = FakeAnalyticsStore()
131130
val sut = createDefaultAnalyticsService(
132-
coroutineScope = it,
131+
coroutineScope = backgroundScope,
133132
analyticsStore = store,
134133
)
135134
assertThat(store.userConsentFlow.first()).isFalse()
@@ -140,10 +139,10 @@ class DefaultAnalyticsServiceTest {
140139
}
141140

142141
@Test
143-
fun `setAnalyticsId is sent to the store`() = runCancellableScopeTest {
142+
fun `setAnalyticsId is sent to the store`() = runTest {
144143
val store = FakeAnalyticsStore()
145144
val sut = createDefaultAnalyticsService(
146-
coroutineScope = it,
145+
coroutineScope = backgroundScope,
147146
analyticsStore = store,
148147
)
149148
assertThat(store.analyticsIdFlow.first()).isEqualTo("")
@@ -154,10 +153,10 @@ class DefaultAnalyticsServiceTest {
154153
}
155154

156155
@Test
157-
fun `setDidAskUserConsent is sent to the store`() = runCancellableScopeTest {
156+
fun `setDidAskUserConsent is sent to the store`() = runTest {
158157
val store = FakeAnalyticsStore()
159158
val sut = createDefaultAnalyticsService(
160-
coroutineScope = it,
159+
coroutineScope = backgroundScope,
161160
analyticsStore = store,
162161
)
163162
assertThat(store.didAskUserConsentFlow.first()).isFalse()
@@ -168,26 +167,26 @@ class DefaultAnalyticsServiceTest {
168167
}
169168

170169
@Test
171-
fun `when a session is deleted, the store is reset`() = runCancellableScopeTest {
170+
fun `when a session is deleted, the store is reset`() = runTest {
172171
val resetLambda = lambdaRecorder<Unit> { }
173172
val store = FakeAnalyticsStore(
174173
resetLambda = resetLambda,
175174
)
176175
val sut = createDefaultAnalyticsService(
177-
coroutineScope = it,
176+
coroutineScope = backgroundScope,
178177
analyticsStore = store,
179178
)
180179
sut.onSessionDeleted("userId")
181180
resetLambda.assertions().isCalledOnce()
182181
}
183182

184183
@Test
185-
fun `when reset is invoked, the user consent is reset`() = runCancellableScopeTest {
184+
fun `when reset is invoked, the user consent is reset`() = runTest {
186185
val store = FakeAnalyticsStore(
187186
defaultDidAskUserConsent = true,
188187
)
189188
val sut = createDefaultAnalyticsService(
190-
coroutineScope = it,
189+
coroutineScope = backgroundScope,
191190
analyticsStore = store,
192191
)
193192
assertThat(store.didAskUserConsentFlow.first()).isTrue()
@@ -196,9 +195,9 @@ class DefaultAnalyticsServiceTest {
196195
}
197196

198197
@Test
199-
fun `when a session is added, nothing happen`() = runCancellableScopeTest {
198+
fun `when a session is added, nothing happen`() = runTest {
200199
val sut = createDefaultAnalyticsService(
201-
coroutineScope = it,
200+
coroutineScope = backgroundScope,
202201
)
203202
sut.onSessionCreated("userId")
204203
}
@@ -231,10 +230,10 @@ class DefaultAnalyticsServiceTest {
231230
}
232231

233232
@Test
234-
fun `when consent is provided, updateUserProperties is sent to the provider`() = runCancellableScopeTest {
233+
fun `when consent is provided, updateUserProperties is sent to the provider`() = runTest {
235234
val updateUserPropertiesLambda = lambdaRecorder<UserProperties, Unit> { _ -> }
236235
val sut = createDefaultAnalyticsService(
237-
coroutineScope = it,
236+
coroutineScope = backgroundScope,
238237
analyticsProviders = setOf(
239238
FakeAnalyticsProvider(
240239
initLambda = { },
@@ -248,10 +247,10 @@ class DefaultAnalyticsServiceTest {
248247
}
249248

250249
@Test
251-
fun `when super properties are updated, updateSuperProperties is sent to the provider`() = runCancellableScopeTest {
250+
fun `when super properties are updated, updateSuperProperties is sent to the provider`() = runTest {
252251
val updateSuperPropertiesLambda = lambdaRecorder<SuperProperties, Unit> { _ -> }
253252
val sut = createDefaultAnalyticsService(
254-
coroutineScope = it,
253+
coroutineScope = backgroundScope,
255254
analyticsProviders = setOf(
256255
FakeAnalyticsProvider(
257256
initLambda = { },

0 commit comments

Comments
 (0)