Skip to content

Commit 4e00733

Browse files
alexmarkovCommit Queue
authored andcommitted
[tests] Fix flaky standalone/io/http_auth_bearer_test
This test uses multiple asyncExpectThrows which are built on top of asyncStart/asyncEnd. Multiple top-level asyncStart/asyncEnd is not allowed, which caused the folllowing flaky error: Exception: Fatal: asyncStart() was called even though we are done with testing.. This is most likely a bug in your test. This change adds a top-level asyncStart/asyncEnd to enclose individual test cases. Also, awaits are added to make sure all test cases are completed before issuing the final asyncEnd. TEST=standalone/io/http_auth_bearer_test Change-Id: Ie0165c7a845928848451cfe37cf26e1292d208c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417221 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 924f3a3 commit 4e00733

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

tests/standalone/io/http_auth_bearer_test.dart

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ class Server {
6161
return this;
6262
}
6363

64-
void shutdown() {
65-
server.close();
66-
}
64+
Future<void> shutdown() => server.close();
6765

6866
String get host => server.address.address;
6967

@@ -83,7 +81,7 @@ void testCreateInvalidBearerTokens() {
8381
Expect.throws(() => HttpClientBearerCredentials(" "));
8482
}
8583

86-
void testBearerWithoutCredentials() async {
84+
Future<void> testBearerWithoutCredentials() async {
8785
final server = await Server().start();
8886
final client = HttpClient();
8987

@@ -100,11 +98,11 @@ void testBearerWithoutCredentials() async {
10098
],
10199
]);
102100

103-
server.shutdown();
101+
await server.shutdown();
104102
client.close();
105103
}
106104

107-
void testBearerWithCredentials() async {
105+
Future<void> testBearerWithCredentials() async {
108106
final server = await Server().start();
109107
final client = HttpClient();
110108

@@ -130,11 +128,11 @@ void testBearerWithCredentials() async {
130128
],
131129
]);
132130

133-
server.shutdown();
131+
await server.shutdown();
134132
client.close();
135133
}
136134

137-
void testBearerWithAuthenticateCallback() async {
135+
Future<void> testBearerWithAuthenticateCallback() async {
138136
final server = await Server().start();
139137
final client = HttpClient();
140138

@@ -165,11 +163,11 @@ void testBearerWithAuthenticateCallback() async {
165163
// assert that all authenticate callbacks have actually been called
166164
Expect.setEquals({for (int i = 0; i < 5; i++) "test$i"}, callbacks);
167165

168-
server.shutdown();
166+
await server.shutdown();
169167
client.close();
170168
}
171169

172-
void testMalformedAuthenticateHeaderWithoutCredentials() async {
170+
Future<void> testMalformedAuthenticateHeaderWithoutCredentials() async {
173171
final server = await Server().start();
174172
final client = HttpClient();
175173
final uri = Uri.parse(
@@ -178,13 +176,13 @@ void testMalformedAuthenticateHeaderWithoutCredentials() async {
178176

179177
// the request should resolve normally if no authentication is configured
180178
final request = await client.getUrl(uri);
181-
final response = await request.close();
179+
await request.close();
182180

183-
server.shutdown();
181+
await server.shutdown();
184182
client.close();
185183
}
186184

187-
void testMalformedAuthenticateHeaderWithCredentials() async {
185+
Future<void> testMalformedAuthenticateHeaderWithCredentials() async {
188186
final server = await Server().start();
189187
final client = HttpClient();
190188
final uri = Uri.parse(
@@ -197,15 +195,15 @@ void testMalformedAuthenticateHeaderWithCredentials() async {
197195
await asyncExpectThrows<HttpException>(
198196
Future(() async {
199197
final request = await client.getUrl(uri);
200-
final response = await request.close();
198+
await request.close();
201199
}),
202200
);
203201

204-
server.shutdown();
202+
await server.shutdown();
205203
client.close();
206204
}
207205

208-
void testMalformedAuthenticateHeaderWithAuthenticateCallback() async {
206+
Future<void> testMalformedAuthenticateHeaderWithAuthenticateCallback() async {
209207
final server = await Server().start();
210208
final client = HttpClient();
211209
final uri = Uri.parse(
@@ -217,15 +215,15 @@ void testMalformedAuthenticateHeaderWithAuthenticateCallback() async {
217215
await asyncExpectThrows<HttpException>(
218216
Future(() async {
219217
final request = await client.getUrl(uri);
220-
final response = await request.close();
218+
await request.close();
221219
}),
222220
);
223221

224-
server.shutdown();
222+
await server.shutdown();
225223
client.close();
226224
}
227225

228-
void testLocalServerBearer() async {
226+
Future<void> testLocalServerBearer() async {
229227
final client = HttpClient();
230228

231229
client.authenticate = (url, scheme, realm) async {
@@ -248,16 +246,18 @@ void testLocalServerBearer() async {
248246
client.close();
249247
}
250248

251-
main() {
249+
Future<void> main() async {
250+
asyncStart();
252251
testCreateValidBearerTokens();
253252
testCreateInvalidBearerTokens();
254-
testBearerWithoutCredentials();
255-
testBearerWithCredentials();
256-
testBearerWithAuthenticateCallback();
257-
testMalformedAuthenticateHeaderWithoutCredentials();
258-
testMalformedAuthenticateHeaderWithCredentials();
259-
testMalformedAuthenticateHeaderWithAuthenticateCallback();
253+
await testBearerWithoutCredentials();
254+
await testBearerWithCredentials();
255+
await testBearerWithAuthenticateCallback();
256+
await testMalformedAuthenticateHeaderWithoutCredentials();
257+
await testMalformedAuthenticateHeaderWithCredentials();
258+
await testMalformedAuthenticateHeaderWithAuthenticateCallback();
260259
// These tests are not normally run. They can be used for locally
261260
// testing with another web server (e.g. Apache).
262-
// testLocalServerBearer();
261+
// await testLocalServerBearer();
262+
asyncEnd();
263263
}

0 commit comments

Comments
 (0)