Skip to content

Commit 857cffd

Browse files
committedSep 20, 2021
refactor: move disconnect to handle_close in poll
1 parent d55f808 commit 857cffd

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed
 

‎engineio/src/client/socket.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,8 @@ impl Socket {
313313
PacketId::Message => {
314314
self.socket.handle_data(packet.data.clone())?;
315315
}
316-
317316
PacketId::Close => {
318317
self.socket.handle_close()?;
319-
// set current state to not connected and stop polling
320-
self.socket.disconnect()?;
321318
}
322319
PacketId::Open => {
323320
unreachable!("Won't happen as we open the connection beforehand");
@@ -448,16 +445,36 @@ mod test {
448445
socket.close()
449446
}
450447

448+
#[test]
449+
fn test_connection_long() -> Result<()> {
450+
// Long lived socket to receive pings
451+
let url = crate::test::engine_io_server()?;
452+
let socket = builder(url).build()?;
453+
454+
socket.connect()?;
455+
456+
let mut iter = socket.iter();
457+
// hello client
458+
iter.next();
459+
// Ping
460+
iter.next();
461+
462+
socket.disconnect()?;
463+
464+
assert!(!socket.is_connected()?);
465+
466+
Ok(())
467+
}
468+
451469
#[test]
452470
fn test_connection_dynamic() -> Result<()> {
453471
let url = crate::test::engine_io_server()?;
454472
let socket = builder(url).build()?;
455473
test_connection(socket)?;
456474

457475
let url = crate::test::engine_io_polling_server()?;
458-
assert!(builder(url).build().is_err());
459-
460-
Ok(())
476+
let socket = builder(url).build()?;
477+
test_connection(socket)
461478
}
462479

463480
#[test]
@@ -489,6 +506,9 @@ mod test {
489506

490507
#[test]
491508
fn test_connection_wss() -> Result<()> {
509+
let url = crate::test::engine_io_polling_server()?;
510+
assert!(builder(url).build_websocket_with_upgrade().is_err());
511+
492512
let host =
493513
std::env::var("ENGINE_IO_SECURE_HOST").unwrap_or_else(|_| "localhost".to_owned());
494514
let mut url = crate::test::engine_io_server_secure()?;
@@ -521,6 +541,9 @@ mod test {
521541

522542
#[test]
523543
fn test_connection_ws() -> Result<()> {
544+
let url = crate::test::engine_io_polling_server()?;
545+
assert!(builder(url).build_websocket().is_err());
546+
524547
let mut url = crate::test::engine_io_server()?;
525548

526549
let builder = builder(url.clone());

‎engineio/src/socket.rs

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ impl Socket {
183183
if let Some(on_close) = self.on_close.as_ref() {
184184
spawn_scoped!(on_close(()));
185185
}
186+
187+
self.connected.store(false, Ordering::Release);
186188
Ok(())
187189
}
188190
}

0 commit comments

Comments
 (0)