From 876064113e1b6f5d97186de824313562878aa685 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 16 Oct 2020 00:51:57 +0100 Subject: [PATCH] Make retry_until_success log the reason for failure otherwise it gets swallowed. That means we can remove the same pattern from all the other places we have it. --- run-tests.pl | 14 +++++++++----- tests/30rooms/04messages.pl | 4 ---- tests/30rooms/13guestaccess.pl | 4 ---- tests/30rooms/70publicroomslist.pl | 4 ---- tests/50federation/31room-send.pl | 4 ---- tests/50federation/40publicroomlist.pl | 4 ---- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/run-tests.pl b/run-tests.pl index 1d626c4a6..9741520e1 100755 --- a/run-tests.pl +++ b/run-tests.pl @@ -413,20 +413,24 @@ sub delay } # Handy utility wrapper around Future::Utils::try_repeat_until_success which -# includes a delay on retry +# includes a delay on retry (and logs the reason for failure) sub retry_until_success(&) { my ( $code ) = @_; my $delay = 0.1; + my $iter = 0; try_repeat { - my $prev_f = shift; - - ( $prev_f ? + ( $iter++ ? delay( $delay *= 1.5 ) : Future->done ) - ->then( $code ); + ->then( $code ) + ->on_fail( sub { + my ( $exc ) = @_; + chomp $exc; + log_if_fail("Iteration $iter: not ready yet: $exc"); + }); } until => sub { !$_[0]->failure }; } diff --git a/tests/30rooms/04messages.pl b/tests/30rooms/04messages.pl index 2eac89727..37ecad52b 100644 --- a/tests/30rooms/04messages.pl +++ b/tests/30rooms/04messages.pl @@ -400,10 +400,6 @@ assert_deeply_eq( $chunk->[0]{content}, {}, 'chunk[0] content size' ); Future->done(1); - })->on_fail( sub { - my ( $exc ) = @_; - chomp $exc; - log_if_fail "Iteration $iter: not ready yet: $exc"; }); } }); diff --git a/tests/30rooms/13guestaccess.pl b/tests/30rooms/13guestaccess.pl index 3b1b73a2f..5ba4f2490 100644 --- a/tests/30rooms/13guestaccess.pl +++ b/tests/30rooms/13guestaccess.pl @@ -413,10 +413,6 @@ } Future->done( 1 ); - })->on_fail( sub { - my ( $exc ) = @_; - chomp $exc; - log_if_fail "Iteration $iter: not ready yet: $exc"; }); }; }) diff --git a/tests/30rooms/70publicroomslist.pl b/tests/30rooms/70publicroomslist.pl index 8502af213..f2eee3562 100644 --- a/tests/30rooms/70publicroomslist.pl +++ b/tests/30rooms/70publicroomslist.pl @@ -103,10 +103,6 @@ } Future->done( 1 ); - })->on_fail( sub { - my ( $exc ) = @_; - chomp $exc; - log_if_fail "Iteration $iter: not ready yet: $exc"; }); }; }); diff --git a/tests/50federation/31room-send.pl b/tests/50federation/31room-send.pl index fe2d528f1..9497a23e0 100644 --- a/tests/50federation/31room-send.pl +++ b/tests/50federation/31room-send.pl @@ -192,10 +192,6 @@ assert_deeply_eq( $chunk->[0]{content}, {}, 'chunk[0] content size' ); Future->done(1); - })->on_fail( sub { - my ( $exc ) = @_; - chomp $exc; - log_if_fail "Iteration $iter: not ready yet: $exc"; }); } }); diff --git a/tests/50federation/40publicroomlist.pl b/tests/50federation/40publicroomlist.pl index 45989cad0..0d1d6fdae 100644 --- a/tests/50federation/40publicroomlist.pl +++ b/tests/50federation/40publicroomlist.pl @@ -97,10 +97,6 @@ } Future->done(1); - })->on_fail(sub { - my ($exc) = @_; - chomp $exc; - log_if_fail "Iteration $iter: not ready yet: $exc"; }); }; })