1
1
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s
2
2
// TODO: move to target-run-simple-leaks-swift once CI is using at least Xcode 14.3
3
3
4
- // rdar://110025115 - Temporarily disable this test
5
- // REQUIRES: rdar110025115
6
-
7
4
// REQUIRES: concurrency
8
5
// REQUIRES: executable_test
9
6
// REQUIRES: concurrency_runtime
@@ -19,29 +16,76 @@ import _Concurrency
19
16
final class PayloadFirst { }
20
17
final class PayloadSecond { }
21
18
19
+ actor SimpleCountDownLatch {
20
+ let from : Int
21
+ var count : Int
22
+
23
+ var continuation : CheckedContinuation < Void , Never > ?
24
+
25
+ init ( from: Int ) {
26
+ self . from = from
27
+ self . count = from
28
+ }
29
+
30
+ func hit( ) {
31
+ defer { count -= 1 }
32
+ print ( " hit @ \( count) " )
33
+ if count == 0 {
34
+ fatalError ( " Counted down more times than expected! (From: \( from) ) " )
35
+ } else if count == 1 {
36
+ print ( " hit resume " )
37
+ print ( " resume " )
38
+ continuation? . resume ( )
39
+ }
40
+ }
41
+
42
+ func wait( ) async {
43
+ guard self . count > 0 else {
44
+ return // we're done
45
+ }
46
+
47
+ return await withCheckedContinuation { cc in
48
+ self . continuation = cc
49
+ }
50
+ }
51
+ }
52
+
22
53
final class ErrorFirst : Error {
23
54
let first : PayloadFirst
55
+ let id : String
56
+ let latch : SimpleCountDownLatch
24
57
25
- init ( file: String = #fileID, line: UInt = #line) {
58
+ init ( latch: SimpleCountDownLatch , file: String = #fileID, line: UInt = #line) {
59
+ self . latch = latch
60
+ self . id = " \( file) : \( line) "
26
61
first = . init( )
62
+ print ( " init \( self ) id: \( id) " )
27
63
}
28
64
deinit {
29
- print ( " deinit \( self ) " )
65
+ print ( " deinit \( self ) id: \( id) " )
66
+ Task { [ latch] in await latch. hit ( ) }
30
67
}
31
68
}
32
69
70
+ // Should not really matter that different types, but want to make really sure
33
71
final class ErrorSecond : Error {
34
- let second : PayloadSecond
72
+ let first : PayloadFirst
73
+ let id : String
74
+ let latch : SimpleCountDownLatch
35
75
36
- init ( file: String = #fileID, line: UInt = #line) {
37
- second = . init( )
76
+ init ( latch: SimpleCountDownLatch , file: String = #fileID, line: UInt = #line) {
77
+ self . latch = latch
78
+ self . id = " \( file) : \( line) "
79
+ first = . init( )
80
+ print ( " init \( self ) id: \( id) " )
38
81
}
39
-
40
82
deinit {
41
- print ( " deinit \( self ) " )
83
+ print ( " deinit \( self ) id: \( id) " )
84
+ Task { [ latch] in await latch. hit ( ) }
42
85
}
43
86
}
44
87
88
+
45
89
func shouldStartWith( _ lhs: Any , _ rhs: Any ) {
46
90
let l = " \( lhs) "
47
91
let r = " \( rhs) "
@@ -50,20 +94,25 @@ func shouldStartWith(_ lhs: Any, _ rhs: Any) {
50
94
51
95
// NOTE: Not as StdlibUnittest/TestSuite since these types of tests are unreasonably slow to load/debug.
52
96
97
+ @discardableResult
98
+ func one( ) -> Int {
99
+ 1
100
+ }
101
+
53
102
@main struct Main {
54
103
static func main( ) async {
104
+ let latch = SimpleCountDownLatch ( from: 6 )
55
105
do {
106
+
56
107
let got = try await withThrowingDiscardingTaskGroup ( ) { group in
57
- group. addTask {
58
- 1
59
- }
60
- group. addTask {
61
- throw ErrorFirst ( )
62
- }
108
+ group. addTask { one ( ) }
109
+ group. addTask { throw ErrorFirst ( latch: latch) }
110
+ group. addTask { throw ErrorFirst ( latch: latch) }
111
+ group. addTask { throw ErrorFirst ( latch: latch) }
63
112
64
- group. addTask {
65
- throw ErrorSecond ( )
66
- }
113
+ group. addTask { throw ErrorSecond ( latch : latch ) }
114
+ group . addTask { throw ErrorSecond ( latch : latch ) }
115
+ group . addTask { throw ErrorSecond ( latch : latch ) }
67
116
68
117
return 12
69
118
}
@@ -73,5 +122,12 @@ func shouldStartWith(_ lhs: Any, _ rhs: Any) {
73
122
}
74
123
// CHECK: deinit main.Error
75
124
// CHECK: deinit main.Error
125
+ // CHECK: deinit main.Error
126
+
127
+ // CHECK: deinit main.Error
128
+ // CHECK: deinit main.Error
129
+ // CHECK: deinit main.Error
130
+ await latch. wait ( )
131
+ print ( " done " ) // CHECK: done
76
132
}
77
133
}
0 commit comments