Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 1ccfaa7

Browse files
committed
Limit test execution time not to hog CI's computational resources
For `libtest` tests, this utilizes the unstable rustc feature added by rust-lang/rust#64873 to meter the execution time.
1 parent 7f233fd commit 1ccfaa7

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

ci/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
variables:
2-
rustVersion: nightly-2019-10-13
2+
rustVersion: nightly-2019-11-11
33
linuxPrestep: |
44
sudo apt-get update &&
55
sudo apt-get install -y \

ci/jobs/cargo-test.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ parameters:
2525
no-default-features: false # Do not activate the `default` feature
2626

2727
# parameters from libtest `cargo test -- --help`
28+
# TODO: specifying a portion of these does not work
2829
test_flags:
2930
include-ignored: false # Run ignored and not ignored tests
3031
ignored: false # Run only ignored tests
@@ -41,6 +42,7 @@ parameters:
4142
quite: false # Display one character per test instead of one line.
4243
# Alias to --format=terse
4344
exact: false # Exactly match filters rather than by substring
45+
ensure-time: true # Treat excess of the test execution time limit as error. (unstable)
4446
color: '' # auto|always|never
4547
# Configure coloring of output: auto = colorize if
4648
# stdout is a tty and tests are run on serially
@@ -50,7 +52,7 @@ parameters:
5052
# Configure formatting of output: pretty = Print verbose
5153
# output; terse = Display one character per test; json =
5254
# Output a json document
53-
Z: [] # unstable-options Enable nightly-only flags: unstable-options = Allow
55+
Z: ['unstable-options'] # unstable-options Enable nightly-only flags: unstable-options = Allow
5456
# use of experimental features
5557

5658

@@ -66,6 +68,11 @@ jobs:
6668
variables:
6769
check_flags: ''
6870
test_build_flags: ''
71+
72+
# Time limits for `--ensure-time`
73+
RUST_TEST_TIME_UNIT: '2,10'
74+
RUST_TEST_TIME_INTEGRATION: '4,30'
75+
RUST_TEST_TIME_DOCTEST: '8,40'
6976
steps:
7077
# Custom pre steps:
7178
- script: $(prepareScript)
@@ -141,6 +148,10 @@ jobs:
141148
enabled: ${{ parameters.test_flags['exact'] }}
142149
displayName: "[cli flag modify]Exactly match filters rather than by substring"
143150

151+
- script: echo '##vso[task.setvariable variable=check_flags]$(check_flags) --ensure-time'
152+
enabled: ${{ parameters.test_flags['ensure-time'] }}
153+
displayName: "[cli flag modify]Treat excess of the test execution time limit as error"
154+
144155
- script: echo "##vso[task.setvariable variable=check_flags]$(check_flags) --color ${{ parameters.test_flags['color'] }}"
145156
enabled: ${{ ne(parameters.test_flags['color'], '') }}
146157
displayName: "[cli flag modify] Configure coloring of output: ${{ parameters.test_flags['color'] }}"
@@ -150,7 +161,7 @@ jobs:
150161
displayName: "[cli flag modify] Configure formatting of output: ${{ parameters.test_flags['format'] }}"
151162

152163
- ${{ each z in parameters.test_flags['Z'] }}:
153-
- script: echo '##vso[task.setvariableV variable=check_flags]$(check_flags) --Z ${{ z }}'
164+
- script: echo '##vso[task.setvariable variable=check_flags]$(check_flags) -Z ${{ z }}'
154165
displayName: "[cli flag modify] unstable-option: ${{ z }}"
155166

156167
# *********************************************************************************************

tcw3/pal/tests/common/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::time::Duration;
2+
3+
pub fn set_timelimit_default() {
4+
std::thread::spawn(|| {
5+
std::thread::sleep(Duration::from_secs(30));
6+
eprintln!("!!! Time limit exceeed.");
7+
std::process::abort();
8+
});
9+
}

tcw3/pal/tests/futures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use futures::{channel::oneshot::channel, task::LocalSpawnExt};
22
use std::{env::var_os, time::Duration};
33
use tcw3_pal::{prelude::Wm as _, prelude::*, Wm};
44

5+
mod common;
6+
57
fn main() {
68
env_logger::init();
9+
common::set_timelimit_default();
710

811
if let Some(value) = var_os("ST_SKIP_NATIVE_BACKEND_TESTS") {
912
if !value.is_empty() && value != "0" {

tcw3/pal/tests/timer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ use std::{
66
};
77
use tcw3_pal::{prelude::Wm as _, prelude::*, Wm};
88

9+
mod common;
10+
911
fn main() {
1012
env_logger::init();
13+
common::set_timelimit_default();
1114

1215
if let Some(value) = var_os("ST_SKIP_NATIVE_BACKEND_TESTS") {
1316
if !value.is_empty() && value != "0" {

0 commit comments

Comments
 (0)