Add a generic Ack message, use it instead of Pong

Remove the `id` field from `Ping`, because it isn't used.
There is already an id on the message envelope.
This commit is contained in:
Max Brunsfeld
2021-09-09 11:24:16 -07:00
parent 000305472a
commit 38bfaba135
5 changed files with 17 additions and 40 deletions
+3 -9
View File
@@ -139,13 +139,9 @@ impl Client {
let this = self.clone();
let foreground = cx.foreground();
state._maintain_connection = Some(cx.foreground().spawn(async move {
let mut next_ping_id = 0;
loop {
foreground.timer(heartbeat_interval).await;
this.request(proto::Ping { id: next_ping_id })
.await
.unwrap();
next_ping_id += 1;
this.request(proto::Ping {}).await.unwrap();
}
}));
}
@@ -543,13 +539,11 @@ mod tests {
cx.foreground().advance_clock(Duration::from_secs(10));
let ping = server.receive::<proto::Ping>().await.unwrap();
assert_eq!(ping.payload.id, 0);
server.respond(ping.receipt(), proto::Pong { id: 0 }).await;
server.respond(ping.receipt(), proto::Ack {}).await;
cx.foreground().advance_clock(Duration::from_secs(10));
let ping = server.receive::<proto::Ping>().await.unwrap();
assert_eq!(ping.payload.id, 1);
server.respond(ping.receipt(), proto::Pong { id: 1 }).await;
server.respond(ping.receipt(), proto::Ack {}).await;
client.disconnect(&cx.to_async()).await.unwrap();
assert!(server.receive::<proto::Ping>().await.is_err());