Repository: influxdata/influxdb
File: influxdb3/tests/server/cli.rs (Rust)

Code before:
fn create_plugin_file(code: &str) -> NamedTempFile {
    let mut file = NamedTempFile::new().unwrap();
    writeln!(file, "{}", code).unwrap();
    file
}

#[test_log::test(tokio::test)]
async fn test_telemetry_disabled_with_debug_msg() {
    let serve_args = &[
        "serve",
        "--writer-id",
        "the-best-writer",
        "--object-store",
        "memory",
    ];

    let expected_disabled: &str = "Initializing TelemetryStore with upload disabled.";

    // validate we get a debug message indicating upload disabled
    AssertCmd::cargo_bin("influxdb3")
        .unwrap()
        .args(serve_args)
        .arg("-vv")
        .arg("--disable-telemetry-upload")
        .timeout(std::time::Duration::from_millis(500))
        .assert()
        .failure()
        .stdout(predicates::str::contains(expected_disabled));
}

#[test_log::test(tokio::test)]
async fn test_telemetry_disabled() {
    let serve_args = &[
        "serve",
        "--writer-id",
        "the-best-writer",
        "--object-store",
        "memory",
    ];

    let expected_disabled: &str = "Initializing TelemetryStore with upload disabled.";
    // validate no message when debug output disabled
    AssertCmd::cargo_bin("influxdb3")
        .unwrap()
        .args(serve_args)
        .arg("-v")
        .arg("--disable-telemetry-upload")
        .timeout(std::time::Duration::from_millis(500))
        .assert()
        .failure()
        .stdout(predicates::str::contains(expected_disabled).not());

Review comment (bug):
Is it `failure()` because process starts and hangs around till 500 millis and then shuts down? Just wondered if it could've used the `TestServer` to spin up the server and got hold of the stdout for your assertions. If you'd already looked into it and it didn't work for you that's fine, but it has the mechanism built in to kill the process after the test without `timeout`.

Code after:
    let mut file = NamedTempFile::new().unwrap();
    writeln!(file, "{}", code).unwrap();
    file
}

#[test_log::test(tokio::test)]
async fn test_telemetry_disabled_with_debug_msg() {
    let serve_args = &[
        "serve",
        "--writer-id",
        "the-best-writer",
        "--object-store",
        "memory",
    ];

    let expected_disabled: &str = "Initializing TelemetryStore with upload disabled.";

    // validate we get a debug message indicating upload disabled
    let output = AssertCmd::cargo_bin("influxdb3")
        .unwrap()
        .args(serve_args)
        .arg("-vv")
        .arg("--disable-telemetry-upload")
        .timeout(std::time::Duration::from_millis(500))
        .assert()
        .failure()
        .get_output()
        .stdout
        .clone();
    let output = String::from_utf8(output).expect("must be able to convert output to String");
    assert_contains!(output, expected_disabled);
}

#[test_log::test(tokio::test)]
async fn test_telemetry_disabled() {
    let serve_args = &[
        "serve",
        "--writer-id",
        "the-best-writer",
        "--object-store",
        "memory",
    ];

    let expected_disabled: &str = "Initializing TelemetryStore with upload disabled.";
    // validate no message when debug output disabled
    let output = AssertCmd::cargo_bin("influxdb3")
        .unwrap()
        .args(serve_args)
        .arg("-v")
        .arg("--disable-telemetry-upload")
        .timeout(std::time::Duration::from_millis(500))