Skip to content

Commit

Permalink
test(integration): Enable test_notification.
Browse files Browse the repository at this point in the history
This test was failing since the migration from the sliding sync proxy
to Synapse.

This patch fixes the test. The failing part was:

```rust
assert_eq!(notification.joined_members_count, 1);
```

This patch changes the value from 1 to 0. Indeed, Synapse doesn't share
this data for the sake of privacy because the room is not joined.

A comment has been made on MSC4186 to precise this behaviour:
matrix-org/matrix-spec-proposals#4186 (comment).

Moreover, this test was asserting a bug (which is alright), but now
a bug report has been made. The patch contains the link to this bug
report.

The code has been a bit rewritten to make it simpler, and more comments
have been added.
  • Loading branch information
Hywan committed Sep 25, 2024
1 parent 8469c64 commit a623d64
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use tracing::warn;
use crate::helpers::TestClientBuilder;

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[ignore]
async fn test_notification() -> Result<()> {
// Create new users for each test run, to avoid conflicts with invites existing
// from previous runs.
Expand Down Expand Up @@ -61,14 +60,16 @@ async fn test_notification() -> Result<()> {
let room_id = alice_room.room_id().to_owned();

// Bob receives a notification about it.

let bob_invite_response = bob.sync_once(Default::default()).await?;
let sync_token = bob_invite_response.next_batch;

let mut invited_rooms = bob_invite_response.rooms.invite.into_iter();
let mut invited_rooms = bob_invite_response.rooms.invite;

assert_eq!(invited_rooms.len(), 1, "must be only one invitation");

let (_, invited_room) = invited_rooms.next().expect("must be invited to one room");
assert!(invited_rooms.next().is_none(), "no more invited rooms: {invited_rooms:#?}");
let Some(invited_room) = invited_rooms.get(&room_id) else {
panic!("bob is invited in an unexpected room");
};

if let Some(event_id) = invited_room.invite_state.events.iter().find_map(|event| {
let Ok(AnyStrippedStateEvent::RoomMember(room_member_ev)) = event.deserialize() else {
Expand All @@ -90,15 +91,16 @@ async fn test_notification() -> Result<()> {
// Try with sliding sync first.
let notification_client =
NotificationClient::new(bob.clone(), process_setup.clone()).await.unwrap();

assert_let!(
NotificationStatus::Event(notification) =
notification_client.get_notification_with_sliding_sync(&room_id, &event_id).await?
);

warn!("sliding_sync: checking invite notification");

assert_matches!(notification.event, NotificationEvent::Invite(_));
assert_eq!(notification.event.sender(), alice.user_id().unwrap());
assert_eq!(notification.joined_members_count, 1);
assert_eq!(notification.is_room_encrypted, None);
assert!(notification.is_direct_message_room);

Expand All @@ -109,8 +111,10 @@ async fn test_notification() -> Result<()> {
assert_eq!(notification.sender_display_name.as_deref(), Some(ALICE_NAME));

// In theory, the room name ought to be ROOM_NAME here, but the sliding sync
// proxy returns the other person's name as the room's name (as of
// server returns the other person's name as the room's name (as of
// 2023-08-04).
//
// See https://github.com/element-hq/synapse/issues/17763.
assert!(notification.room_computed_display_name != ROOM_NAME);
assert_eq!(notification.room_computed_display_name, ALICE_NAME);

Expand All @@ -125,7 +129,7 @@ async fn test_notification() -> Result<()> {
warn!("Couldn't get the invite event.");
}

// Bob accepts the invite, joins the room.
// Bob inspects the invite room.
{
let room = bob.get_room(&room_id).expect("bob doesn't know about the room");
ensure!(
Expand All @@ -137,13 +141,16 @@ async fn test_notification() -> Result<()> {
assert_eq!(sender.user_id(), alice.user_id().expect("alice has a user_id"));
}

// Bob joins the room.
bob.get_room(alice_room.room_id()).unwrap().join().await?;
bob.get_room(alice_room.room_id())
.unwrap()
// Bob joins the room.
.join()
.await?;

// Now Alice sends a message to Bob.
alice_room.send(RoomMessageEventContent::text_plain("Hello world!")).await?;

// In this sync, bob receives the message from Alice.
// In this sync, Bob receives the message from Alice.
let bob_response = bob.sync_once(SyncSettings::default().token(sync_token)).await?;

let mut joined_rooms = bob_response.rooms.join.into_iter();
Expand Down Expand Up @@ -201,6 +208,7 @@ async fn test_notification() -> Result<()> {
assert_eq!(notification.room_computed_display_name, ROOM_NAME);
};

// Check with sliding sync.
let notification_client =
NotificationClient::new(bob.clone(), process_setup.clone()).await.unwrap();
assert_let!(
Expand All @@ -209,6 +217,7 @@ async fn test_notification() -> Result<()> {
);
check_notification(true, notification);

// Check with `/context`.
let notification_client = NotificationClient::new(bob.clone(), process_setup).await.unwrap();
let notification = notification_client
.get_notification_with_context(&room_id, &event_id)
Expand Down

0 comments on commit a623d64

Please sign in to comment.