Skip to content

Commit

Permalink
Give an error message when the wasm test fails (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
quodlibetor authored Sep 26, 2020
1 parent 1b895b4 commit cf771cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 8 additions & 3 deletions ci/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ test_wasm() {
}

test_wasm_simple() {
now=$(date +%s)
tz=$(date +%z)
runt env TZ="$tz" NOW="$now" wasm-pack test --node -- --features wasmbind
if ! runt env TZ="$(date +%z)" NOW="$(date +%s)" wasm-pack test --node -- --features wasmbind ; then
# sometimes on github the initial build takes 8-10 minutes, and we
# check that the time makes sense inside the test by approximately
# comparing it to the env var,
#
# so re-run the test in case it took too long
runt env TZ="$(date +%z)" NOW="$(date +%s)" wasm-pack test --node -- --features wasmbind
fi
}

main "$@"
15 changes: 12 additions & 3 deletions tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ mod test {
let utc: DateTime<Utc> = Utc::now();
let local: DateTime<Local> = Local::now();

// Ensure time fetched is correct
let actual = Utc.datetime_from_str(&env!("NOW"), "%s").unwrap();
assert!(utc - actual < chrono::Duration::minutes(5));
// Ensure time set by the test script is correct
let now = env!("NOW");
let actual = Utc.datetime_from_str(&now, "%s").unwrap();
let diff = utc - actual;
assert!(
diff < chrono::Duration::minutes(5),
"expected {} - {} == {} < 5m (env var: {})",
utc,
actual,
diff,
now,
);

let tz = env!("TZ");
eprintln!("testing with tz={}", tz);
Expand Down

0 comments on commit cf771cb

Please sign in to comment.