Skip to content

fail CI when successful tests leave stuff in TMPDIR #992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/buildomat/jobs/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ ptime -m ./tools/ci_download_clickhouse
banner cockroach
ptime -m bash ./tools/ci_download_cockroachdb

#
# Set up a custom temporary directory within whatever one we were given so that
# we can check later whether we left detritus around.
#
TEST_TMPDIR="${TMPDIR:-/var/tmp}/omicron_tmp"
echo "tests will store output in $TEST_TMPDIR"
mkdir $TEST_TMPDIR

#
# Put "./cockroachdb/bin" and "./clickhouse" on the PATH for the test
# suite.
Expand All @@ -43,6 +51,7 @@ export PATH="$PATH:$PWD/out/cockroachdb/bin:$PWD/out/clickhouse"
banner build
export RUSTFLAGS="-D warnings"
export RUSTDOCFLAGS="-D warnings"
export TMPDIR=$TEST_TMPDIR
ptime -m cargo +'nightly-2022-04-27' build --locked --all-targets --verbose

#
Expand All @@ -57,3 +66,12 @@ ptime -m cargo run --bin omicron-package -- check
#
banner test
ptime -m cargo +'nightly-2022-04-27' test --workspace --locked --verbose

#
# Make sure that we have left nothing around in $TEST_TMPDIR. The easiest way
# to check is to try to remove it with `rmdir`.
#
unset TMPDIR
echo "files in $TEST_TMPDIR (none expected on success):"
find $TEST_TMPDIR -ls
rmdir $TEST_TMPDIR
9 changes: 7 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ jobs:
# Put "./cockroachdb/bin" and "./clickhouse" on the PATH for the test
# suite.
run: TMPDIR=$OMICRON_TMP PATH="$PATH:$PWD/out/cockroachdb/bin:$PWD/out/clickhouse" RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo test --no-fail-fast --workspace --locked --verbose
- name: Archive any failed test results
if: ${{ failure() }}
- name: Archive results left by tests
# actions/upload-artifact@v2.3.1
uses: actions/upload-artifact@82c141cc518b40d92cc801eee768e7aafc9c2fa2
with:
Expand All @@ -156,3 +155,9 @@ jobs:
${{ env.OMICRON_TMP }}
!${{ env.OMICRON_TMP }}/crdb-base
!${{ env.OMICRON_TMP }}/rustc*
# Fail the build if successful tests leave detritus in $TMPDIR. The easiest
# way to check if the directory is empty is to try to remove it with
# `rmdir`.
- name: Remove temporary directory on success (if this fails, tests leaked files in TMPDIR)
if: ${{ success() }}
run: rmdir $OMICRON_TMP
9 changes: 6 additions & 3 deletions nexus/src/db/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mod test {
#[tokio::test]
async fn test_explain() {
let logctx = dev::test_setup_log("test_explain");
let db = test_setup_database(&logctx.log).await;
let mut db = test_setup_database(&logctx.log).await;
let cfg = db::Config { url: db.pg_config().clone() };
let pool = db::Pool::new(&cfg);

Expand All @@ -190,14 +190,15 @@ mod test {
)
.await
.unwrap();
db.cleanup().await.unwrap();
logctx.cleanup_successful();
}

// Tests the ".explain_async()" method in an asynchronous context.
#[tokio::test]
async fn test_explain_async() {
let logctx = dev::test_setup_log("test_explain_async");
let db = test_setup_database(&logctx.log).await;
let mut db = test_setup_database(&logctx.log).await;
let cfg = db::Config { url: db.pg_config().clone() };
let pool = db::Pool::new(&cfg);

Expand All @@ -212,14 +213,15 @@ mod test {
.unwrap();

assert_contents("tests/output/test-explain-output", &explanation);
db.cleanup().await.unwrap();
logctx.cleanup_successful();
}

// Tests that ".explain()" can tell us when we're doing full table scans.
#[tokio::test]
async fn test_explain_full_table_scan() {
let logctx = dev::test_setup_log("test_explain_full_table_scan");
let db = test_setup_database(&logctx.log).await;
let mut db = test_setup_database(&logctx.log).await;
let cfg = db::Config { url: db.pg_config().clone() };
let pool = db::Pool::new(&cfg);

Expand All @@ -238,6 +240,7 @@ mod test {
"Expected [{}] to contain 'FULL SCAN'",
explanation
);
db.cleanup().await.unwrap();
logctx.cleanup_successful();
}
}