Made message ids unique.
This commit is contained in:
		
							
								
								
									
										15
									
								
								src/queue.rs
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/queue.rs
									
									
									
									
									
								
							@@ -131,7 +131,7 @@ impl Queue {
 | 
			
		||||
    fn listen(&mut self) {
 | 
			
		||||
        loop {
 | 
			
		||||
            let mut msg = self.rx.recv().unwrap();
 | 
			
		||||
            msg.id = Uuid::max();
 | 
			
		||||
            msg.id = Uuid::new_v4();
 | 
			
		||||
            let senders = self.registry.read().unwrap();
 | 
			
		||||
            for sender in senders.iter() {
 | 
			
		||||
                sender.send(msg.reply(MsgType::ClientMessage)).unwrap();
 | 
			
		||||
@@ -169,4 +169,17 @@ mod queues {
 | 
			
		||||
            _ => unreachable!("should have been a client message"),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn new_client_messages_are_unique() {
 | 
			
		||||
        let (tx, rx) = start_queue();
 | 
			
		||||
        let msg = Message::new();
 | 
			
		||||
        let mut ids: Vec<Uuid> = Vec::new();
 | 
			
		||||
        for _ in 0..10 {
 | 
			
		||||
            tx.send(msg.reply(MsgType::NewClientMessage)).unwrap();
 | 
			
		||||
            let result = rx.recv().unwrap();
 | 
			
		||||
            assert!(!ids.contains(&result.id.clone()), "{} is a duplicate", &result.id);
 | 
			
		||||
            ids.push(result.id);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user