Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass correct log-source for stderr wait strategy #692

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testcontainers/src/core/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

let mut find_iter = msg_finder.find_iter(message.as_ref());
while let Some(_) = find_iter.next() {

Check warning on line 96 in testcontainers/src/core/logs.rs

View workflow job for this annotation

GitHub Actions / clippy

this loop could be written as a `for` loop

warning: this loop could be written as a `for` loop --> testcontainers/src/core/logs.rs:96:13 | 96 | while let Some(_) = find_iter.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in find_iter` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator = note: `#[warn(clippy::while_let_on_iterator)]` on by default
found_times += 1; // can't overflow, because of check below
if found_times == times {
log::debug!(
Expand Down Expand Up @@ -135,7 +135,7 @@
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
Loading