Skip to content

Commit

Permalink
Add tests for on_reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
rageshkrishna committed Mar 26, 2024
1 parent 240f196 commit 2f05dea
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion socketio/src/asynchronous/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,10 @@ mod test {
};

use crate::{
asynchronous::client::{builder::ClientBuilder, client::Client},
asynchronous::{
client::{builder::ClientBuilder, client::Client},
ReconnectSettings,
},
error::Result,
packet::{Packet, PacketId},
Payload, TransportType,
Expand Down Expand Up @@ -739,13 +742,23 @@ mod test {
async fn socket_io_reconnect_integration() -> Result<()> {
static CONNECT_NUM: AtomicUsize = AtomicUsize::new(0);
static MESSAGE_NUM: AtomicUsize = AtomicUsize::new(0);
static ON_RECONNECT_CALLED: AtomicUsize = AtomicUsize::new(0);

let url = crate::test::socket_io_restart_server();

let socket = ClientBuilder::new(url)
.reconnect(true)
.max_reconnect_attempts(100)
.reconnect_delay(100, 100)
.on_reconnect(|| {
async move {
ON_RECONNECT_CALLED.fetch_add(1, Ordering::Release);

// This returns a default object that changes nothing
ReconnectSettings::new()
}
.boxed()
})
.on("open", |_, socket| {
async move {
CONNECT_NUM.fetch_add(1, Ordering::Release);
Expand Down Expand Up @@ -792,6 +805,11 @@ mod test {

assert_eq!(load(&CONNECT_NUM), 2, "should connect twice");
assert_eq!(load(&MESSAGE_NUM), 2, "should receive two messages");
assert_eq!(
load(&ON_RECONNECT_CALLED),
1,
"should call on_reconnect once"
);

socket.disconnect().await?;
Ok(())
Expand Down

0 comments on commit 2f05dea

Please sign in to comment.