Skip to content

Draft: Feature 587 turmoil http.1 client-server test #642

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Babbleshack
Copy link
Contributor

@Babbleshack Babbleshack commented Jul 25, 2025

Adds a simple http.1 client - server test using tokio-turmoil

Addresses #587

Dominic Lindsay added 4 commits July 20, 2025 23:07
- Adds `test-turmoil/test-client-server` package
- Adds simple client server test using tokio-turmoil
@Babbleshack
Copy link
Contributor Author

@GlenDC or @soundofspace I was wondering if I could get some early feedback here.

Am interested to know if this is what you guys had in mind?

What do you think of the package structure?

Any changes you would like to see?

Dominic Lindsay added 2 commits July 25, 2025 19:22
Copy link
Member

@GlenDC GlenDC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. Left some feedback already.
Besides that, two questions:

  1. Why does this need to be a separate package? Can this not be just another main application in /tests?
  2. What is the output when you run this? Is it just binary it works or fails? are there warnings. Asking as I haven't played with turmoil myself yet.

Cargo.toml Outdated
@@ -48,7 +48,7 @@ members = [
"rama-udp",
"rama-unix",
"rama-utils",
"rama-ws",
"rama-ws", "tests-turmoil/test-client-server",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give entries their own line please


[dependencies]
rama = { path = "../..", features = ["full"] }
turmoil = "0.6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add as a workspace dep first and than use { workspace = true }

tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use from rama-core

};
use turmoil::Builder;

const ADDRESS: SocketAddress = SocketAddress::default_ipv4(62004);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you made sure this port is not used by any other test?

HttpServer::http1()
.listen(
address.into(),
(TraceLayer::new_for_http()).into_layer(WebService::default().get("/", "Hello, World")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless round brackets

(TraceLayer::new_for_http()).into_layer(WebService::default().get("/", "Hello, World")),
)
.await
.map_err(|e| e as Box<dyn std::error::Error>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map_err(|e| e as Box<dyn std::error::Error>)
.map_err(Into::into)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wont work, but also here we are trying to coerce the type so that w ecan drop the Send + Sync trait bounds.

@Babbleshack
Copy link
Contributor Author

Looks fine to me. Left some feedback already. Besides that, two questions:

1. Why does this need to be a separate package? Can this not be just another main application in `/tests`?

2. What is the output when you run this? Is it just binary it works or fails? are there warnings. Asking as I haven't played with turmoil myself yet.
  1. I think I mis-interpretted your instructions from the ticket (Add distributed session/application layer tests using turmoil #587).

I would keep these tests separate from other tests and just add them under ./tests-turmoil/, each test its own cargo project there. This way we can add them to the workspace via the pattern ./tests-turmoil/* in our cargo toml of the rama workspace.

Now I have re-read this I think what you actually wanted was integration tests in a /tests/turmoil package. Ill make this change.

2. What is the output when you run this? Is it just binary it works or fails? are there warnings. Asking as I haven't played with turmoil myself yet.

There are no outputs unless logging is enabled.

If the assertion fails, the binary panics as expected.

If a Result::Err is returned from one of the async closure than it is returned similar to JoinHandle behaviour.

For example if we do:

    let mut sim = Builder::new().enable_tokio_io().build();
    sim.host(ADDRESS.ip_addr(), || async {
       Err("error returned from server".into())
    });
    
    sim.client(...);
    
    sim.run().expect("Error during simulation");
    
$ cargo run
...
2025-07-25T19:30:18.246122Z  INFO turmoil: New nodename="0.0.0.0" addr=0.0.0.0
2025-07-25T19:30:18.247514Z  INFO turmoil: New nodename="client" addr=192.168.0.1

thread 'main' panicked at tests-turmoil/test-client-server/src/main.rs:73:23:
Error during simulation: "error returned from server"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@GlenDC
Copy link
Member

GlenDC commented Jul 25, 2025

Is there no bookkeeping that can be checked to see what inputs and parameters it used during the tests? And how to know it ran at all?

@Babbleshack
Copy link
Contributor Author

Babbleshack commented Jul 25, 2025

Is there no bookkeeping that can be checked to see what inputs and parameters it used during the tests? And how to know it ran at all?

There are some functions for inspecting the simulation state:

The simulation (struct Sim) provide some functions for manipulating the environment.

However after some more investigation I dont believe this test is using the turmoil net types.

$ RUST_LOG=INFO,turmoil=TRACE cargo test --test turmoil --features http-full
    Finished `test` profile [optimized] target(s) in 0.30s
     Running tests/turmoil/main.rs (target/debug/deps/turmoil-e998ab69135e2f65)

running 1 test
2025-07-25T21:02:52.748036Z  INFO turmoil: New nodename="0.0.0.0" addr=0.0.0.0
2025-07-25T21:02:52.748150Z  INFO turmoil: New nodename="client" addr=192.168.0.1
2025-07-25T21:02:52.748167Z TRACE turmoil: step 1
2025-07-25T21:02:52.748389Z TRACE turmoil: step 2
2025-07-25T21:02:52.748559Z TRACE turmoil: step 3
2025-07-25T21:02:52.748604Z TRACE turmoil: step 4
test http::http_1_client_server_it ... ok

The output should show network traffice as it sent and delivered.

I think I need to adjust the client and server so that they are using turmoil::net types.

Something more like:

2023-11-29T20:23:43.277039Z TRACE node{name="client"}: turmoil: Delivered src=192.168.0.1:9999 dst=192.168.0.2:49152 protocol=TCP [...]
2023-11-29T20:23:43.277097Z TRACE node{name="client"}: turmoil: Recv src=192.168.0.1:9999 dst=192.168.0.2:49152 protocol=TCP [..]
2023-11-29T20:23:43.277324Z  INFO client: axum_example: Got response: Response { status: 200, version: HTTP/1.1, headers: {"content-type": "text/plain; charset=utf-8", "content-length": "10", "date": "Wed, 29 Nov 2023 20:23:43 GMT"}, body: b"Hello foo!" }
...

We could use something like tracing_test to scrape logs and assert specific network events.

Although its not great. I think a better solution might be to add counters to the turmoil::Sim type

@GlenDC
Copy link
Member

GlenDC commented Jul 26, 2025

Cool I think what you have of tracing and output is probably good enough for now, unless you think differently.

@GlenDC GlenDC force-pushed the main branch 3 times, most recently from 153e3e8 to 049503f Compare July 28, 2025 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants