Commit 46b38899 authored by Him188's avatar Him188

Add more tests

parent e2bd8b20
...@@ -48,14 +48,14 @@ internal class LockFreeLinkedListTest { ...@@ -48,14 +48,14 @@ internal class LockFreeLinkedListTest {
} }
@Test @Test
fun addAndGetMassConcurrentAccess() = runBlocking { fun `so many concurrent add remove and foreach`() = runBlocking {
val list = LockFreeLinkedList<Int>() val list = LockFreeLinkedList<Int>()
val addJob = async { list.concurrentDo(2, 30000) { addLast(1) } } val addJob = async { list.concurrentDo(2, 30000) { addLast(1) } }
//delay(1) // let addJob fly //delay(1) // let addJob fly
if (addJob.isCompleted) { if (addJob.isCompleted) {
error("Number of elements are not enough") println("Number of elements are not enough")
} }
val foreachJob = async { val foreachJob = async {
list.concurrentDo(1, 10000) { list.concurrentDo(1, 10000) {
...@@ -170,6 +170,18 @@ internal class LockFreeLinkedListTest { ...@@ -170,6 +170,18 @@ internal class LockFreeLinkedListTest {
list.size shouldBeEqualTo 5 list.size shouldBeEqualTo 5
} }
@Test
fun `remove while foreach`() {
val list = LockFreeLinkedList<Int>()
list.addAll(listOf(1, 2, 3, 4, 5))
list.forEach {
list.remove(3)
}
list.toString() shouldBeEqualTo "[1, 2, 4, 5]"
}
@Test @Test
fun `filteringGetOrAdd when empty`() { fun `filteringGetOrAdd when empty`() {
val list = LockFreeLinkedList<Int>() val list = LockFreeLinkedList<Int>()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment