Reattached document service.

This commit is contained in:
Jeff Baskin 2025-04-22 08:31:25 -04:00
parent 0ab0b59f4c
commit 38af08eb14
3 changed files with 30 additions and 2 deletions

View File

@ -155,4 +155,19 @@ mod clients {
assert_eq!(result.get_id(), expected.get_id());
assert_eq!(result.get_msg_type(), expected.get_msg_type());
}
#[test]
fn document_return() {
let queue = Queue::new();
let (queue_tx, queue_rx) = channel();
queue.add(queue_tx, [MsgType::DocumentRequest].to_vec());
let chan = Client::start(queue.clone());
let chan_rx = chan.send(Message::new(MsgType::DocumentRequest));
let msg = queue_rx.recv_timeout(TIMEOUT).unwrap();
let expected = msg.reply(MsgType::Document);
queue.send(expected.clone()).unwrap();
let result = chan_rx.recv_timeout(TIMEOUT).unwrap();
assert_eq!(result.get_id(), expected.get_id());
assert_eq!(result.get_msg_type(), expected.get_msg_type());
}
}

View File

@ -42,4 +42,12 @@ impl MoreThanText {
let reply = rx.recv().unwrap();
reply.get_data("sess_id").unwrap().to_uuid().unwrap()
}
pub fn get_document(&self, sess_id: Uuid) -> String {
let mut msg = Message::new(MsgType::DocumentRequest);
msg.add_data("sess_id", sess_id);
let rx = self.client_channel.send(msg);
let reply = rx.recv().unwrap();
reply.get_data("doc").unwrap().to_string()
}
}

View File

@ -80,8 +80,13 @@ where
}
}
async fn mtt_conn(_sess_id: SessionID, _state: State<MoreThanText>) -> impl IntoResponse {
("something".to_string(),)
async fn mtt_conn(sess_id: SessionID, state: State<MoreThanText>) -> impl IntoResponse {
let (tx, mut rx) = channel(1);
spawn(async move {
tx.send(state.get_document(sess_id.0)).await.unwrap();
});
let content = rx.recv().await.unwrap();
content
}
#[cfg(test)]