Skip to content

Commit

Permalink
fix: pass correct log-source for stderr
Browse files Browse the repository at this point in the history
There was a mistake in `WaitFor::message_on_stderr`. Covered with simple test now.
  • Loading branch information
DDtKey committed Jul 7, 2024
1 parent 41f2f06 commit 0ed8134
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion testcontainers/src/core/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl fmt::Debug for WaitingStreamWrapper {
mod tests {
use super::*;

#[tokio::test(flavor = "multi_thread")]
#[tokio::test]
async fn given_logs_when_line_contains_message_should_find_it() {
let _ = pretty_env_logger::try_init();
let log_stream = || {
Expand Down
2 changes: 1 addition & 1 deletion testcontainers/src/core/wait/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl WaitFor {

/// Wait for the message to appear on the container's stderr.
pub fn message_on_stderr(message: impl AsRef<[u8]>) -> WaitFor {
Self::log(LogWaitStrategy::new(LogSource::StdOut, message))
Self::log(LogWaitStrategy::new(LogSource::StdErr, message))
}

/// Wait for the message to appear on the container's stdout.
Expand Down
1 change: 1 addition & 0 deletions testcontainers/tests/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async fn async_run_exec() -> anyhow::Result<()> {
let _ = pretty_env_logger::try_init();

let image = GenericImage::new("simple_web_server", "latest")
.with_wait_for(WaitFor::message_on_stderr("server will be listening to"))
.with_wait_for(WaitFor::log(
LogWaitStrategy::stdout("server is ready").with_times(2),
))
Expand Down
1 change: 1 addition & 0 deletions testimages/src/bin/simple_web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async fn main() {
// run it
let addr = SocketAddr::from(([0, 0, 0, 0], 80));
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
eprintln!("server will be listening to the port 80");
println!("server is ready");
println!("server is ready"); // duplicate line to test `times` parameter of `WaitFor::Log`
axum::serve(listener, app.into_make_service())
Expand Down

0 comments on commit 0ed8134

Please sign in to comment.