Skip to content

Commit 3f5a1ba

Browse files
DanTupCommit Queue
authored andcommitted
[dds/dap] Don't wait for 10s for outstanding requests/events when tests tear down
The DAP tests have some debug logging that prints if a request/event takes longer than 10 seconds to arrive. In the case where tests run quickly and the DAP client is torn down, these delays cause the test run to stay alive for 10 sec unnecessarily (and print irrelevant warnings). This changes that code to check periodically instead, and exits early if the client is torn down avoiding both the 10s wait and the spurious warning. Change-Id: Ic07826942e8ae307867820020b30595a42e68d15 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411680 Reviewed-by: Derek Xu <[email protected]> Commit-Queue: Derek Xu <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]>
1 parent b08d837 commit 3f5a1ba

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

pkg/dds/test/dap/integration/test_client.dart

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class DapTestClient {
8585
_subscription = _channel.listen(
8686
_handleMessage,
8787
onDone: () {
88+
_isStopping = true;
8889
if (_pendingRequests.isNotEmpty) {
8990
_logger?.call(
9091
'Application terminated without a response to ${_pendingRequests.length} requests');
@@ -486,10 +487,14 @@ class DapTestClient {
486487
sendRequest(StepOutArguments(threadId: threadId));
487488

488489
Future<void> stop() async {
490+
_isStopping = true;
489491
_channel.close();
490492
await _subscription.cancel();
491493
}
492494

495+
/// Whether this client is stopping (for any shutdown reason).
496+
bool _isStopping = false;
497+
493498
/// Whether or not any `terminate()` request has been sent.
494499
bool get hasSentTerminateRequest => _hasSentTerminateRequest;
495500
bool _hasSentTerminateRequest = false;
@@ -500,6 +505,7 @@ class DapTestClient {
500505
/// completes, or when a `terminated` event is received since it is not
501506
/// guaranteed that this request will return a response during a shutdown.
502507
Future<void> terminate() async {
508+
_isStopping = true;
503509
_hasSentTerminateRequest = true;
504510
return Future.any([
505511
event('terminated').then(
@@ -565,6 +571,7 @@ class DapTestClient {
565571
// tests are waiting on something that will never come, they fail at
566572
// a useful location.
567573
if (message.event == 'terminated') {
574+
_isStopping = true;
568575
unawaited(_eventController.close());
569576

570577
if (_stderr.isNotEmpty) {
@@ -587,13 +594,30 @@ class DapTestClient {
587594
}
588595

589596
/// Prints a warning if [future] takes longer than [_requestWarningDuration]
590-
/// to complete.
597+
/// to complete aid debugging test failures on bots from logs.
591598
///
592599
/// Returns [future].
593600
Future<T> _logIfSlow<T>(String name, Future<T> future) {
594-
final timer = Timer(_requestWarningDuration, () {
595-
print(
596-
'$name has taken longer than ${_requestWarningDuration.inSeconds}s');
601+
// Use a loop to periodically check so that we can exit earlier if
602+
// the test is being torn down.
603+
var endTime = DateTime.now().add(_requestWarningDuration);
604+
late Timer timer;
605+
timer = Timer.periodic(Duration(milliseconds: 100), (_) {
606+
// Shutting down, so just abort.
607+
if (_isStopping) {
608+
timer.cancel();
609+
return;
610+
}
611+
612+
// We've hit the warning threshold, report and then abort.
613+
if (DateTime.now().isAfter(endTime)) {
614+
print(
615+
'$name has taken longer than ${_requestWarningDuration.inSeconds}s');
616+
timer.cancel();
617+
return;
618+
}
619+
620+
// Otherwise, do nothing and check on the next tick.
597621
});
598622
return future.whenComplete(timer.cancel);
599623
}

0 commit comments

Comments
 (0)