Skip to content
Merged
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
9 changes: 4 additions & 5 deletions tests/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn handler_receives_message_and_echoes_response() {
let called_clone = called.clone();
let app = WireframeApp::new()
.unwrap()
.frame_processor(LengthPrefixedProcessor)
.frame_processor(LengthPrefixedProcessor::default())
.route(
1,
Box::new(move |_| {
Expand All @@ -49,14 +49,13 @@ async fn handler_receives_message_and_echoes_response() {
};
let env_bytes = BincodeSerializer.serialize(&env).unwrap();
let mut framed = BytesMut::new();
LengthPrefixedProcessor
.encode(&env_bytes, &mut framed)
.unwrap();
let processor = LengthPrefixedProcessor::default();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider reusing the processor instance throughout the test for consistency.

Reusing the same processor instance in all test steps, including .frame_processor, helps ensure consistency and can reveal state-related issues if the processor becomes stateful in the future.

Suggested implementation:

    let processor = LengthPrefixedProcessor::default();
    let app = app
        .frame_processor(processor.clone())
        .route(
            1,
            Box::new(move |_| {
    };
    let env_bytes = BincodeSerializer.serialize(&env).unwrap();
    let mut framed = BytesMut::new();
    processor.encode(&env_bytes, &mut framed).unwrap();

    let out = run_app_with_frame(app, framed.to_vec()).await.unwrap();

    let mut buf = BytesMut::from(&out[..]);
    let frame = processor.decode(&mut buf).unwrap().unwrap();
    let (resp_env, _) = BincodeSerializer
        .deserialize::<TestEnvelope>(&frame)
        .unwrap();
  • Ensure that LengthPrefixedProcessor implements Clone if it does not already, as .frame_processor(processor.clone()) requires it.
  • If the app variable is not defined in this snippet, you may need to adjust the placement of the processor instantiation and the .frame_processor() call to fit the actual test structure.

processor.encode(&env_bytes, &mut framed).unwrap();

let out = run_app_with_frame(app, framed.to_vec()).await.unwrap();

let mut buf = BytesMut::from(&out[..]);
let frame = LengthPrefixedProcessor.decode(&mut buf).unwrap().unwrap();
let frame = processor.decode(&mut buf).unwrap().unwrap();
let (resp_env, _) = BincodeSerializer
.deserialize::<TestEnvelope>(&frame)
.unwrap();
Expand Down
Loading