From e23e6d20a4d138b3d597ec33a18d9b8e739979be Mon Sep 17 00:00:00 2001 From: Francesco_Cina Date: Wed, 6 Jul 2022 12:27:32 +0200 Subject: [PATCH 1/3] Make Docker Send and Sync --- testcontainers/src/core/container.rs | 2 +- testcontainers/tests/container.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 testcontainers/tests/container.rs diff --git a/testcontainers/src/core/container.rs b/testcontainers/src/core/container.rs index 6e0613a5..9db7b205 100644 --- a/testcontainers/src/core/container.rs +++ b/testcontainers/src/core/container.rs @@ -237,7 +237,7 @@ where /// /// This trait is pub(crate) because it should not be used directly by users but only represents an internal abstraction that allows containers to be generic over the client they have been started with. /// All functionality of this trait is available on [`Container`]s directly. -pub(crate) trait Docker { +pub(crate) trait Docker: Sync + Send { fn stdout_logs(&self, id: &str) -> LogStream; fn stderr_logs(&self, id: &str) -> LogStream; fn ports(&self, id: &str) -> Ports; diff --git a/testcontainers/tests/container.rs b/testcontainers/tests/container.rs new file mode 100644 index 00000000..5e69e639 --- /dev/null +++ b/testcontainers/tests/container.rs @@ -0,0 +1,19 @@ +use testcontainers::clients::Cli; +use testcontainers::images::hello_world::HelloWorld; + +#[test] +fn container_should_be_send() { + let docker = Cli::default(); + let node = docker.run(HelloWorld{}); + need_send(node); +} + +#[test] +fn container_should_be_sync() { + let docker = Cli::default(); + let node = docker.run(HelloWorld{}); + need_sync(node); +} + +fn need_send(_t: T) {} +fn need_sync(_t: T) {} \ No newline at end of file From 0c870d00f5604c71224bb265d82de1d8560bf57e Mon Sep 17 00:00:00 2001 From: Francesco_Cina Date: Wed, 6 Jul 2022 12:37:50 +0200 Subject: [PATCH 2/3] Fix formatting --- testcontainers/tests/container.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/testcontainers/tests/container.rs b/testcontainers/tests/container.rs index 5e69e639..bf1563ff 100644 --- a/testcontainers/tests/container.rs +++ b/testcontainers/tests/container.rs @@ -1,19 +1,18 @@ -use testcontainers::clients::Cli; -use testcontainers::images::hello_world::HelloWorld; +use testcontainers::{clients::Cli, images::hello_world::HelloWorld}; #[test] fn container_should_be_send() { let docker = Cli::default(); - let node = docker.run(HelloWorld{}); + let node = docker.run(HelloWorld {}); need_send(node); } #[test] fn container_should_be_sync() { let docker = Cli::default(); - let node = docker.run(HelloWorld{}); + let node = docker.run(HelloWorld {}); need_sync(node); } fn need_send(_t: T) {} -fn need_sync(_t: T) {} \ No newline at end of file +fn need_sync(_t: T) {} From 6b570fc34c72b6082d8475e18d7b4bcd5a5668ae Mon Sep 17 00:00:00 2001 From: Francesco_Cina Date: Thu, 7 Jul 2022 10:09:26 +0200 Subject: [PATCH 3/3] Implement review comments --- testcontainers/src/core/container.rs | 14 ++++++++++++++ testcontainers/tests/container.rs | 18 ------------------ 2 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 testcontainers/tests/container.rs diff --git a/testcontainers/src/core/container.rs b/testcontainers/src/core/container.rs index 9db7b205..a9721277 100644 --- a/testcontainers/src/core/container.rs +++ b/testcontainers/src/core/container.rs @@ -248,3 +248,17 @@ pub(crate) trait Docker: Sync + Send { fn exec(&self, id: &str, cmd: String); fn block_until_ready(&self, id: &str, ready_conditions: Vec); } + +#[cfg(test)] +mod test { + + use super::Container; + use crate::images::hello_world::HelloWorld; + + #[test] + fn container_should_be_send_and_sync() { + assert_send_and_sync::>(); + } + + fn assert_send_and_sync() {} +} diff --git a/testcontainers/tests/container.rs b/testcontainers/tests/container.rs deleted file mode 100644 index bf1563ff..00000000 --- a/testcontainers/tests/container.rs +++ /dev/null @@ -1,18 +0,0 @@ -use testcontainers::{clients::Cli, images::hello_world::HelloWorld}; - -#[test] -fn container_should_be_send() { - let docker = Cli::default(); - let node = docker.run(HelloWorld {}); - need_send(node); -} - -#[test] -fn container_should_be_sync() { - let docker = Cli::default(); - let node = docker.run(HelloWorld {}); - need_sync(node); -} - -fn need_send(_t: T) {} -fn need_sync(_t: T) {}