Skip to content

Commit 16429fa

Browse files
fix(dev): handle out of order reads in test_fair_reads (#24270)
* fix(dev): handle out of order reads in test_fair_reads * chore(vdev): apply vdev rust check fixes
1 parent 5edc393 commit 16429fa

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/sources/file.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,15 +2071,15 @@ mod tests {
20712071
writeln!(&mut older, "hello i am the old file").unwrap();
20722072
writeln!(&mut older, "i have been around a while").unwrap();
20732073
writeln!(&mut older, "you can read newer files at the same time").unwrap();
2074-
older.sync_all().unwrap(); // sync_all is needed due to windows
2074+
older.sync_all().unwrap();
20752075

20762076
let newer_path = dir.path().join("a_newer_file");
20772077
let mut newer = File::create(&newer_path).unwrap();
20782078

20792079
writeln!(&mut newer, "and i am the new file").unwrap();
20802080
writeln!(&mut newer, "this should be interleaved with the old one").unwrap();
20812081
writeln!(&mut newer, "which is fine because we want fairness").unwrap();
2082-
newer.sync_all().unwrap(); // sync_all is needed due to windows
2082+
newer.sync_all().unwrap();
20832083

20842084
let received = run_file_source(
20852085
&config,
@@ -2092,17 +2092,24 @@ mod tests {
20922092

20932093
let received = extract_messages_value(received);
20942094

2095-
assert_eq!(
2096-
received,
2097-
vec![
2098-
"hello i am the old file".into(),
2099-
"and i am the new file".into(),
2100-
"i have been around a while".into(),
2101-
"this should be interleaved with the old one".into(),
2102-
"you can read newer files at the same time".into(),
2103-
"which is fine because we want fairness".into(),
2104-
]
2105-
);
2095+
let old_first = vec![
2096+
"hello i am the old file".into(),
2097+
"and i am the new file".into(),
2098+
"i have been around a while".into(),
2099+
"this should be interleaved with the old one".into(),
2100+
"you can read newer files at the same time".into(),
2101+
"which is fine because we want fairness".into(),
2102+
];
2103+
let new_first: Vec<_> = old_first
2104+
.chunks(2)
2105+
.flat_map(|chunk| chunk.iter().rev().cloned().collect::<Vec<_>>())
2106+
.collect();
2107+
2108+
if received[0] == old_first[0] {
2109+
assert_eq!(received, old_first);
2110+
} else {
2111+
assert_eq!(received, new_first);
2112+
}
21062113
}
21072114

21082115
#[tokio::test]

0 commit comments

Comments
 (0)