@@ -122,79 +122,95 @@ final class CAresDNSResolverTests: XCTestCase {
122
122
}
123
123
124
124
func test_concurrency( ) async throws {
125
+ let verbose = self . verbose
126
+
125
127
func run(
128
+ _ name: String ,
126
129
times: Int = 100 ,
127
130
_ query: @Sendable @escaping ( _ index: Int ) async throws -> Void
128
131
) async throws {
129
- try await withThrowingTaskGroup ( of: Void . self) { group in
130
- for i in 1 ... times {
131
- group. addTask {
132
- try await query ( i)
132
+ let start = Date . now
133
+ defer {
134
+ if verbose {
135
+ print ( " Test of \( name) took \( Int64 ( start. timeIntervalSinceNow * - 1000 ) ) ms. " )
136
+ }
137
+ }
138
+ do {
139
+ try await withThrowingTaskGroup ( of: Void . self) { group in
140
+ for i in 1 ... times {
141
+ group. addTask {
142
+ try await query ( i)
143
+ }
133
144
}
145
+ for try await _ in group { }
146
+ }
147
+ } catch {
148
+ if verbose {
149
+ print ( " Test of \( name) is throwing an error. " )
134
150
}
135
- for try await _ in group { }
151
+ throw error
136
152
}
137
153
}
138
154
139
155
let resolver = self . resolver!
140
- let verbose = self . verbose
141
- try await run { i in
156
+ try await run ( " queryA " ) { i in
142
157
let reply = try await resolver. queryA ( name: " apple.com " )
143
158
if verbose {
144
159
print ( " [A] run # \( i) result: \( reply) " )
145
160
}
146
161
}
147
162
148
- try await run { i in
163
+ try await run ( " queryAAAA " ) { i in
149
164
let reply = try await resolver. queryAAAA ( name: " apple.com " )
150
165
if verbose {
151
166
print ( " [AAAA] run # \( i) result: \( reply) " )
152
167
}
153
168
}
154
169
155
- try await run { i in
170
+ try await run ( " queryNS " ) { i in
156
171
let reply = try await resolver. queryNS ( name: " apple.com " )
157
172
if verbose {
158
173
print ( " [NS] run # \( i) result: \( reply) " )
159
174
}
160
175
}
161
176
162
- try await run { i in
177
+ try await run ( " queryCNAME " ) { i in
163
178
let reply = try await resolver. queryCNAME ( name: " www.apple.com " )
164
179
if verbose {
165
180
print ( " [CNAME] run # \( i) result: \( String ( describing: reply) ) " )
166
181
}
167
182
}
168
183
169
- try await run { i in
184
+ try await run ( " querySOA " ) { i in
170
185
let reply = try await resolver. querySOA ( name: " apple.com " )
171
186
if verbose {
172
187
print ( " [SOA] run # \( i) result: \( String ( describing: reply) ) " )
173
188
}
174
189
}
175
190
176
- try await run { i in
191
+ try await run ( " queryPTR " ) { i in
177
192
let reply = try await resolver. queryPTR ( name: " 47.224.172.17.in-addr.arpa " )
178
193
if verbose {
179
194
print ( " [PTR] run # \( i) result: \( reply) " )
180
195
}
181
196
}
182
197
183
- try await run { i in
198
+ try await run ( " queryMX " ) { i in
184
199
let reply = try await resolver. queryMX ( name: " apple.com " )
185
200
if verbose {
186
201
print ( " [MX] run # \( i) result: \( reply) " )
187
202
}
188
203
}
189
204
190
- try await run { i in
205
+ // TXT lookups are very slow in CI and lead to timeouts.
206
+ try await run ( " queryTXT " , times: 5 ) { i in
191
207
let reply = try await resolver. queryTXT ( name: " apple.com " )
192
208
if verbose {
193
209
print ( " [TXT] run # \( i) result: \( reply) " )
194
210
}
195
211
}
196
212
197
- try await run { i in
213
+ try await run ( " querySRV " ) { i in
198
214
let reply = try await resolver. querySRV ( name: " _caldavs._tcp.google.com " )
199
215
if verbose {
200
216
print ( " [SRV] run # \( i) result: \( reply) " )
0 commit comments