diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 148cf9391bf..e588a9d279d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -82,6 +82,8 @@ jobs: run: cargo doc build-and-test: + env: + OMICRON_TMP: /tmp/omicron_tmp needs: skip_duplicate_jobs if: ${{ needs.skip_duplicate_jobs.outputs.should_skip != 'true' }} runs-on: ${{ matrix.os }} @@ -114,6 +116,8 @@ jobs: - name: Download CockroachDB binary if: steps.cache-cockroachdb.outputs.cache-hit != 'true' run: bash ./tools/ci_download_cockroachdb + - name: Create temporary directory for test outputs + run: mkdir -p $OMICRON_TMP - name: Build # We build with: # - RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings": disallow warnings @@ -125,10 +129,24 @@ jobs: # also gives us a record of which dependencies were used for each CI # run. Building with `--locked` ensures that the checked-in Cargo.lock # is up to date. - run: PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse" RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo build --locked --all-targets --verbose + # - TMPDIR=$OMICRON_TMP: we specify a specific temporary directory so that + # failed test outputs will be in a known place that we can grab at the + # end without also grabbing random other temporary files. + run: TMPDIR=$OMICRON_TMP PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse" RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo build --locked --all-targets --verbose - name: Run tests # Use the same RUSTFLAGS and RUSTDOCFLAGS as above to avoid having to # rebuild here. # Put "./cockroachdb/bin" and "./clickhouse" on the PATH for the test # suite. - run: PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse" RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo test --workspace --locked --verbose + run: TMPDIR=$OMICRON_TMP PATH="$PATH:$PWD/cockroachdb/bin:$PWD/clickhouse" RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo test --workspace --locked --verbose + - name: Archive any failed test results + if: ${{ failure() }} + # actions/upload-artifact@v2.3.1 + uses: actions/upload-artifact@82c141cc518b40d92cc801eee768e7aafc9c2fa2 + with: + name: failed_test_outputs_${{ runner.os }} + retention-days: 7 + path: | + ${{ env.OMICRON_TMP }} + !${{ env.OMICRON_TMP }}/crdb-base + !${{ env.OMICRON_TMP }}/rustc* diff --git a/nexus/src/authz/context.rs b/nexus/src/authz/context.rs index cfd0fd45740..8d5db942df6 100644 --- a/nexus/src/authz/context.rs +++ b/nexus/src/authz/context.rs @@ -189,7 +189,7 @@ mod test { #[tokio::test] async fn test_organization() { - let logctx = dev::test_setup_log("test_database"); + let logctx = dev::test_setup_log("test_organization"); let mut db = dev::test_setup_database(&logctx.log).await; let (opctx, datastore) = crate::db::datastore::datastore_test(&logctx, &db).await; diff --git a/test-utils/src/dev/db.rs b/test-utils/src/dev/db.rs index 88361210bfa..4268d3e22da 100644 --- a/test-utils/src/dev/db.rs +++ b/test-utils/src/dev/db.rs @@ -572,7 +572,14 @@ impl Drop for CockroachInstance { } #[allow(unused_must_use)] if let Some(temp_dir) = self.temp_dir.take() { - temp_dir.close(); + /* + * Do NOT clean up the temporary directory in this case. + */ + let path = temp_dir.into_path(); + eprintln!( + "WARN: temporary directory leaked: {}", + path.display() + ); } } } @@ -1239,13 +1246,13 @@ mod test { */ #[tokio::test] async fn test_database_concurrent() { - let db1 = new_builder() + let mut db1 = new_builder() .build() .expect("failed to create starter for the first database") .start() .await .expect("failed to start first database"); - let db2 = new_builder() + let mut db2 = new_builder() .build() .expect("failed to create starter for the second database") .start() @@ -1274,6 +1281,9 @@ mod test { client2.query("SELECT v FROM foo", &[]).await.expect("list rows"); assert_eq!(rows.len(), 0); client2.cleanup().await.expect("second connection closed ungracefully"); + + db1.cleanup().await.expect("failed to clean up first database"); + db2.cleanup().await.expect("failed to clean up second database"); } /* Success case for make_pg_config() */