Clean up dead code.

This commit is contained in:
Jeff Baskin 2025-04-21 22:29:15 -04:00
parent 393b66a9f5
commit a61474f38a
6 changed files with 10 additions and 67 deletions

View File

@ -1,8 +1,4 @@
use crate::{
field::Field,
queue::{Message, MsgType, Queue},
utils::GenID,
};
use crate::queue::{Message, MsgType, Queue};
use std::{
collections::HashMap,
sync::{
@ -40,7 +36,7 @@ impl ClientChannel {
}
let (tx, rx) = channel();
reg.insert(msg.get_id(), tx);
self.queue.send(msg);
self.queue.send(msg).unwrap();
rx
}
@ -60,17 +56,6 @@ mod client_channels {
static TIMEOUT: Duration = Duration::from_millis(500);
#[test]
fn request_new_message() {
let queue = Queue::new();
let chan = ClientChannel::new(queue);
let msg_types = [MsgType::Document, MsgType::Time];
for msg_type in msg_types.iter() {
let msg = Message::new(msg_type.clone());
assert_eq!(msg.get_msg_type(), msg_type);
}
}
#[test]
fn fowards_message() {
let msg_type = MsgType::Document;
@ -122,15 +107,13 @@ mod client_channels {
pub struct Client {
channel: ClientChannel,
queue: Queue,
rx: Receiver<Message>,
}
impl Client {
fn new(chan: ClientChannel, queue: Queue, rx: Receiver<Message>) -> Self {
fn new(chan: ClientChannel, rx: Receiver<Message>) -> Self {
Self {
channel: chan,
queue: queue,
rx: rx,
}
}
@ -139,7 +122,7 @@ impl Client {
let (tx, rx) = channel();
queue.add(tx.clone(), RESPONS_TO.to_vec());
let chan = ClientChannel::new(queue.clone());
let client = Client::new(chan.clone(), queue, rx);
let client = Client::new(chan.clone(), rx);
spawn(move || {
client.listen();
});
@ -171,7 +154,7 @@ mod clients {
let chan_rx = chan.send(Message::new(MsgType::SessionValidate));
let msg = queue_rx.recv_timeout(TIMEOUT).unwrap();
let expected = create_validated_reply(msg);
queue.send(expected.clone());
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

@ -50,10 +50,6 @@ pub mod documents {
const TIMEOUT: Duration = Duration::from_millis(500);
pub fn get_root_document() -> Message {
Message::new(MsgType::DocumentRequest)
}
fn setup_document(listen_for: Vec<MsgType>) -> (Queue, Receiver<Message>) {
let queue = Queue::new();
let (tx, rx) = channel();

View File

@ -4,7 +4,6 @@ mod document;
mod field;
mod queue;
mod session;
mod utils;
use client::{Client, ClientChannel};
use clock::Clock;
@ -43,17 +42,4 @@ impl MoreThanText {
let reply = rx.recv().unwrap();
reply.get_data("sess_id").unwrap().to_uuid().unwrap()
}
pub fn request<F>(&mut self, session: Option<F>) -> Message
where
F: Into<Field>,
{
let sess = match session {
Some(id) => Some(id.into()),
None => None,
};
let req = Message::new(MsgType::DocumentRequest);
let rx = self.client_channel.send(req.into());
rx.recv().unwrap()
}
}

View File

@ -60,7 +60,7 @@ where
{
type Rejection = Infallible;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
let Extension(cookies) = parts.extract::<Extension<Cookies>>().await.unwrap();
let Extension(mut state) = parts.extract::<Extension<MoreThanText>>().await.unwrap();
let req_id = match cookies.get(SESSION_KEY) {
@ -80,10 +80,7 @@ where
}
}
async fn mtt_conn(
sess_id: SessionID,
state: State<MoreThanText>,
) -> impl IntoResponse {
async fn mtt_conn(_sess_id: SessionID, _state: State<MoreThanText>) -> impl IntoResponse {
("something".to_string(),)
}
@ -141,7 +138,7 @@ mod servers {
.unwrap();
assert_eq!(initial.status(), StatusCode::OK);
let sessid = initial.headers().get(SET_COOKIE).unwrap();
let mut request = Request::builder()
let request = Request::builder()
.uri("/")
.header(COOKIE, sessid.clone())
.body(Body::empty())

View File

@ -7,7 +7,6 @@ use uuid::Uuid;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum MsgType {
ClientRequest,
Document,
DocumentRequest,
SessionValidate,
@ -79,7 +78,6 @@ impl Message {
#[cfg(test)]
mod messages {
use super::*;
use crate::document::documents::get_root_document;
#[test]
fn new_message() {
@ -108,11 +106,11 @@ mod messages {
let mut msg = Message::new(MsgType::SessionValidate);
msg.id = id.clone();
msg.add_data("test", "test");
let data = MsgType::ClientRequest;
let data = MsgType::SessionValidate;
let result = msg.reply(data);
assert_eq!(result.id, id);
match result.msg_type {
MsgType::ClientRequest => {}
MsgType::SessionValidate => {}
_ => unreachable!("should have been a registration request"),
}
assert!(result.data.is_empty());

View File

@ -1,17 +0,0 @@
use uuid::Uuid;
pub struct GenID;
impl GenID {
pub fn new() -> Self {
GenID {}
}
}
impl Iterator for GenID {
type Item = Uuid;
fn next(&mut self) -> Option<Self::Item> {
Some(Uuid::new_v4())
}
}