Skip to content

Commit 391db9c

Browse files
committed
make (normal) task group "dont leak" test use leaks and enable by default
1 parent 5b06fcf commit 391db9c

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

test/Concurrency/Runtime/async_taskgroup_dontLeakTasks.swift

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,39 @@
1-
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) 2>&1 | %FileCheck %s --dump-input=always
1+
// RUN: %target-run-simple-leaks-swift( -Xfrontend -disable-availability-checking -parse-as-library)
2+
3+
// This test uses `leaks` which is only available on apple platforms; limit it to macOS:
4+
// REQUIRES: OS=macosx
5+
26
// REQUIRES: executable_test
37
// REQUIRES: concurrency
4-
// REQUIRES: swift_task_debug_log
58

69
// REQUIRES: concurrency_runtime
710
// UNSUPPORTED: back_deployment_runtime
811

9-
#if os(Linux)
10-
import Glibc
11-
#elseif os(Windows)
12-
import MSVCRT
13-
#else
1412
import Darwin
15-
#endif
13+
14+
final class Something {
15+
let int: Int
16+
init(int: Int) {
17+
self.int = int
18+
}
19+
}
1620

1721
func test_taskGroup_next() async {
18-
// CHECK: creating task [[MAIN_TASK:0x.*]] with parent 0x0
19-
// CHECK: creating task [[GROUP_TASK_1:0x.*]] with parent [[MAIN_TASK]]
20-
// CHECK: creating task [[GROUP_TASK_2:0x.*]] with parent [[MAIN_TASK]]
21-
// CHECK: creating task [[GROUP_TASK_3:0x.*]] with parent [[MAIN_TASK]]
22-
// CHECK: creating task [[GROUP_TASK_4:0x.*]] with parent [[MAIN_TASK]]
23-
// CHECK: creating task [[GROUP_TASK_5:0x.*]] with parent [[MAIN_TASK]]
24-
25-
_ = await withTaskGroup(of: Int.self, returning: Int.self) { group in
26-
for n in 0..<5 {
22+
let tasks = 5
23+
_ = await withTaskGroup(of: Something.self, returning: Int.self) { group in
24+
for n in 0..<tasks {
2725
group.spawn {
28-
return n
26+
Something(int: n)
2927
}
3028
}
31-
await Task.sleep(2_000_000)
3229

3330
var sum = 0
3431
for await value in group {
35-
sum += 1
32+
sum += value.int
3633
}
3734

3835
return sum
3936
}
40-
// as we exit the group, it must be guaranteed that its child tasks were destroyed
41-
//
42-
// NOTE: there is no great way to express "any of GROUP_TASK_n",
43-
// so we just check that 5 tasks were destroyed
44-
//
45-
// CHECK: destroy task [[DESTROY_GROUP_TASK_1:0x.*]]
46-
// CHECK: destroy task [[DESTROY_GROUP_TASK_2:0x.*]]
47-
// CHECK: destroy task [[DESTROY_GROUP_TASK_3:0x.*]]
48-
// CHECK: destroy task [[DESTROY_GROUP_TASK_4:0x.*]]
49-
// CHECK: destroy task [[DESTROY_GROUP_TASK_5:0x.*]]
5037
}
5138

5239
@main struct Main {

0 commit comments

Comments
 (0)