From 6b7099de9a6007dd552e817b3a92a1bc45572cf0 Mon Sep 17 00:00:00 2001 From: Matt Kline Date: Wed, 26 Jul 2023 22:31:02 -0700 Subject: [PATCH] Add test for #924 fix --- rust/tests/handles_time0_messages.rs | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 rust/tests/handles_time0_messages.rs diff --git a/rust/tests/handles_time0_messages.rs b/rust/tests/handles_time0_messages.rs new file mode 100644 index 0000000000..851f16ff7c --- /dev/null +++ b/rust/tests/handles_time0_messages.rs @@ -0,0 +1,59 @@ +mod common; + +// use common::*; +use std::io::Cursor; + +use anyhow::Result; + +/// Check that chunks and statistics properly handle messages with log_time = 0 +/// and don't ignore it, using the next time as the minimum. +#[test] +fn handles_time0_messages() -> Result<()> { + let mut buf = Vec::new(); + let mut out = mcap::Writer::new(Cursor::new(&mut buf))?; + + // Channels and schemas are automatically assigned ID as they're serialized, + // and automatically deduplicated with `Arc` when deserialized. + let my_channel = mcap::Channel { + topic: String::from("time"), + message_encoding: String::from("text/plain"), + metadata: Default::default(), + schema: None, + }; + + let channel_id = out.add_channel(&my_channel)?; + + out.write_to_known_channel( + &mcap::records::MessageHeader { + channel_id, + sequence: 1, + log_time: 0, + publish_time: 0, + }, + b"Time, Dr. Freeman?", + )?; + out.write_to_known_channel( + &mcap::records::MessageHeader { + channel_id, + sequence: 2, + log_time: 42, + publish_time: 42, + }, + b"Is it really that time agian?", + )?; + + out.finish()?; + drop(out); + + let summary = mcap::read::Summary::read(&buf)?.expect("no summary"); + + let the_chunk = &summary.chunk_indexes[0]; + assert_eq!(the_chunk.message_start_time, 0); + assert_eq!(the_chunk.message_end_time, 42); + + let stats = &summary.stats.expect("no stats"); + assert_eq!(stats.message_start_time, 0); + assert_eq!(stats.message_end_time, 42); + + Ok(()) +}