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

Additional tests for SSE (client side) #4550

Closed
1 of 2 tasks
Tracked by #4567 ...
touilleMan opened this issue May 15, 2023 · 0 comments · Fixed by #6509
Closed
1 of 2 tasks
Tracked by #4567 ...

Additional tests for SSE (client side) #4550

touilleMan opened this issue May 15, 2023 · 0 comments · Fixed by #6509
Assignees
Labels
I-Rust Impact: Rust-related stuff I-Test Test-related issue
Milestone

Comments

@touilleMan
Copy link
Member

touilleMan commented May 15, 2023

Basic tests for SSE already exists:

#[parsec_test(testbed = "coolorg", with_server)]
async fn authenticated_sse(env: &TestbedEnv) {
let alice = env.local_device("alice@dev1".parse().unwrap());
let bob = env.local_device("bob@dev1".parse().unwrap());
let cmds_alice =
AuthenticatedCmds::new(&env.discriminant_dir, alice.clone(), ProxyConfig::default())
.unwrap();
let cmds_bob =
AuthenticatedCmds::new(&env.discriminant_dir, bob.clone(), ProxyConfig::default()).unwrap();
let send_ping = |msg: &str| {
let msg = msg.to_owned();
async {
let rep = cmds_bob
.send(authenticated_cmds::ping::Req { ping: msg })
.await;
assert!(matches!(
rep.unwrap(),
authenticated_cmds::ping::Rep::Ok { .. }
));
}
};
// Request sent before sse started, will be ignored
send_ping("too soon").await;
// Start the sse...
let mut sse = cmds_alice
.start_sse_and_wait_for_connection::<authenticated_cmds::events_listen::Req>()
.await
.unwrap();
// Now event are received !
send_ping("good 1").await;
p_assert_eq!(
sse.next().await.unwrap(),
SSEResponseOrMissedEvents::Response(authenticated_cmds::events_listen::Rep::Ok(
authenticated_cmds::events_listen::APIEvent::Pinged {
ping: "good 1".to_owned()
}
))
);
// Also try to enqueue multiple events
send_ping("good 2").await;
send_ping("good 3").await;
send_ping("good 4").await;
p_assert_eq!(
sse.next().await.unwrap(),
SSEResponseOrMissedEvents::Response(authenticated_cmds::events_listen::Rep::Ok(
authenticated_cmds::events_listen::APIEvent::Pinged {
ping: "good 2".to_owned()
}
))
);
p_assert_eq!(
sse.next().await.unwrap(),
SSEResponseOrMissedEvents::Response(authenticated_cmds::events_listen::Rep::Ok(
authenticated_cmds::events_listen::APIEvent::Pinged {
ping: "good 3".to_owned()
}
))
);
p_assert_eq!(
sse.next().await.unwrap(),
SSEResponseOrMissedEvents::Response(authenticated_cmds::events_listen::Rep::Ok(
authenticated_cmds::events_listen::APIEvent::Pinged {
ping: "good 4".to_owned()
}
))
);
sse.close();
// Bad request: invalid signature
let bad_alice = {
let mut bad_alice = (*alice).clone();
bad_alice.signing_key = SigningKey::generate();
Arc::new(bad_alice)
};
let cmds_bad_alice =
AuthenticatedCmds::new(&env.discriminant_dir, bad_alice, ProxyConfig::default()).unwrap();
let mut sse = cmds_bad_alice.start_sse::<authenticated_cmds::events_listen::Req>();
let rep = sse.next().await;
assert!(
matches!(
rep,
Err(ConnectionError::InvalidResponseStatus(
reqwest::StatusCode::UNAUTHORIZED
))
),
r#"expected `InvalidResponseStatus` with code 401, but got {rep:?}"#
);
}

Additional tests we want:

However those tests are a bit tedious to write:

  • We want to test errors behavior, so the testbed server cannot be used.
  • We want to test the whole SSE machinery, including the 3rd party libs that implement SSE protocol.
    So we cannot use the testbed mock system.

So there is two solutions to implemented those tests:

  1. Modify the testbed server to be able to notify it when it should voluntarily close the client connection to simulate loss of connection.

  2. Start our own dummy HTTP server and serve SSE payloads

    We used to have an implementation of such code,
    but it got replaced by the use of the testbed server. Guess it's time for it to return \o/.

Solution 2 seems the cleaner and less painful way to go (given for testing the last-event-id system, we want).

@touilleMan touilleMan added I-Rust Impact: Rust-related stuff I-Test Test-related issue labels May 15, 2023
@touilleMan touilleMan changed the title [:boxing_glove: :1st_place_medal: Additional tests for SSE (client side) [:boxing_glove: :1st_place_medal: Final oxidation] Additional tests for SSE (client side) May 16, 2023
@FirelightFlagboy FirelightFlagboy changed the title [:boxing_glove: :1st_place_medal: Final oxidation] Additional tests for SSE (client side) [:boxing_glove: :crab: :1st_place_medal: Final oxidation] Additional tests for SSE (client side) May 17, 2023
@FirelightFlagboy FirelightFlagboy self-assigned this Nov 20, 2023
@touilleMan touilleMan changed the title [:boxing_glove: :crab: :1st_place_medal: Final oxidation] Additional tests for SSE (client side) Additional tests for SSE (client side) Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-Rust Impact: Rust-related stuff I-Test Test-related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants