test(gui): the live viewer's "update" test waits for the line it asserts on
A newer wanderbooks writes its lines one at a time, and the viewer may look between two of them. With the unknown line last, nothing can check it, so the viewer says "newer or damaged" (BS-format-1); once the next line lands it says "update". Both are right. The test took the first error it saw and held it to the "update" wording, so a look that fell between the test's two appends failed it. The loader is unchanged by the fault: the test read the first of two correct messages. The loader path is the same on main (0 of 30 runs failed there, 0 of 30 on the branch: the natural failure is rare, and shows on a loaded machine); the branch's load only makes the gap likelier. Seen deterministically by pausing the test 300 ms between its two appends. The test now waits for the "update" and holds every message before it to the "newer or damaged" one; a new test pins the between-the-lines look by waiting on the viewer's first error before it writes the second line. The same shape was in the background-tab test: it waited for the tab's seq to move, which an entry's first journal line does, then asserted the posted cash. It now waits for the cash itself. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1fbeab7c1
commit
dce7898e96
2 files changed
+64
-13
No files matched your search
@@ -132,9 +132,29 @@ fn the_viewer_says_update_for_newer_books_and_corrupt_for_damaged_ones() {
|
||||
assert!(!err.contains("newer"), "{err}");
|
||||
}
|
||||
|
||||
/// The viewer's next error, within ten seconds. It never shows books it
|
||||
/// can't read: an update carrying books is a failure.
|
||||
fn next_error(loader: &Loader) -> String {
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
while Instant::now() < deadline {
|
||||
match loader.wait(Duration::from_millis(200)) {
|
||||
Some(Update::Error(e)) => return e,
|
||||
Some(Update::Books(_)) => panic!("the viewer read a line it doesn't know"),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
panic!("the viewer never said anything about the line it doesn't know");
|
||||
}
|
||||
|
||||
/// Following: the viewer has the books open when a newer wanderbooks
|
||||
/// writes a line this one can't read. It says to update, and keeps the
|
||||
/// books it had.
|
||||
///
|
||||
/// The writer's two lines are two writes, and the viewer may look between
|
||||
/// them: with the newer line last, nothing can check it, and the viewer
|
||||
/// says "newer or damaged" (BS-format-1) until the line after it lands.
|
||||
/// Both are right, so this waits for the "update" and holds every message
|
||||
/// before it to the "newer or damaged" one.
|
||||
#[test]
|
||||
fn a_live_viewer_says_update_when_the_books_move_ahead_of_it() {
|
||||
let data = books("live");
|
||||
@@ -147,19 +167,46 @@ fn a_live_viewer_says_update_when_the_books_move_ahead_of_it() {
|
||||
w.append("entry.evidence_inherited", json!({"entry_id": 1}))
|
||||
.unwrap();
|
||||
w.append("fx.rate_set", rate()).unwrap();
|
||||
let deadline = Instant::now() + Duration::from_secs(10);
|
||||
let mut said = None;
|
||||
while Instant::now() < deadline {
|
||||
match loader.wait(Duration::from_millis(200)) {
|
||||
Some(Update::Error(e)) => {
|
||||
said = Some(e);
|
||||
break;
|
||||
}
|
||||
Some(Update::Books(_)) => panic!("the viewer read a line it doesn't know"),
|
||||
_ => {}
|
||||
loop {
|
||||
let said = next_error(&loader);
|
||||
if said.starts_with("Journal line") {
|
||||
says_newer_or_damaged(&said);
|
||||
} else {
|
||||
says_update(&said);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The viewer looks between the writer's two lines, as it can at any time:
|
||||
/// with the newer line last it says "newer or damaged"; when the next line
|
||||
/// lands it says "update", with no new look asked for.
|
||||
#[test]
|
||||
fn a_live_viewer_that_looks_between_the_two_lines_says_update_once_the_second_lands() {
|
||||
let data = books("live-between");
|
||||
let loader = Loader::spawn(source(&data), egui::Context::default());
|
||||
match loader.wait(Duration::from_secs(10)) {
|
||||
Some(Update::Books(_)) => {}
|
||||
_ => panic!("no initial load"),
|
||||
}
|
||||
let mut w = JournalWriter::open(&data.join(JOURNAL_FILE)).unwrap();
|
||||
w.append("entry.evidence_inherited", json!({"entry_id": 1}))
|
||||
.unwrap();
|
||||
// The viewer has looked and found the newer line last.
|
||||
says_newer_or_damaged(&next_error(&loader));
|
||||
// The line after it lands: the first line is now checked, and known
|
||||
// newer. (Looks made before the second line is read may repeat the
|
||||
// last-line message; none may be anything else.)
|
||||
w.append("fx.rate_set", rate()).unwrap();
|
||||
loop {
|
||||
let said = next_error(&loader);
|
||||
if said.starts_with("Journal line") {
|
||||
says_newer_or_damaged(&said);
|
||||
} else {
|
||||
says_update(&said);
|
||||
break;
|
||||
}
|
||||
}
|
||||
says_update(&said.expect("the viewer never said to update"));
|
||||
}
|
||||
|
||||
/// A declared format this version reads opens like any books, and the
|
||||
|
||||
@@ -457,7 +457,7 @@ fn a_background_tab_follows_its_journal_and_is_current_when_shown() {
|
||||
let mut h = start_with_prefs(&w, &[("open_companies", "alpha,beta")]);
|
||||
loaded(&mut h);
|
||||
assert_eq!(h.state().active(), Some(0));
|
||||
let beta_seq = h.state().views()[1].books().unwrap().seq();
|
||||
let beta_cash = h.state().views()[1].books().unwrap().kpis.cash;
|
||||
|
||||
// Beta's journal changes while alpha is in front: 100.00 more cash.
|
||||
let mut s = Store::open(&b.data).unwrap();
|
||||
@@ -470,8 +470,12 @@ fn a_background_tab_follows_its_journal_and_is_current_when_shown() {
|
||||
10_000,
|
||||
);
|
||||
drop(s);
|
||||
// The entry is several journal lines, and the tab may read some of
|
||||
// them first (its seq moves): wait for the one that posts it, whose
|
||||
// 100.00 lands in cash.
|
||||
let beta_cash_after = beta_cash + Decimal::new(10_000, 2);
|
||||
until(&mut h, "the background tab reads the new entry", |a| {
|
||||
a.views()[1].books().unwrap().seq() > beta_seq
|
||||
a.views()[1].books().unwrap().kpis.cash == beta_cash_after
|
||||
});
|
||||
assert_eq!(h.state().active(), Some(0), "nothing brought beta forward");
|
||||
|
||||
|
||||
Reference in new issue
Block a user