diff --git a/libsql/src/hrana/stream.rs b/libsql/src/hrana/stream.rs index 490824d930..310df23fc2 100644 --- a/libsql/src/hrana/stream.rs +++ b/libsql/src/hrana/stream.rs @@ -442,7 +442,6 @@ where } } -#[cfg(feature = "remote")] impl Drop for RawStream where T: HttpSend, @@ -557,3 +556,46 @@ pub enum SqlDescription { /// the scope of current transaction/prepared statement, which sent a store SQL request. SqlId(SqlId), } + +#[cfg(test)] +mod tests { + use super::*; + use std::sync::Mutex as StdMutex; + + #[derive(Clone, Default)] + struct MockSend { + sent: Arc>>, + } + + impl HttpSend for MockSend { + type Stream = futures::stream::Empty>; + type Result = futures::future::Pending>; + + fn http_send(&self, _url: Arc, _auth: Arc, _body: String) -> Self::Result { + futures::future::pending() + } + + fn oneshot(self, _url: Arc, _auth: Arc, body: String) { + self.sent.lock().unwrap().push(body); + } + } + + #[test] + fn dropping_stream_with_baton_sends_close() { + let client = MockSend::default(); + let sent = client.sent.clone(); + let raw = RawStream { + client, + baton: RefCell::new(Some("baton-1".to_string())), + pipeline_url: Arc::from("http://localhost/v3/pipeline"), + cursor_url: Arc::from("http://localhost/v3/cursor"), + auth_token: Arc::from(""), + sql_id_generator: RefCell::new(0), + }; + drop(raw); + let sent = sent.lock().unwrap(); + assert_eq!(sent.len(), 1); + assert!(sent[0].contains("baton-1"), "{}", sent[0]); + assert!(sent[0].contains("close"), "{}", sent[0]); + } +}