dart-sdk/tests/dartdevc/hot_restart_timer_test.dart
Sigmund Cherem 7e8a203f1e [ddc] use async-helper in ddc's hot_restart_timer test
This test returned a future, which in other runtimes may mean that
the test would not be awaited for. The test-runner for DDC does include
extra asyncStart/asyncEnd to ensure the test runs to completion.
However, this sporadically caused double reporting and flaky failures
([example][1]).

This change makes the test itself track the async nature of the test,
just like we do in most other tests today.

[1]: https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8766055193681740753/+/u/test_results/ignored_flaky_test_failure_logs

Change-Id: Ib0edab197db21026d38b40036a1eeaf6edff5ad6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333300
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2023-11-02 15:37:14 +00:00

57 lines
1.5 KiB
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'dart:async';
import 'dart:_runtime' as dart;
void main() {
asyncTest(() async {
await timeoutTest();
await periodicTest();
});
}
Future<void> timeoutTest() async {
bool beforeRestart = true;
bool calledBeforeRestart = false;
bool calledAfterRestart = false;
void callback() {
if (beforeRestart) {
calledBeforeRestart = true;
} else {
calledAfterRestart = true;
}
}
Timer(Duration(milliseconds: 500), callback);
dart.hotRestart();
beforeRestart = false;
await new Future.delayed(Duration(milliseconds: 600));
Expect.isFalse(calledBeforeRestart);
Expect.isFalse(calledAfterRestart);
}
Future<void> periodicTest() async {
bool beforeRestart = true;
bool calledBeforeRestart = false;
bool calledAfterRestart = false;
void callback(_) {
if (beforeRestart) {
calledBeforeRestart = true;
} else {
calledAfterRestart = true;
}
}
Timer.periodic(Duration(milliseconds: 10), callback);
await new Future.delayed(Duration(milliseconds: 100));
dart.hotRestart();
beforeRestart = false;
await new Future.delayed(Duration(milliseconds: 100));
Expect.isTrue(calledBeforeRestart);
Expect.isFalse(calledAfterRestart);
}