Example of testcontainers with a single Docker container created for all test functions.
The idea was taken from Reddit thread, authors: u/rtimush and u/tbss123456.
Rust compiler won't allow to store a reference to Container<'_, T>
in a static variable,
because it doesn't implement Sync
. The exact error in rustc 1.70.0 is:
`(dyn testcontainers::core::container::Docker + 'static)` cannot be shared between threads safely
the trait `std::marker::Sync` is not implemented for `(dyn testcontainers::core::container::Docker + 'static)`
required for `std::ptr::Unique<(dyn testcontainers::core::container::Docker + 'static)>` to implement `std::marker::Sync`
- Spawn container in a separate thread.
- Reference container only from it.
- Use message passing to send commands to container and retreive data from it.
These are specifics of this Gist.
-
MinIO
container because for my project I needed to test integration with it. Hovewer, this approach could be reused for any Docker container. -
Single channel for all container commands and separate channels for each output message.
-
ctor crate to run start up and shut down code.