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

Add tests for MSC3771 / MSC3773: threaded receipts & notifications #496

Merged
merged 10 commits into from
Oct 27, 2022

Conversation

clokep
Copy link
Member

@clokep clokep commented Oct 11, 2022

Related to #351.

Tests for the bug fixed in matrix-org/synapse#14140 specifically, but also a bit more general.

Comment on lines 14 to 26
func syncHasUnreadNotifs(roomID string, check func(gjson.Result, gjson.Result) bool) client.SyncCheckOpt {
return func(clientUserID string, topLevelSyncJSON gjson.Result) error {
unreadNotifications := topLevelSyncJSON.Get("rooms.join." + client.GjsonEscape(roomID) + ".unread_notifications")
unreadThreadNotifications := topLevelSyncJSON.Get("rooms.join." + client.GjsonEscape(roomID) + ".unread_thread_notifications")
if !unreadNotifications.Exists() {
return fmt.Errorf("syncHasUnreadNotifs(%s): missing notifications", roomID)
}
if check(unreadNotifications, unreadThreadNotifications) {
return nil
}
return fmt.Errorf("syncHasUnreadNotifs(%s): check function did not pass: %v / %v", roomID, unreadNotifications.Raw, unreadThreadNotifications.Raw)
}
}
Copy link
Contributor

@MadLittleMods MadLittleMods Oct 14, 2022

Choose a reason for hiding this comment

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

We could craft much better errors if we changed the check function into a expectedMap and displayed a diff

(however to do this in Go)

syncHasUnreadNotifs(roomID, {
  main: {
    highlight_count: 2,
    notification_count: 4
  },
  [firstEventID]: {
    label: "firstEventIDThreadNotifications",
    highlight_count: 1,
    notification_count: 4
  }
})
  • syncHasUnreadNotifs for main: Expected 2 / 4 but actual was 3 / 4 - Format is (highlights / notifications)
  • syncHasUnreadNotifs for firstEventIDThreadNotifications ($abcdef): Expected 1 / 2 but actual was 1 / 1 - Format is (highlights / notifications)

For comparison as a different, separate example, I made the errors for the MSC3030 tests a bit fancy to show the diff of what was expected vs actual in context of the room timeline so it's much easier to figure out what's going wrong, see #178

Copy link
Member Author

Choose a reason for hiding this comment

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

I left this somewhat generic because:

  1. It seems to fit better how check functions are done with complement.
  2. I suspect we will eventually want to check multiple threads.

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

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

Eric's already taken a look at this (thanks @MadLittleMods), but this is in the review queue so I also took a look.

I'd be happy to see this land as-is! I've left some thoughts and suggestions, but they're nitpicking and left to your discretion.

tests/csapi/thread_notifications_test.go Outdated Show resolved Hide resolved
tests/csapi/thread_notifications_test.go Show resolved Hide resolved
//
// Notification counts and receipts are handled by bob.
func TestThreadedReceipts(t *testing.T) {
runtime.SkipIf(t, runtime.Dendrite) // not supported
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels a bit icky to couple the test to the implementation, but I suppose we do this everywhere. Might be possible to do something cleaner with build tags, but that might be a faff too (would have to e.g. update Synapse CI and complement.sh...)

This is probably fine as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we only use build tags for unstable features?

tests/csapi/thread_notifications_test.go Outdated Show resolved Hide resolved
tests/csapi/thread_notifications_test.go Outdated Show resolved Hide resolved
tests/csapi/thread_notifications_test.go Outdated Show resolved Hide resolved
tests/csapi/thread_notifications_test.go Outdated Show resolved Hide resolved
tests/csapi/thread_notifications_test.go Show resolved Hide resolved
@clokep clokep removed the request for review from a team October 27, 2022 14:00
@clokep clokep merged commit ebfd0b5 into main Oct 27, 2022
@clokep clokep deleted the clokep/fix-main-timeline branch October 27, 2022 14:21
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.

3 participants