dart-sdk/tests/dartdevc/hot_restart_timer_test.dart
Nicholas Shahan 1332cf8c41 [ddc] Migrate tests in dartdevc suite
Change-Id: I2a35de7f79b8d768cdd0144b3bf5de87fa929942
Issue: https://github.com/dart-lang/sdk/issues/42107
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154301
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2020-07-15 00:16:03 +00:00

54 lines
1.4 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:expect/expect.dart';
import 'dart:async';
import 'dart:_runtime' as dart;
void main() 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);
}