blob: 96a381f02764aced7e9544373436691cfd99bc8e [file] [log] [blame]
Roman Elizarove0b6db02018-04-28 19:22:29 +03001/*
2 * Copyright 2016-2017 JetBrains s.r.o.
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
17package kotlinx.coroutines.experimental
18
19import org.junit.*
20
21class AwaitJvmTest : TestBase() {
22 @Test
23 public fun testSecondLeak() = runTest {
24 // This test is to make sure that handlers installed on the second deferred do not leak
25 val d1 = CompletableDeferred<Int>()
26 val d2 = CompletableDeferred<Int>()
27 d1.completeExceptionally(TestException()) // first is crashed
28 val iterations = 3_000_000 * stressTestMultiplier
29 for (iter in 1..iterations) {
30 try {
31 awaitAll(d1, d2)
32 expectUnreached()
33 } catch (e: TestException) {
34 expect(iter)
35 }
36 }
37 finish(iterations + 1)
38 }
39
40 private class TestException : Exception()
41}