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

Commit

Permalink
Limit test execution time not to hog CI's computational resources
Browse files Browse the repository at this point in the history
For `libtest` tests, this utilizes the unstable rustc feature added by
rust-lang/rust#64873 to meter the execution time.
  • Loading branch information
yvt committed Nov 12, 2019
1 parent 7f233fd commit 1ccfaa7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ci/common.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
rustVersion: nightly-2019-10-13
rustVersion: nightly-2019-11-11
linuxPrestep: |
sudo apt-get update &&
sudo apt-get install -y \
Expand Down
15 changes: 13 additions & 2 deletions ci/jobs/cargo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ parameters:
no-default-features: false # Do not activate the `default` feature

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


Expand All @@ -66,6 +68,11 @@ jobs:
variables:
check_flags: ''
test_build_flags: ''

# Time limits for `--ensure-time`
RUST_TEST_TIME_UNIT: '2,10'
RUST_TEST_TIME_INTEGRATION: '4,30'
RUST_TEST_TIME_DOCTEST: '8,40'
steps:
# Custom pre steps:
- script: $(prepareScript)
Expand Down Expand Up @@ -141,6 +148,10 @@ jobs:
enabled: ${{ parameters.test_flags['exact'] }}
displayName: "[cli flag modify]Exactly match filters rather than by substring"

- script: echo '##vso[task.setvariable variable=check_flags]$(check_flags) --ensure-time'
enabled: ${{ parameters.test_flags['ensure-time'] }}
displayName: "[cli flag modify]Treat excess of the test execution time limit as error"

- script: echo "##vso[task.setvariable variable=check_flags]$(check_flags) --color ${{ parameters.test_flags['color'] }}"
enabled: ${{ ne(parameters.test_flags['color'], '') }}
displayName: "[cli flag modify] Configure coloring of output: ${{ parameters.test_flags['color'] }}"
Expand All @@ -150,7 +161,7 @@ jobs:
displayName: "[cli flag modify] Configure formatting of output: ${{ parameters.test_flags['format'] }}"

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

# *********************************************************************************************
Expand Down
9 changes: 9 additions & 0 deletions tcw3/pal/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::time::Duration;

pub fn set_timelimit_default() {
std::thread::spawn(|| {
std::thread::sleep(Duration::from_secs(30));
eprintln!("!!! Time limit exceeed.");
std::process::abort();
});
}
3 changes: 3 additions & 0 deletions tcw3/pal/tests/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use futures::{channel::oneshot::channel, task::LocalSpawnExt};
use std::{env::var_os, time::Duration};
use tcw3_pal::{prelude::Wm as _, prelude::*, Wm};

mod common;

fn main() {
env_logger::init();
common::set_timelimit_default();

if let Some(value) = var_os("ST_SKIP_NATIVE_BACKEND_TESTS") {
if !value.is_empty() && value != "0" {
Expand Down
3 changes: 3 additions & 0 deletions tcw3/pal/tests/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use std::{
};
use tcw3_pal::{prelude::Wm as _, prelude::*, Wm};

mod common;

fn main() {
env_logger::init();
common::set_timelimit_default();

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

0 comments on commit 1ccfaa7

Please sign in to comment.