Skip to content

Commit

Permalink
fix: remove gitea container at end of tests
Browse files Browse the repository at this point in the history
Context:
* after running cargo test, gitea container is still started

Problem:
* we want container to be destroyed at end of tests
* `cargo test` command doesn't cleanup static variables

Solution:
* use ctor crate as workaround to drop gitea container
  • Loading branch information
jagu-sayan committed Jan 23, 2025
1 parent b3daf47 commit 551f912
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ reqwest = { version = "0.12.12", features = ["blocking", "brotli", "json"] }
ssh-key = { version = "0.6.7", features = ["ed25519"] }
rand = "0.8.5"
base64 = "0.22.1"
ctor = "0.2.9"

[target."cfg(unix)".dependencies]
expanduser = "1.2.2"
Expand Down
1 change: 0 additions & 1 deletion tests/container/gitea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct GiteaContainer {
pub private_key: String,
token: String,
tls_cert: String,
// tmp_dir: TempDir,
http_client: Client,
}

Expand Down
12 changes: 12 additions & 0 deletions tests/gitea_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ pub fn gitea_container() -> &'static GiteaContainer {
GITEA_CONTAINER.get_or_init(GiteaContainer::start)
}

// Remove gitea container at end of tests
// Comment out this function for debugging to keep container running after tests
#[ctor::dtor]
fn cleanup() {
let container = &GITEA_CONTAINER as *const _ as *mut OnceLock<GiteaContainer>;
// Safety: We have exclusive access to GITEA_CONTAINER during cleanup/destruction
if let Some(container) = unsafe { (*container).take() } {
println!("Remove Gitea container...\n");
drop(container);
}
}

fn update_command(workspace_path: &Path) {
lock(workspace_path).unwrap();
update(workspace_path, 8).unwrap();
Expand Down

0 comments on commit 551f912

Please sign in to comment.