Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental.sync |
| 6 | |
| 7 | import kotlinx.coroutines.experimental.* |
| 8 | import kotlin.test.* |
| 9 | |
| 10 | class 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 | } |