Skip to content

Commit d53b2b9

Browse files
Add missing uts for the optimization on fetch_entries_to. (#385)
Signed-off-by: lucasliang <[email protected]>
1 parent 03f77d9 commit d53b2b9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/failpoints/test_engine.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,52 @@ fn test_concurrent_write_perf_context() {
631631
}
632632
}
633633

634+
#[test]
635+
fn test_fetch_with_updated_entry_index() {
636+
let dir = tempfile::Builder::new()
637+
.prefix("test_fetch_with_updated_entry_index")
638+
.tempdir()
639+
.unwrap();
640+
let entry_data = vec![b'x'; 1024];
641+
let cfg = Config {
642+
dir: dir.path().to_str().unwrap().to_owned(),
643+
..Default::default()
644+
};
645+
let engine = Engine::open(cfg).unwrap();
646+
for i in 0..10 {
647+
append(
648+
&engine,
649+
i + 1,
650+
1 + i * 10,
651+
1 + i * 10 + 10,
652+
Some(&entry_data),
653+
);
654+
}
655+
assert_eq!(
656+
10,
657+
engine
658+
.fetch_entries_to::<MessageExtTyped>(1, 1, 11, None, &mut vec![])
659+
.unwrap()
660+
);
661+
// Mock: the file is broken or abnormal to read
662+
{
663+
let _f = FailGuard::new("log_file::read::err", "return");
664+
engine
665+
.fetch_entries_to::<MessageExtTyped>(10, 91, 101, None, &mut vec![])
666+
.unwrap_err();
667+
}
668+
// Mock: one entry have been updated by background rewrite thread.
669+
{
670+
let _f = FailGuard::new("log_file::read::err", "8*off->return->off");
671+
assert_eq!(
672+
10,
673+
engine
674+
.fetch_entries_to::<MessageExtTyped>(10, 91, 101, None, &mut vec![])
675+
.unwrap()
676+
);
677+
}
678+
}
679+
634680
// FIXME: this test no longer works because recovery cannot reliably detect
635681
// overwrite anomaly.
636682
// See https://github.com/tikv/raft-engine/issues/250

0 commit comments

Comments
 (0)