Skip to content

Commit fe41d54

Browse files
Add --suite-load-timeout option (#2505)
Remove the hardcoded timeout and allow specifying a timeout for loading individual test suites.
1 parent ce6ef63 commit fe41d54

File tree

14 files changed

+143
-16
lines changed

14 files changed

+143
-16
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
## 1.29.1-wip
1+
## 1.30.0-wip
22

3+
* Add a `--suite-load-timeout` argument to allow configuring a timeout for
4+
compiling and loading individual test suites.
5+
* Remove the default 12 minute timeout to compile and load test suites.
6+
* Bump `test_core` to 0.6.16
37
* Add comments to the top-level libraries in the package.
48

59
## 1.29.0

pkgs/test/doc/configuration.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tags:
2626
2727
* [Test Configuration](#test-configuration)
2828
* [`timeout`](#timeout)
29+
* [`suite_load_timeout`](#suite_load_timeout)
2930
* [`ignore-timeouts`](#ignore-timeouts)
3031
* [`verbose_trace`](#verbose_trace)
3132
* [`chain_stack_traces`](#chain_stack_traces)
@@ -97,9 +98,27 @@ formats:
9798
timeout: 1m
9899
```
99100

101+
### `suite_load_timeout`
102+
103+
This field indicates how much time the test runner should allow for compiling
104+
and loading a test suite before it considers that suite to have failed. It has
105+
two possible formats:
106+
107+
* The string "none" indicates that loading suites should never time out.
108+
109+
* A number followed by a unit abbreviation indicates an exact time. For example,
110+
"1m" means a timeout of one minute, and "30s" means a timeout of thirty
111+
seconds. Multiple numbers can be combined, as in "1m 30s".
112+
113+
```yaml
114+
suite_load_timeout: 1m
115+
```
116+
100117
### `ignore-timeouts`
101118

102-
This field disables all timeouts for all tests. This can be useful when debugging, so tests don't time out during debug sessions. It defaults to `false`.
119+
This field disables all timeouts for all tests. This can be useful when
120+
debugging, so tests don't time out during debug sessions. It defaults to
121+
`false`.
103122

104123
```yaml
105124
ignore-timeouts: true

pkgs/test/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test
2-
version: 1.29.1-wip
2+
version: 1.30.0-wip
33
description: >-
44
A full featured library for writing and running Dart tests across platforms.
55
repository: https://github.com/dart-lang/test/tree/master/pkgs/test
@@ -36,7 +36,7 @@ dependencies:
3636

3737
# Use an exact version until the test_api and test_core package are stable.
3838
test_api: 0.7.9
39-
test_core: 0.6.15
39+
test_core: 0.6.16-wip
4040

4141
typed_data: ^1.3.0
4242
web_socket_channel: '>=2.0.0 <4.0.0'

pkgs/test/test/runner/configuration/top_level_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,34 @@ void main() {
448448
await test.shouldExit(1);
449449
});
450450

451+
test('uses the specified suite load timeout', () async {
452+
await d
453+
.file('dart_test.yaml', jsonEncode({'suite_load_timeout': '1s'}))
454+
.create();
455+
456+
await d.file('test.dart', '''
457+
import 'dart:async';
458+
459+
import 'package:test/test.dart';
460+
461+
Future<void> main() async {
462+
await Future.delayed(Duration(seconds: 2));
463+
test('success', () {});
464+
}
465+
''').create();
466+
467+
var test = await runTest(['test.dart']);
468+
expect(
469+
test.stdout,
470+
containsInOrder([
471+
'loading test.dart [E]',
472+
'Test timed out after 1 seconds.',
473+
'-1: Some tests failed.',
474+
]),
475+
);
476+
await test.shouldExit(1);
477+
});
478+
451479
test('runs on the specified platforms', () async {
452480
await d
453481
.file(

pkgs/test/test/runner/runner_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ $_runtimeCompilers
8585
--shard-index The index of this test runner invocation (of --total-shards).
8686
--timeout The default test timeout. For example: 15s, 2x, none
8787
(defaults to "30s")
88+
--suite-load-timeout The timeout for loading a test suite. Loading the test suite includes compiling the test suite. For example: 15s, 2m, none
89+
(defaults to "none")
8890
--ignore-timeouts Ignore all timeouts (useful if debugging)
8991
--pause-after-load Pause for debugging before any tests execute.
9092
Implies --concurrency=1, --debug, and --ignore-timeouts.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:test/test.dart';
9+
import 'package:test_descriptor/test_descriptor.dart' as d;
10+
11+
import '../io.dart';
12+
13+
void main() {
14+
setUpAll(precompileTestExecutable);
15+
16+
test('uses the passed suite load timeout', () async {
17+
await d.file('test.dart', '''
18+
import 'dart:async';
19+
20+
import 'package:test/test.dart';
21+
22+
Future<void> main() async {
23+
await Future.delayed(Duration(seconds: 2));
24+
test('success', () {});
25+
}
26+
''').create();
27+
28+
var test = await runTest(['--suite-load-timeout=1s', 'test.dart']);
29+
expect(
30+
test.stdout,
31+
containsInOrder([
32+
'loading test.dart [E]',
33+
'Test timed out after 1 seconds.',
34+
'-1: Some tests failed.',
35+
]),
36+
);
37+
await test.shouldExit(1);
38+
});
39+
}

pkgs/test/test/utils.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ SuiteConfiguration suiteConfiguration({
181181
Map<BooleanSelector, SuiteConfiguration>? tags,
182182
Map<PlatformSelector, SuiteConfiguration>? onPlatform,
183183
bool? ignoreTimeouts,
184+
Timeout? suiteLoadTimeout,
184185

185186
// Test-level configuration
186187
Timeout? timeout,
@@ -203,6 +204,7 @@ SuiteConfiguration suiteConfiguration({
203204
tags: tags,
204205
onPlatform: onPlatform,
205206
ignoreTimeouts: ignoreTimeouts,
207+
suiteLoadTimeout: suiteLoadTimeout,
206208
timeout: timeout,
207209
verboseTrace: verboseTrace,
208210
chainStackTraces: chainStackTraces,
@@ -256,6 +258,7 @@ Configuration configuration({
256258
Map<BooleanSelector, SuiteConfiguration>? tags,
257259
Map<PlatformSelector, SuiteConfiguration>? onPlatform,
258260
int? testRandomizeOrderingSeed,
261+
Timeout? suiteLoadTimeout,
259262

260263
// Test-level configuration
261264
Timeout? timeout,
@@ -307,6 +310,7 @@ Configuration configuration({
307310
tags: tags,
308311
onPlatform: onPlatform,
309312
testRandomizeOrderingSeed: testRandomizeOrderingSeed,
313+
suiteLoadTimeout: suiteLoadTimeout,
310314
stopOnFirstFailure: false,
311315
timeout: timeout,
312316
verboseTrace: verboseTrace,

pkgs/test_core/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.16-wip
2+
3+
* Add `SuiteConfiguration.suiteLoadTimeout` to configure the timeout for loading a test suite.
4+
* Removed hard-coded timeout of 12m for loading a test suite and set default to `none`.
5+
16
## 0.6.15
27

38
* Add `--coverage-package` flag, which filters the coverage report to specific

pkgs/test_core/lib/src/runner/configuration.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class Configuration {
311311
required Map<BooleanSelector, SuiteConfiguration>? tags,
312312
required Map<PlatformSelector, SuiteConfiguration>? onPlatform,
313313
required bool? ignoreTimeouts,
314+
required Timeout? suiteLoadTimeout,
314315

315316
// Test-level configuration
316317
required Timeout? timeout,
@@ -366,6 +367,7 @@ class Configuration {
366367
tags: tags,
367368
onPlatform: onPlatform,
368369
ignoreTimeouts: ignoreTimeouts,
370+
suiteLoadTimeout: suiteLoadTimeout,
369371

370372
// Test-level configuration
371373
timeout: timeout,
@@ -429,6 +431,7 @@ class Configuration {
429431
Map<BooleanSelector, SuiteConfiguration>? tags,
430432
Map<PlatformSelector, SuiteConfiguration>? onPlatform,
431433
bool? ignoreTimeouts,
434+
Timeout? suiteLoadTimeout,
432435

433436
// Test-level configuration
434437
Timeout? timeout,
@@ -481,6 +484,7 @@ class Configuration {
481484
tags: tags,
482485
onPlatform: onPlatform,
483486
ignoreTimeouts: ignoreTimeouts,
487+
suiteLoadTimeout: suiteLoadTimeout,
484488
timeout: timeout,
485489
verboseTrace: verboseTrace,
486490
chainStackTraces: chainStackTraces,
@@ -500,6 +504,7 @@ class Configuration {
500504
required bool? verboseTrace,
501505
required bool? jsTrace,
502506
required Timeout? timeout,
507+
required Timeout? suiteLoadTimeout,
503508
required Map<String, Configuration>? presets,
504509
required bool? chainStackTraces,
505510
required Iterable<String>? foldTraceExcept,
@@ -537,6 +542,7 @@ class Configuration {
537542
testRandomizeOrderingSeed: null,
538543
stopOnFirstFailure: null,
539544
ignoreTimeouts: null,
545+
suiteLoadTimeout: suiteLoadTimeout,
540546
allowDuplicateTestNames: null,
541547
allowTestRandomization: null,
542548
runSkipped: null,
@@ -617,6 +623,7 @@ class Configuration {
617623
tags: null,
618624
onPlatform: null,
619625
ignoreTimeouts: null,
626+
suiteLoadTimeout: null,
620627
timeout: null,
621628
verboseTrace: null,
622629
chainStackTraces: null,
@@ -683,6 +690,7 @@ class Configuration {
683690
tags: null,
684691
onPlatform: null,
685692
ignoreTimeouts: null,
693+
suiteLoadTimeout: null,
686694
timeout: null,
687695
verboseTrace: null,
688696
chainStackTraces: null,
@@ -747,6 +755,7 @@ class Configuration {
747755
tags: null,
748756
onPlatform: null,
749757
ignoreTimeouts: null,
758+
suiteLoadTimeout: null,
750759
timeout: null,
751760
verboseTrace: null,
752761
chainStackTraces: null,

pkgs/test_core/lib/src/runner/configuration/args.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ final ArgParser _parser =
141141
help: 'The default test timeout. For example: 15s, 2x, none',
142142
defaultsTo: '30s',
143143
);
144+
parser.addOption(
145+
'suite-load-timeout',
146+
help:
147+
'The timeout for loading a test suite. Loading the test suite '
148+
'includes compiling the test suite. For example: 15s, 2m, none',
149+
defaultsTo: 'none',
150+
);
144151
parser.addFlag(
145152
'ignore-timeouts',
146153
help: 'Ignore all timeouts (useful if debugging)',
@@ -476,6 +483,7 @@ class _Parser {
476483
shardIndex: shardIndex,
477484
totalShards: totalShards,
478485
timeout: _parseOption('timeout', Timeout.parse),
486+
suiteLoadTimeout: _parseOption('suite-load-timeout', Timeout.parse),
479487
globalPatterns: patterns,
480488
compilerSelections: compilerSelections,
481489
runtimes: runtimes,

0 commit comments

Comments
 (0)