blob: d613e342e85af6f41021f983b3c484fca54fbc63 [file] [log] [blame]
Roman Elizarovaa461cf2018-04-11 13:20:29 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovaa461cf2018-04-11 13:20:29 +03003 */
4
5package kotlinx.coroutines.experimental.sync
6
7import kotlinx.coroutines.experimental.*
8import kotlin.test.*
9
10class MutexStressTest : TestBase() {
11 @Test
12 fun testStress() = runTest {
13 val n = 1000 * stressTestMultiplier
14 val k = 100
15 var shared = 0
16 val mutex = Mutex()
17 val jobs = List(n) {
18 launch(CommonPool) {
19 repeat(k) {
20 mutex.lock()
21 shared++
22 mutex.unlock()
23 }
24 }
25 }
26 jobs.forEach { it.join() }
27 println("Shared value = $shared")
28 assertEquals(n * k, shared)
29 }
30}