File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
android/src/androidTest/java/io/ably/lib/test Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ package io .ably .lib .test ;
2
+
3
+ import org .junit .rules .TestRule ;
4
+ import org .junit .runner .Description ;
5
+ import org .junit .runners .model .Statement ;
6
+
7
+
8
+ public class RetryTestRule implements TestRule {
9
+
10
+ private final int timesToRunTestCount ;
11
+
12
+ /**
13
+ * If `times` is 0, then we should run the test once.
14
+ */
15
+ public RetryTestRule (int times ) {
16
+ this .timesToRunTestCount = times + 1 ;
17
+ }
18
+
19
+ @ Override
20
+ public Statement apply (Statement base , Description description ) {
21
+ return statement (base , description );
22
+ }
23
+
24
+ private Statement statement (Statement base , Description description ) {
25
+ return new Statement () {
26
+
27
+ @ Override
28
+ public void evaluate () throws Throwable {
29
+ Throwable latestException = null ;
30
+
31
+ for (int i = 0 ; i < timesToRunTestCount ; i ++) {
32
+ try {
33
+ base .evaluate ();
34
+ return ;
35
+ } catch (Throwable t ) {
36
+ latestException = t ;
37
+ System .err .println ("${description.methodName}: test failed on run: `$runCount`. Will run a maximum of `$timesToRunTestCount` times." );
38
+ t .printStackTrace ();
39
+ }
40
+ }
41
+
42
+ if (latestException != null ) {
43
+ System .err .println ("${description.displayName}: giving up after `$timesToRunTestCount` failures" );
44
+ throw latestException ;
45
+ }
46
+ }
47
+ };
48
+ }
49
+ }
Original file line number Diff line number Diff line change 41
41
import io .ably .lib .rest .Auth ;
42
42
import io .ably .lib .rest .Channel ;
43
43
import io .ably .lib .rest .DeviceDetails ;
44
+ import io .ably .lib .test .RetryTestRule ;
44
45
import io .ably .lib .test .common .Helpers ;
45
46
import io .ably .lib .test .common .Helpers .AsyncWaiter ;
46
47
import io .ably .lib .test .common .Helpers .CompletionWaiter ;
60
61
61
62
import org .junit .AfterClass ;
62
63
import org .junit .BeforeClass ;
64
+ import org .junit .Rule ;
63
65
import org .junit .Test ;
64
66
import org .junit .runner .RunWith ;
65
67
86
88
public class AndroidPushTest {
87
89
private static final int TIMEOUT_SECONDS = 30 ;
88
90
91
+ @ Rule
92
+ public RetryTestRule retryRule = new RetryTestRule (2 );
93
+
89
94
private class TestActivation {
90
95
private Helpers .RawHttpTracker httpTracker ;
91
96
private AblyRest rest ;
You can’t perform that action at this time.
0 commit comments