Skip to content

Commit c7569dc

Browse files
committed
Add tests for RibEvents buffer size configuration
1 parent 51094ed commit c7569dc

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2024. Uber Technologies
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.uber.rib.core
17+
18+
import com.google.common.truth.Truth.assertThat
19+
import kotlinx.coroutines.ExperimentalCoroutinesApi
20+
import kotlinx.coroutines.channels.Channel
21+
import kotlinx.coroutines.launch
22+
import kotlinx.coroutines.test.runCurrent
23+
import kotlinx.coroutines.test.runTest
24+
import org.junit.After
25+
import org.junit.Before
26+
import org.junit.Ignore
27+
import org.junit.Test
28+
import org.mockito.kotlin.mock
29+
30+
@OptIn(ExperimentalCoroutinesApi::class)
31+
@Ignore(
32+
"""
33+
Test only passes when running in isolation: RibEvents flows might've been accessed
34+
when running full suite.
35+
""",
36+
)
37+
class RibEventsTest {
38+
private val extraBufferCapacity = 16
39+
40+
@Before
41+
fun setUp() {
42+
RibEvents.setExtraBufferCapacity(extraBufferCapacity)
43+
}
44+
45+
@After
46+
fun tearDown() {
47+
RibEvents.setExtraBufferCapacity(Channel.UNLIMITED)
48+
}
49+
50+
@Test
51+
fun setExtraBufferCapacityTest() = runTest {
52+
val results = mutableListOf<RibRouterEvent>()
53+
backgroundScope.launch { RibEvents.routerEventsFlow.collect(results::add) }
54+
runCurrent()
55+
repeat(32) { RibEvents.emitRouterEvent(RibEventType.ATTACHED, mock(), mock()) }
56+
runCurrent()
57+
assertThat(results.size).isEqualTo(16)
58+
}
59+
}

0 commit comments

Comments
 (0)