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

Side by Side Diff: tests/standalone/io/test_runner_test.dart

Issue 12035053: Support for running a limited amount of browser tests in parallel (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:io";
6 import "dart:isolate"; 5 import "dart:isolate";
7 import "dart:async"; 6 import "dart:async";
8 import "dart:utf"; 7 import "dart:utf";
9 import "../../../tools/testing/dart/test_runner.dart"; 8 import "../../../tools/testing/dart/test_runner.dart";
9 import "../../../tools/testing/dart/test_suite.dart";
10 import "../../../tools/testing/dart/status_file_parser.dart"; 10 import "../../../tools/testing/dart/status_file_parser.dart";
11 import "../../../tools/testing/dart/test_options.dart"; 11 import "../../../tools/testing/dart/test_options.dart";
12 import "process_test_util.dart"; 12 import "process_test_util.dart";
13 13
14 final DEFAULT_TIMEOUT = 2;
15 final LONG_TIMEOUT = 30;
16
14 class TestController { 17 class TestController {
15 static const int numTests = 4; 18 static int numTests = 0;
16 static int numCompletedTests = 0; 19 static int numCompletedTests = 0;
17 20
18 // Used as TestCase.completedCallback. 21 // Used as TestCase.completedCallback.
19 static processCompletedTest(TestCase testCase) { 22 static processCompletedTest(TestCase testCase) {
23 numCompletedTests++;
20 CommandOutput output = testCase.lastCommandOutput; 24 CommandOutput output = testCase.lastCommandOutput;
21 print("Test: ${testCase.commands.last.commandLine}"); 25 if (testCase.displayName == "fail-unexpected") {
22 if (output.unexpectedOutput) { 26 Expect.isTrue(output.unexpectedOutput);
23 throw "Unexpected output: ${output.result}"; 27 } else {
28 Expect.isFalse(output.unexpectedOutput);
24 } 29 }
25 print("stdout: "); 30 }
26 print(decodeUtf8(output.stdout));
27 print("stderr: ");
28 print(decodeUtf8(output.stderr));
29 31
30 print("Time: ${output.time}"); 32 static void finished() {
31 print("Exit code: ${output.exitCode}"); 33 Expect.equals(numTests, numCompletedTests);
32
33 ++numCompletedTests;
34 print("$numCompletedTests/$numTests");
35 if (numCompletedTests == numTests) {
36 print("test_runner_test.dart PASSED");
37 }
38 } 34 }
39 } 35 }
40 36
41 TestCase MakeTestCase(String testName, List<String> expectations) { 37
42 var configuration = new TestOptionsParser().parse(['--timeout', '2'])[0]; 38 class CustomTestSuite extends TestSuite {
43 return new TestCase(testName, 39 CustomTestSuite() : super({}, "CustomTestSuite");
44 [new Command(new Options().executable, 40
45 <String>[new Options().script, 41 void forEachTest(TestCaseEvent onTest, Map testCache, [onDone]) {
46 testName])], 42 void enqueueTestCase(testCase) {
47 configuration, 43 TestController.numTests++;
48 TestController.processCompletedTest, 44 onTest(testCase);
49 new Set<String>.from(expectations)); 45 }
46
47 var testCaseCrash = _makeCrashTestCase("crash", [CRASH]);
48 var testCasePass = _makeNormalTestCase("pass", [PASS]);
49 var testCaseFail = _makeNormalTestCase("fail", [FAIL]);
50 var testCaseTimeout = _makeNormalTestCase("timeout", [TIMEOUT]);
51 var testCaseFailUnexpected =
52 _makeNormalTestCase("fail-unexpected", [PASS]);
53
54 enqueueTestCase(testCaseCrash);
55 enqueueTestCase(testCasePass);
56 enqueueTestCase(testCaseFail);
57 enqueueTestCase(testCaseTimeout);
58 enqueueTestCase(testCaseFailUnexpected);
59
60 if (onDone != null) {
61 onDone();
62 }
63 }
64
65 TestCase _makeNormalTestCase(name, expectations) {
66 var command = new Command(new Options().executable,
67 [new Options().script, name]);
68 return _makeTestCase(name, DEFAULT_TIMEOUT, command, expectations);
69 }
70
71 _makeCrashTestCase(name, expectations) {
72 var crashCommand = new Command(getProcessTestFileName(),
73 ["0", "0", "1", "1"]);
74 // The crash test sometimes times out. Run it with a large timeout
75 // to help diagnose the delay.
76 // The test loads a new executable, which may sometimes take a long time.
77 // It involves a wait on the VM event loop, and possible system
78 // delays.
79 return _makeTestCase(name, LONG_TIMEOUT, crashCommand, expectations);
80 }
81
82 _makeTestCase(name, timeout, command, expectations) {
83 var configuration = new TestOptionsParser()
84 .parse(['--timeout', '$timeout'])[0];
85 return new TestCase(name,
86 [command],
87 configuration,
88 TestController.processCompletedTest,
89 new Set<String>.from(expectations));
90 }
50 } 91 }
51 92
52 void testTestRunner() { 93 void testProcessQueue() {
53 new RunningProcess(MakeTestCase("pass", [PASS])).start(); 94 var maxProcesses = 2;
54 new RunningProcess(MakeTestCase("fail", [FAIL])).start(); 95 var maxBrowserProcesses = maxProcesses;
55 new RunningProcess(MakeTestCase("timeout", [TIMEOUT])).start(); 96 new ProcessQueue(maxProcesses, maxBrowserProcesses, "silent",
56 97 new Date.now(), false, [new CustomTestSuite()], TestController.finished);
57 // The crash test sometimes times out. Run it with a large timeout to help
58 // diagnose the delay.
59 // The test loads a new executable, which may sometimes take a long time.
60 // It involves a wait on the VM event loop, and possible system delays.
61 var configuration = new TestOptionsParser().parse(['--timeout', '60'])[0];
62 new RunningProcess(new TestCase("CrashTest",
63 [new Command(getProcessTestFileName(),
64 const ["0", "0", "1", "1"])],
65 configuration,
66 TestController.processCompletedTest,
67 new Set<String>.from([CRASH]))).start();
68 Expect.equals(4, TestController.numTests);
69 // Test that the test runner throws an exception if a test with
70 // expectation SKIP is run. The RunningProcess constructor must throw
71 // the exception synchronously, for it to be caught here at the call site.
72 Expect.throws(new RunningProcess(MakeTestCase("pass", [SKIP])).start);
73 } 98 }
74 99
75 void main() { 100 void main() {
76 // Run the test_runner_test if there are no command-line options. 101 // Run the test_runner_test if there are no command-line options.
77 // Otherwise, run one of the component tests that always pass, 102 // Otherwise, run one of the component tests that always pass,
78 // fail, or timeout. 103 // fail, or timeout.
79 var arguments = new Options().arguments; 104 var arguments = new Options().arguments;
80 if (arguments.isEmpty) { 105 if (arguments.isEmpty) {
81 testTestRunner(); 106 testProcessQueue();
82 } else { 107 } else {
83 switch (arguments[0]) { 108 switch (arguments[0]) {
84 case 'pass': 109 case 'pass':
85 return; 110 return;
111 case 'fail-unexpected':
86 case 'fail': 112 case 'fail':
87 Expect.fail("This test always fails, to test the test scripts."); 113 Expect.fail("This test always fails, to test the test scripts.");
88 » break; 114 break;
89 case 'timeout': 115 case 'timeout':
90 // Run for 10 seconds, then exit. This tests a 2 second timeout. 116 // Run for 10 seconds, then exit. This tests a 2 second timeout.
91 new Timer(10 * 1000, (t){ }); 117 new Timer(10 * 1000, (t){ });
92 break; 118 break;
93 default: 119 default:
94 throw "Unknown option ${arguments[0]} passed to test_runner_test"; 120 throw "Unknown option ${arguments[0]} passed to test_runner_test";
95 } 121 }
96 } 122 }
97 } 123 }
OLDNEW
« no previous file with comments | « tests/standalone/io/skipping_dart2js_compilations_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698