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 message size test #104

Merged
merged 5 commits into from
May 1, 2024
Merged
Changes from 4 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
28 changes: 24 additions & 4 deletions libraries/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub mod sensor;
pub mod sensor_status;
pub mod state;

pub const MAX_SIZE: usize = 64;
NoahSprenger marked this conversation as resolved.
Show resolved Hide resolved
pub const MAX_HEALTH_SIZE: usize = 47;
pub const MAX_SENSOR_SIZE: usize = 53;
pub const MAX_STATE_SIZE: usize = 13;
pub const MAX_LOGNCOMMAND_SIZE: usize = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know they are the same size, but they might not always be the same size, can you split these.


pub use logging::{ErrorContext, Event, Log, LogLevel};

Expand Down Expand Up @@ -70,16 +73,33 @@ impl Message {

#[cfg(test)]
mod test {
use crate::{Message, MAX_SIZE};
use crate::{Message, MAX_HEALTH_SIZE, MAX_LOGNCOMMAND_SIZE, MAX_SENSOR_SIZE, MAX_STATE_SIZE};
use proptest::prelude::*;

proptest! {
#[test]
fn message_size(msg: Message) {
let bytes = postcard::to_allocvec(&msg).unwrap();

dbg!(msg);
assert!(dbg!(bytes.len()) <= MAX_SIZE);
dbg!(&msg);
// The size of the message should be less than or equal the maximum size.
match msg.data {
crate::Data::State(_) => {
assert!(dbg!(bytes.len()) <= MAX_STATE_SIZE);
}
crate::Data::Sensor(_) => {
assert!(dbg!(bytes.len()) <= MAX_SENSOR_SIZE);
}
crate::Data::Log(_) => {
assert!(dbg!(bytes.len()) <= MAX_LOGNCOMMAND_SIZE);
}
crate::Data::Command(_) => {
assert!(dbg!(bytes.len()) <= MAX_LOGNCOMMAND_SIZE);
}
crate::Data::Health(_) => {
assert!(dbg!(bytes.len()) <= MAX_HEALTH_SIZE);
}
}
}
}
}
Loading