Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[update-engine] fix buffer tests #4163

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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