File tree 1 file changed +20
-0
lines changed
kotlinx-coroutines-core/common/test/channels
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -138,4 +138,24 @@ class ChannelUndeliveredElementTest : TestBase() {
138
138
channel.send(Unit )
139
139
finish(3 )
140
140
}
141
+
142
+ @Test
143
+ fun testChannelBufferOverflow () = runTest {
144
+ testBufferOverflowStrategy(3 , BufferOverflow .DROP_LATEST )
145
+ testBufferOverflowStrategy(1 , BufferOverflow .DROP_OLDEST )
146
+ }
147
+
148
+ private suspend fun testBufferOverflowStrategy (expectedDroppedElement : Int , strategy : BufferOverflow ) {
149
+ val list = ArrayList <Int >()
150
+ val channel = Channel <Int >(
151
+ capacity = 2 ,
152
+ onBufferOverflow = strategy,
153
+ onUndeliveredElement = { value -> list.add(value) }
154
+ )
155
+
156
+ (1 .. 3 ).forEach { value ->
157
+ channel.send(value)
158
+ }
159
+ assertEquals(expectedDroppedElement, list.single())
160
+ }
141
161
}
You can’t perform that action at this time.
0 commit comments