Skip to content

Commit 35efa0e

Browse files
committed
test(proto): Test closing while the client migrates
Adds a test that check if we close correctly during a connection migration. Test adapted from #390, but as a more constructive test than a regression test. (Hot take: regression tests are technical debt in less than 3 refactors)
1 parent a75c541 commit 35efa0e

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

noq-proto/src/tests/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,40 @@ fn connection_close_sends_acks() {
13321332
);
13331333
}
13341334

1335+
/// Client closes the connection at the same time it experience a passive migration.
1336+
#[test]
1337+
fn close_from_migrated_address() {
1338+
let _guard = subscribe();
1339+
let mut pair = ConnPair::default();
1340+
pair.drive();
1341+
1342+
// Change client address - server will see this as migration
1343+
pair.client.addr = SocketAddr::new(
1344+
Ipv4Addr::new(127, 0, 0, 1).into(),
1345+
CLIENT_PORTS.lock().unwrap().next().unwrap(),
1346+
);
1347+
1348+
// Client closes connection from the NEW address. The server will see the migration and
1349+
// close the connection on the new address.
1350+
// TOD(flub): Potentially the server should also send the CONNECTION_CLOSE to the old
1351+
// address. Because the new one has not yet been validated.
1352+
pair.close(Client, 0, b"bye");
1353+
pair.drive();
1354+
1355+
let server_stats = pair.stats(Server);
1356+
assert_eq!(server_stats.frame_tx.connection_close, 1);
1357+
1358+
assert_matches!(
1359+
pair.poll(Server),
1360+
Some(Event::ConnectionLost {
1361+
reason: ConnectionError::ApplicationClosed(_)
1362+
})
1363+
);
1364+
1365+
let path = pair.conn(Server).network_path(PathId::ZERO).unwrap();
1366+
assert_eq!(path.remote(), pair.client.addr);
1367+
}
1368+
13351369
#[test]
13361370
fn server_hs_retransmit() {
13371371
let _guard = subscribe();

noq-proto/src/tests/util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,10 @@ impl ConnPair {
597597
self.conn_mut(side).handle_timeout(now)
598598
}
599599

600-
pub(super) fn close(&mut self, side: Side, now: Instant, error_code: VarInt, reason: Bytes) {
601-
self.conn_mut(side).close(now, error_code, reason)
600+
pub(super) fn close(&mut self, side: Side, error_code: u32, reason: &[u8]) {
601+
let now = self.pair.time;
602+
self.conn_mut(side)
603+
.close(now, error_code.into(), Bytes::copy_from_slice(reason))
602604
}
603605

604606
pub(super) fn datagrams(&mut self, side: Side) -> Datagrams<'_> {

0 commit comments

Comments
 (0)