Skip to content

Commit 32129d9

Browse files
authored
Update the soft-fail tests to work with recent room versions (#1149)
We have some tests in tests/50federation/52soft-fail.pl which test soft-failing, but which have never been updated to work with room versions other than v1. For the most part, this is just a matter of updating them to use utility functions instead of making assumptions about the shapes of the events, but it turns out that there is another wrinkle, which is that they were making some assumptions about the state-resolution algorithm which are not true in subsequent room versions.
1 parent f8ef7a2 commit 32129d9

File tree

2 files changed

+170
-92
lines changed

2 files changed

+170
-92
lines changed

lib/SyTest/Assertions.pm

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ our @EXPORT_OK = qw(
1212
assert_ok
1313
assert_eq
1414
assert_deeply_eq
15+
assert_elements_eq
1516
1617
assert_json_object
1718
assert_json_keys
@@ -135,6 +136,55 @@ sub assert_deeply_eq
135136
_assert_deeply_eq( $got, $want, undef, $name );
136137
}
137138

139+
=head2 assert_elements_eq
140+
141+
assert_elements_eq( $got, $want, $name )
142+
143+
Fails the test if $got is not an array, or if the entries in $got are
144+
not the same as those in $want (ignoring ordering).
145+
146+
Only a shallow comparison is made between elements (ie, if they are references,
147+
they must be refs to exactly the same object).
148+
149+
=cut
150+
151+
sub assert_elements_eq
152+
{
153+
my ( $got, $want, $name ) = @_;
154+
155+
if( ref $got ne "ARRAY" ) {
156+
croak "Expected an array for $name but got ${\ pp $got }";
157+
}
158+
159+
# for quick lookup, build a hash of the entries in $got
160+
my %got_elts = map { $_ => 1 } @$got;
161+
162+
# go through the entries in $want, checking if they are in %got_elts
163+
# and crossing them off if so.
164+
my @missing_elts;
165+
foreach my $want_elt ( @$want ) {
166+
if( exists $got_elts{ $want_elt } ) {
167+
delete $got_elts{ $want_elt };
168+
} else {
169+
push @missing_elts, $want_elt;
170+
}
171+
}
172+
173+
my @msgs;
174+
if( @missing_elts ) {
175+
push @msgs, "Missing values: ${\ pp( @missing_elts ) }."
176+
}
177+
178+
# any elements left in %got_elts must be absent from $want.
179+
if( %got_elts ) {
180+
push @msgs, "Extra values: ${\ pp( keys %got_elts ) }.";
181+
}
182+
183+
if( @msgs ) {
184+
croak "Mismatch for $name: ". join(" ", @msgs);
185+
}
186+
}
187+
138188
=head2 assert_json_object
139189
140190
assert_json_object( $obj )

0 commit comments

Comments
 (0)