Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: mojo/public/dart/third_party/test/test/runner/signal_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/dart/third_party/test/test/runner/signal_test.dart
diff --git a/mojo/public/dart/third_party/test/test/runner/signal_test.dart b/mojo/public/dart/third_party/test/test/runner/signal_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5397d0767b42e9abd8dfc62b79605c65ea010bd1
--- /dev/null
+++ b/mojo/public/dart/third_party/test/test/runner/signal_test.dart
@@ -0,0 +1,235 @@
+// Copyright (c) 2015, 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.
+
+// Windows doesn't support sending signals.
+@TestOn("vm && !windows")
+
+import 'dart:async';
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+import 'package:scheduled_test/descriptor.dart' as d;
+import 'package:scheduled_test/scheduled_process.dart';
+import 'package:scheduled_test/scheduled_stream.dart';
+import 'package:scheduled_test/scheduled_test.dart';
+
+import '../io.dart';
+
+String get _tempDir => p.join(sandbox, "tmp");
+
+// This test is inherently prone to race conditions. If it fails, it will likely
+// do so flakily, but if it succeeds, it will succeed consistently. The tests
+// represent a best effort to kill the test runner at certain times during its
+// execution.
+void main() {
+ useSandbox(() => d.dir("tmp").create());
+
+ group("during loading,", () {
+ test("cleans up if killed while loading a VM test", () {
+ d.file("test.dart", """
+void main() {
+ print("in test.dart");
+ // Spin for a long time so the test is probably killed while still loading.
+ for (var i = 0; i < 100000000; i++) {}
+}
+""").create();
+
+ var test = _runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough("in test.dart"));
+ signalAndQuit(test);
+
+ expectTempDirEmpty();
+ });
+
+ test("cleans up if killed while loading a browser test", () {
+ d.file("test.dart", "void main() {}").create();
+
+ var test = _runTest(["-p", "chrome", "test.dart"]);
+ test.stdout.expect(consumeThrough(endsWith("compiling test.dart")));
+ signalAndQuit(test);
+
+ expectTempDirEmpty();
+ });
+
+ test("exits immediately if ^C is sent twice", () {
+ d.file("test.dart", """
+void main() {
+ print("in test.dart");
+ while (true) {}
+}
+""").create();
+
+ var test = _runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough("in test.dart"));
+ test.signal(ProcessSignal.SIGTERM);
+
+ // TODO(nweiz): Sending two signals in close succession can cause the
+ // second one to be ignored, so we wait a bit before the second
+ // one. Remove this hack when issue 23047 is fixed.
+ schedule(() => new Future.delayed(new Duration(seconds: 1)));
+
+ signalAndQuit(test);
+ });
+ });
+
+ group("during test running", () {
+ test("waits for a VM test to finish running", () {
+ d.file("test.dart", """
+import 'dart:async';
+import 'dart:io';
+
+import 'package:test/test.dart';
+
+void main() {
+ tearDown(() => new File("output").writeAsStringSync("ran teardown"));
+
+ test("test", () {
+ print("running test");
+ return new Future.delayed(new Duration(seconds: 1));
+ });
+}
+""").create();
+
+ var test = _runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough("running test"));
+ signalAndQuit(test);
+
+ d.file("output", "ran teardown").validate();
+ expectTempDirEmpty();
+ });
+
+ test("kills a browser test immediately", () {
+ d.file("test.dart", """
+import 'dart:async';
+
+import 'package:test/test.dart';
+
+void main() {
+ test("test", () {
+ print("running test");
+
+ // Allow an event loop to pass so the preceding print can be handled.
+ return new Future(() {
+ // Loop forever so that if the test isn't stopped while running, it never
+ // stops.
+ while (true) {}
+ });
+ });
+}
+""").create();
+
+ var test = _runTest(["-p", "content-shell", "test.dart"]);
+ test.stdout.expect(consumeThrough("running test"));
+ signalAndQuit(test);
+
+ expectTempDirEmpty();
+ });
+
+ test("kills a VM test immediately if ^C is sent twice", () {
+ d.file("test.dart", """
+import 'package:test/test.dart';
+
+void main() {
+ test("test", () {
+ print("running test");
+ while (true) {}
+ });
+}
+""").create();
+
+ var test = _runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough("running test"));
+ test.signal(ProcessSignal.SIGTERM);
+
+ // TODO(nweiz): Sending two signals in close succession can cause the
+ // second one to be ignored, so we wait a bit before the second
+ // one. Remove this hack when issue 23047 is fixed.
+ schedule(() => new Future.delayed(new Duration(seconds: 1)));
+ signalAndQuit(test);
+ });
+
+ test("causes expect() to always throw an error immediately", () {
+ d.file("test.dart", """
+import 'dart:async';
+import 'dart:io';
+
+import 'package:test/test.dart';
+
+void main() {
+ var expectThrewError = false;
+
+ tearDown(() {
+ new File("output").writeAsStringSync(expectThrewError.toString());
+ });
+
+ test("test", () async {
+ print("running test");
+
+ await new Future.delayed(new Duration(seconds: 1));
+ try {
+ expect(true, isTrue);
+ } catch (_) {
+ expectThrewError = true;
+ }
+ });
+}
+""").create();
+
+ var test = _runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough("running test"));
+ signalAndQuit(test);
+
+ d.file("output", "true").validate();
+ expectTempDirEmpty();
+ });
+
+ test("causes expectAsync() to always throw an error immediately", () {
+ d.file("test.dart", """
+import 'dart:async';
+import 'dart:io';
+
+import 'package:test/test.dart';
+
+void main() {
+ var expectAsyncThrewError = false;
+
+ tearDown(() {
+ new File("output").writeAsStringSync(expectAsyncThrewError.toString());
+ });
+
+ test("test", () async {
+ print("running test");
+
+ await new Future.delayed(new Duration(seconds: 1));
+ try {
+ expectAsync(() {});
+ } catch (_) {
+ expectAsyncThrewError = true;
+ }
+ });
+}
+""").create();
+
+ var test = _runTest(["test.dart"]);
+ test.stdout.expect(consumeThrough("running test"));
+ signalAndQuit(test);
+
+ d.file("output", "true").validate();
+ expectTempDirEmpty();
+ });
+ });
+}
+
+ScheduledProcess _runTest(List<String> args) =>
+ runTest(args, environment: {"_UNITTEST_TEMP_DIR": _tempDir});
+
+void signalAndQuit(ScheduledProcess test) {
+ test.signal(ProcessSignal.SIGTERM);
+ test.shouldExit();
+ test.stderr.expect(isDone);
+}
+
+void expectTempDirEmpty() {
+ schedule(() => expect(new Directory(_tempDir).listSync(), isEmpty));
+}

Powered by Google App Engine
This is Rietveld 408576698