Skip to content

Commit d1c931a

Browse files
authored
Retry getting unread counts (#1330)
1 parent 7f2e85b commit d1c931a

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

tests/61push/03_unread_count.pl

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,46 @@ sub user_with_push_rule_fixture
6868

6969
matrix_advance_room_receipt_synced( $user1, $room_id, "m.read" => $event_id );
7070
})->then( sub {
71-
matrix_sync( $user1 );
72-
})->then( sub {
73-
my ( $body ) = @_;
71+
retry_until_success {
72+
matrix_sync( $user1 )->then( sub {
73+
my ( $body ) = @_;
7474

75-
my $room = $body->{rooms}{join}{$room_id};
76-
log_if_fail "room in sync response", $room;
75+
my $room = $body->{rooms}{join}{$room_id};
7776

78-
assert_json_keys( $room, "unread_notifications" );
79-
my $unread = $room->{unread_notifications};
80-
assert_json_keys( $unread, $counter );
77+
assert_json_keys( $room, "unread_notifications" );
78+
my $unread = $room->{unread_notifications};
79+
assert_json_keys( $unread, $counter );
80+
log_if_fail "room notifications:", $unread;
81+
82+
$unread->{$counter} == 0
83+
or die "Expected $counter to be 0";
8184

82-
$unread->{$counter} == 0
83-
or die "Expected $counter to be 0";
8485

86+
Future->done(1);
87+
});
88+
}
89+
})->then( sub {
8590
matrix_send_room_text_message_synced( $user2, $room_id,
8691
body => "Test message 2",
8792
);
8893
})->then( sub {
89-
matrix_sync( $user1 );
90-
})->then( sub {
91-
my ( $body ) = @_;
94+
retry_until_success {
95+
matrix_sync( $user1 )->then( sub {
96+
my ( $body ) = @_;
9297

93-
my $room = $body->{rooms}{join}{$room_id};
98+
my $room = $body->{rooms}{join}{$room_id};
9499

95-
assert_json_keys( $room, "unread_notifications" );
96-
my $unread = $room->{unread_notifications};
97-
assert_json_keys( $unread, $counter );
100+
assert_json_keys( $room, "unread_notifications" );
101+
my $unread = $room->{unread_notifications};
102+
assert_json_keys( $unread, $counter );
98103

99-
$unread->{$counter} == 1
100-
or die "Expected $counter to be 1";
104+
log_if_fail "room notifications:", $unread;
105+
$unread->{$counter} == 1
106+
or die "Expected $counter to be 1";
101107

102-
Future->done(1);
108+
Future->done(1);
109+
});
110+
}
103111
});
104112
};
105113
}
@@ -149,19 +157,22 @@ sub user_with_push_rule_fixture
149157
body => "Test message 2",
150158
);
151159
})->then( sub {
152-
matrix_sync( $user1 );
153-
})->then( sub {
154-
my ( $body ) = @_;
160+
retry_until_success {
161+
matrix_sync( $user1 )->then( sub {
162+
my ( $body ) = @_;
155163

156-
my $room = $body->{rooms}{join}{$room_id};
164+
my $room = $body->{rooms}{join}{$room_id};
157165

158-
assert_json_keys( $room, "unread_notifications" );
159-
my $unread = $room->{unread_notifications};
160-
assert_json_keys( $unread, "highlight_count" );
166+
assert_json_keys( $room, "unread_notifications" );
167+
my $unread = $room->{unread_notifications};
168+
assert_json_keys( $unread, "highlight_count" );
161169

162-
$unread->{highlight_count} == 1
163-
or die "Expected unread highlight count to be 1";
170+
log_if_fail "room notifications:", $unread;
171+
$unread->{highlight_count} == 1
172+
or die "Expected unread highlight count to be 1";
164173

165-
Future->done(1);
174+
Future->done(1);
175+
});
176+
}
166177
})
167178
};

0 commit comments

Comments
 (0)