Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Tests: the authentication deadline test writes its first line before the deadline starts (#7428)

.CooCoo89b9e72640d9
diff --git a/crates/automation/src/security.rs b/crates/automation/src/security.rs
index 89a760b32..0735511f2 100644
--- a/crates/automation/src/security.rs
+++ b/crates/automation/src/security.rs
@@ -480,16 +480,23 @@ mod tests {
#[test]
fn an_authenticated_connection_outlives_the_authentication_deadline() {
let (server, mut client) = tcp_pair();
+ // The test thread writes the first line before the deadline starts. The sender writes the
+ // second line once the connection has authenticated and the deadline has passed.
+ client.write_all(b"one\n").unwrap();
+ let limit = Duration::from_secs(1);
+ let mut reader = std::io::BufReader::new(AuthDeadlineStream::new(server, limit));
+ let deadline = Instant::now() + limit;
+ let (tx, rx) = std::sync::mpsc::channel();
let sender = std::thread::spawn(move || {
- client.write_all(b"one\n").unwrap();
- std::thread::sleep(Duration::from_millis(500));
+ rx.recv().unwrap();
+ std::thread::sleep((deadline + Duration::from_millis(300)).saturating_duration_since(Instant::now()));
client.write_all(b"two\n").unwrap();
});
- let mut reader = std::io::BufReader::new(AuthDeadlineStream::new(server, Duration::from_millis(200)));
let mut line = String::new();
assert_eq!(read_bounded_line(&mut reader, &mut line).unwrap(), LineRead::Line);
assert_eq!(line, "one\n");
reader.get_mut().authenticated().unwrap();
+ tx.send(()).unwrap();
// Sent 300 ms after the deadline: only the idle timeout applies now.
assert_eq!(read_bounded_line(&mut reader, &mut line).unwrap(), LineRead::Line);
assert_eq!(line, "two\n");