Skip to content

Commit

Permalink
[update-engine] fix buffer tests (#4163)
Browse files Browse the repository at this point in the history
Apparently I'd made a couple of mistakes while writing tests:

* I was adding all events a second time by accident, which was hiding
  the fact that...
* A couple not signs were flipped, whoops.
  • Loading branch information
sunshowers authored Oct 11, 2023
1 parent 97ddc7d commit 72a0429
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions update-engine/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,18 +1389,23 @@ mod tests {
test_cx
.run_filtered_test(
"all events passed in",
|buffer, event| buffer.add_event(event.clone()),
|buffer, event| {
buffer.add_event(event.clone());
true
},
WithDeltas::No,
)
.unwrap();

test_cx
.run_filtered_test(
"progress events skipped",
|buffer, event| {
if let Event::Step(event) = event {
|buffer, event| match event {
Event::Step(event) => {
buffer.add_step_event(event.clone());
true
}
Event::Progress(_) => false,
},
WithDeltas::Both,
)
Expand All @@ -1410,13 +1415,16 @@ mod tests {
.run_filtered_test(
"low-priority events skipped",
|buffer, event| match event {
Event::Step(event) => {
if event.kind.priority() == StepEventPriority::Low {
Event::Step(event) => match event.kind.priority() {
StepEventPriority::High => {
buffer.add_step_event(event.clone());
true
}
}
StepEventPriority::Low => false,
},
Event::Progress(event) => {
buffer.add_progress_event(event.clone());
true
}
},
WithDeltas::Both,
Expand All @@ -1427,13 +1435,16 @@ mod tests {
.run_filtered_test(
"low-priority and progress events skipped",
|buffer, event| match event {
Event::Step(event) => {
if event.kind.priority() == StepEventPriority::Low {
Event::Step(event) => match event.kind.priority() {
StepEventPriority::High => {
buffer.add_step_event(event.clone());
true
}
}
StepEventPriority::Low => false,
},
Event::Progress(_) => {
// Don't add progress events either.
// Don't add progress events.
false
}
},
WithDeltas::Both,
Expand Down Expand Up @@ -1565,7 +1576,10 @@ mod tests {
fn run_filtered_test(
&self,
event_fn_description: &str,
mut event_fn: impl FnMut(&mut EventBuffer<TestSpec>, &Event<TestSpec>),
mut event_fn: impl FnMut(
&mut EventBuffer<TestSpec>,
&Event<TestSpec>,
) -> bool,
with_deltas: WithDeltas,
) -> anyhow::Result<()> {
match with_deltas {
Expand All @@ -1590,7 +1604,10 @@ mod tests {

fn run_filtered_test_inner(
&self,
mut event_fn: impl FnMut(&mut EventBuffer<TestSpec>, &Event<TestSpec>),
mut event_fn: impl FnMut(
&mut EventBuffer<TestSpec>,
&Event<TestSpec>,
) -> bool,
with_deltas: bool,
) -> anyhow::Result<()> {
let description = format!("with deltas = {with_deltas}");
Expand All @@ -1608,8 +1625,9 @@ mod tests {
let mut last_seen_opt = with_deltas.then_some(None);

for (i, event) in self.generated_events.iter().enumerate() {
(event_fn)(&mut buffer, event);
buffer.add_event(event.clone());
// Going to use event_added in an upcoming commit.
let _event_added = (event_fn)(&mut buffer, event);

let report = match last_seen_opt {
Some(last_seen) => buffer.generate_report_since(last_seen),
None => buffer.generate_report(),
Expand Down

0 comments on commit 72a0429

Please sign in to comment.