Skip to content

Test: Replace sync_timeline_event! with EventFactory for beacon events in room integration test #5051

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

yousefmoazzam
Copy link
Contributor

Part of #3716

I think I've done something sensible for adding the ability to put age into the unsigned data of an event, but it's possible I've misunderstood how the fields on Unsigned are being used.

It seemed like fields from different *Unsigned types from ruma were all put onto the single Unsigned struct (ie, transaction_id and relations from RoomMemberUnsigned, and redacted_because from RedactedUnsigned), and that some but not all fields on an Unsigned instance within an EventBuilder would be made a Some value depending on what event type was being created.

So, I just stuck another field onto Unsigned to allow age to be in the unsigned data, even though it's not a field that's available on every *Unsigned type, imagining it'd be used only for events which actually could have age in the unsigned data. Hope that makes sense!

And apologies for the slightly gnarly <&EventId>::try_from bit. I would have just used the event_id! macro, but rust doesn't allow doing event_id!(format!(...)) (ie, trying to run one macro and then pass its output as input to another macro).

Signed-off-by: Yousef Moazzam [email protected]

@yousefmoazzam yousefmoazzam requested a review from a team as a code owner May 16, 2025 22:00
@yousefmoazzam yousefmoazzam requested review from andybalaam and removed request for a team May 16, 2025 22:00
Copy link

codecov bot commented May 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.85%. Comparing base (ea4c9a4) to head (819ee49).
Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5051   +/-   ##
=======================================
  Coverage   85.85%   85.85%           
=======================================
  Files         325      325           
  Lines       35937    35937           
=======================================
  Hits        30855    30855           
  Misses       5082     5082           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@poljar poljar requested review from poljar and removed request for andybalaam May 19, 2025 07:23
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Looks mostly good, I left some minor suggestions if you're up for it.

timeline_events.push(
f.beacon(
owned_event_id!("$15139375514XsgmR:localhost"),
format!("geo:{nth}.9575274619722,12.494122581370175;u={nth}"),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit too stringly typed for my taste.

What do you think about passing in the longitude, latitude and uncertainty as arguments and the string gets built in the beacon() function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's a good point, I agree that the geo URI could be handled more robustly rather than just passing a string, I'll do that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in fixup commit dbf6516 + corresponding changes to tests done in fixup commit 4c3957c.

I modified the asserts because the printing of the float latitude and longitude values was "slightly off", most likely due to floating-point representation oddities. An example I saw from one of the tests would probably explain it more succinctly; this code:

println!("value is {}", 12.494122581370175);

prints this:

value is 12.494122581370174

Similarly for 10.000000 getting printed as 10 for the other test.

So, I opted to use the format! macro to produced the expected value/LHS of the assertions.

The nicest way to do this could be pretty subjective, so no worries at all about further comments on making it better. I decided to interpolate the float values as they're the potentially problematic ones, and I put the integer value inside the string literal since integers aren't problematic like decimals represented with floating-point.

format!("geo:{nth}.9575274619722,12.494122581370175;u={nth}"),
Some(MilliSecondsSinceUnixEpoch(1_636_829_458u32.into())),
)
.event_id(<&EventId>::try_from(format!("$event_for_stream_{nth}").as_str()).unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting the string or the event ID into a variable at the top might be a bit less gnarly.

let event_id: &EventId = <&EventId>::try_from(format!(...));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a fair suggestion, I think inlining the entire thing was a bit much, I'll split it up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in fixup commit eb9ae84

@@ -790,6 +806,16 @@ impl EventFactory {
self.event(event)
}

/// Create a new `org.matrix.msc3672.beacon` event.
Copy link
Contributor

Choose a reason for hiding this comment

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

An example for this method would be nice, though not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I'm happy to make the docstring more useful by adding an example, thanks for the suggestion!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in fixup commit 819ee49

@yousefmoazzam yousefmoazzam requested a review from poljar May 19, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants