Skip to content

Commit f6a1312

Browse files
committed
test summary mode
1 parent 42a3685 commit f6a1312

2 files changed

Lines changed: 57 additions & 36 deletions

File tree

datafusion/datasource/src/file_stream.rs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ mod tests {
870870
morselizer: MockMorselizer,
871871
file_names: Vec<String>,
872872
preserve_order: bool,
873+
event_summaries: bool,
873874
}
874875

875876
impl MorselTest {
@@ -878,6 +879,7 @@ mod tests {
878879
morselizer: MockMorselizer::new(),
879880
file_names: vec![],
880881
preserve_order: false,
882+
event_summaries: false,
881883
}
882884
}
883885

@@ -893,6 +895,16 @@ mod tests {
893895
self
894896
}
895897

898+
/// Snapshot only the higher-level scheduler events.
899+
///
900+
/// The full event trace is still useful for detailed tests, but for
901+
/// more complex tests those lower level events obscure the important
902+
/// events.
903+
fn with_event_summaries(mut self) -> Self {
904+
self.event_summaries = true;
905+
self
906+
}
907+
896908
async fn run(self) -> Result<String> {
897909
// handle to shared observer
898910
let observer = self.morselizer.observer().clone();
@@ -936,7 +948,12 @@ mod tests {
936948
// maintaining long hand-written event assertions separately.
937949
let mut parts = vec!["----- Output Stream -----".to_string(), output];
938950
parts.push("----- File Stream Events -----".to_string());
939-
parts.push(observer.format_events());
951+
let events = if self.event_summaries {
952+
observer.format_summary_events()
953+
} else {
954+
observer.format_events()
955+
};
956+
parts.push(events);
940957
Ok(parts.join("\n"))
941958
}
942959
}
@@ -1066,7 +1083,9 @@ mod tests {
10661083
.return_none()
10671084
.build();
10681085

1069-
let test = MorselTest::new().with_file("file1.parquet", parent_planner);
1086+
let test = MorselTest::new()
1087+
.with_file("file1.parquet", parent_planner)
1088+
.with_event_summaries();
10701089

10711090
insta::assert_snapshot!(test.run().await.unwrap(), @r"
10721091
----- Output Stream -----
@@ -1076,19 +1095,11 @@ mod tests {
10761095
----- File Stream Events -----
10771096
morselize_file: file1.parquet
10781097
planner_created: PlannerId(0)
1079-
planner_called: PlannerId(0)
10801098
morsel_produced: PlannerId(0), MorselId(10)
10811099
planner_produced_child: PlannerId(0) -> PlannerId(1)
1082-
planner_called: PlannerId(0)
1083-
planner_called: PlannerId(1)
10841100
morsel_produced: PlannerId(1), MorselId(11)
1085-
planner_called: PlannerId(1)
1086-
morsel_stream_started: MorselId(10)
10871101
morsel_stream_batch_produced: MorselId(10), BatchId(42)
1088-
morsel_stream_finished: MorselId(10)
1089-
morsel_stream_started: MorselId(11)
10901102
morsel_stream_batch_produced: MorselId(11), BatchId(43)
1091-
morsel_stream_finished: MorselId(11)
10921103
");
10931104

10941105
Ok(())
@@ -1245,8 +1256,11 @@ mod tests {
12451256
.return_none()
12461257
.build();
12471258

1248-
let test = MorselTest::new().with_file("file1.parquet", parent_planner);
1259+
let test = MorselTest::new()
1260+
.with_file("file1.parquet", parent_planner)
1261+
.with_event_summaries();
12491262

1263+
// Note that the future for planner 1 must resolve before planner 2 begins
12501264
insta::assert_snapshot!(test.run().await.unwrap(), @r"
12511265
----- Output Stream -----
12521266
Batch: 41
@@ -1256,46 +1270,21 @@ mod tests {
12561270
----- File Stream Events -----
12571271
morselize_file: file1.parquet
12581272
planner_created: PlannerId(0)
1259-
planner_called: PlannerId(0)
12601273
planner_produced_child: PlannerId(0) -> PlannerId(1)
12611274
planner_produced_child: PlannerId(0) -> PlannerId(2)
12621275
planner_produced_child: PlannerId(0) -> PlannerId(3)
1263-
planner_called: PlannerId(0)
1264-
planner_called: PlannerId(1)
12651276
io_future_created: PlannerId(1), IoFutureId(100)
1266-
planner_called: PlannerId(2)
12671277
io_future_created: PlannerId(2), IoFutureId(101)
1268-
io_future_polled: PlannerId(1), IoFutureId(100)
1269-
io_future_polled: PlannerId(2), IoFutureId(101)
1270-
io_future_polled: PlannerId(1), IoFutureId(100)
12711278
io_future_resolved: PlannerId(1), IoFutureId(100)
1272-
io_future_polled: PlannerId(2), IoFutureId(101)
1273-
planner_called: PlannerId(3)
12741279
io_future_created: PlannerId(3), IoFutureId(102)
1275-
io_future_polled: PlannerId(2), IoFutureId(101)
1276-
io_future_polled: PlannerId(3), IoFutureId(102)
1277-
io_future_polled: PlannerId(2), IoFutureId(101)
12781280
io_future_resolved: PlannerId(2), IoFutureId(101)
1279-
io_future_polled: PlannerId(3), IoFutureId(102)
12801281
io_future_resolved: PlannerId(3), IoFutureId(102)
1281-
planner_called: PlannerId(1)
12821282
morsel_produced: PlannerId(1), MorselId(11)
1283-
planner_called: PlannerId(1)
1284-
planner_called: PlannerId(2)
12851283
morsel_produced: PlannerId(2), MorselId(12)
1286-
planner_called: PlannerId(2)
1287-
planner_called: PlannerId(3)
12881284
morsel_produced: PlannerId(3), MorselId(13)
1289-
planner_called: PlannerId(3)
1290-
morsel_stream_started: MorselId(11)
12911285
morsel_stream_batch_produced: MorselId(11), BatchId(41)
1292-
morsel_stream_finished: MorselId(11)
1293-
morsel_stream_started: MorselId(12)
12941286
morsel_stream_batch_produced: MorselId(12), BatchId(42)
1295-
morsel_stream_finished: MorselId(12)
1296-
morsel_stream_started: MorselId(13)
12971287
morsel_stream_batch_produced: MorselId(13), BatchId(43)
1298-
morsel_stream_finished: MorselId(13)
12991288
");
13001289

13011290
Ok(())

datafusion/datasource/src/morsel/test_utils.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,38 @@ impl MorselObserver {
138138
.collect::<Vec<_>>()
139139
.join("\n")
140140
}
141+
142+
/// Format only the high-level scheduler events.
143+
///
144+
/// This is useful for tests where the exact `plan()` / `poll()` interleave
145+
/// is not the main point of the assertion. Summary snapshots are easier to
146+
/// review when validating broader behavior such as ordering or outstanding
147+
/// I/O limits.
148+
pub fn format_summary_events(&self) -> String {
149+
self.events()
150+
.into_iter()
151+
.filter(MorselEvent::is_summary_event)
152+
.map(|event| event.to_string())
153+
.collect::<Vec<_>>()
154+
.join("\n")
155+
}
156+
}
157+
158+
impl MorselEvent {
159+
/// Return true for the higher-level events that are most useful in compact
160+
/// scheduler snapshots.
161+
pub fn is_summary_event(&self) -> bool {
162+
matches!(
163+
self,
164+
MorselEvent::MorselizeFile { .. }
165+
| MorselEvent::PlannerCreated { .. }
166+
| MorselEvent::PlannerProducedChild { .. }
167+
| MorselEvent::IoFutureCreated { .. }
168+
| MorselEvent::IoFutureResolved { .. }
169+
| MorselEvent::MorselProduced { .. }
170+
| MorselEvent::MorselStreamBatchProduced { .. }
171+
)
172+
}
141173
}
142174

143175
/// Test [`Morselizer`] that maps file paths to a fixed set of planner specs.

0 commit comments

Comments
 (0)