@@ -22,7 +22,10 @@ public class TestEnvironment {
22
22
private static final String DEFAULT_TIMEOUT_MILLIS_ENV = "DEFAULT_TIMEOUT_MILLIS" ;
23
23
private static final long DEFAULT_TIMEOUT_MILLIS = 100 ;
24
24
25
+ private static final String DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS_ENV = "DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS" ;
26
+
25
27
private final long defaultTimeoutMillis ;
28
+ private final long defaultNoSignalsTimeoutMillis ;
26
29
private final boolean printlnDebug ;
27
30
28
31
private CopyOnWriteArrayList <Throwable > asyncErrors = new CopyOnWriteArrayList <Throwable >();
@@ -32,16 +35,29 @@ public class TestEnvironment {
32
35
* interactions. Longer timeout does not invalidate the correctness of
33
36
* the implementation, but can in some cases result in longer time to
34
37
* run the tests.
35
- *
36
38
* @param defaultTimeoutMillis default timeout to be used in all expect* methods
39
+ * @param defaultNoSignalsTimeoutMillis default timeout to be used when no further signals are expected anymore
37
40
* @param printlnDebug if true, signals such as OnNext / Request / OnComplete etc will be printed to standard output,
38
- * often helpful to pinpoint simple race conditions etc.
39
41
*/
40
- public TestEnvironment (long defaultTimeoutMillis , boolean printlnDebug ) {
42
+ public TestEnvironment (long defaultTimeoutMillis , long defaultNoSignalsTimeoutMillis , boolean printlnDebug ) {
41
43
this .defaultTimeoutMillis = defaultTimeoutMillis ;
44
+ this .defaultNoSignalsTimeoutMillis = defaultNoSignalsTimeoutMillis ;
42
45
this .printlnDebug = printlnDebug ;
43
46
}
44
47
48
+ /**
49
+ * Tests must specify the timeout for expected outcome of asynchronous
50
+ * interactions. Longer timeout does not invalidate the correctness of
51
+ * the implementation, but can in some cases result in longer time to
52
+ * run the tests.
53
+ *
54
+ * @param defaultTimeoutMillis default timeout to be used in all expect* methods
55
+ * @param defaultNoSignalsTimeoutMillis default timeout to be used when no further signals are expected anymore
56
+ */
57
+ public TestEnvironment (long defaultTimeoutMillis , long defaultNoSignalsTimeoutMillis ) {
58
+ this (defaultTimeoutMillis , defaultNoSignalsTimeoutMillis , false );
59
+ }
60
+
45
61
/**
46
62
* Tests must specify the timeout for expected outcome of asynchronous
47
63
* interactions. Longer timeout does not invalidate the correctness of
@@ -51,7 +67,7 @@ public TestEnvironment(long defaultTimeoutMillis, boolean printlnDebug) {
51
67
* @param defaultTimeoutMillis default timeout to be used in all expect* methods
52
68
*/
53
69
public TestEnvironment (long defaultTimeoutMillis ) {
54
- this (defaultTimeoutMillis , false );
70
+ this (defaultTimeoutMillis , defaultTimeoutMillis , false );
55
71
}
56
72
57
73
/**
@@ -67,7 +83,7 @@ public TestEnvironment(long defaultTimeoutMillis) {
67
83
* often helpful to pinpoint simple race conditions etc.
68
84
*/
69
85
public TestEnvironment (boolean printlnDebug ) {
70
- this (envDefaultTimeoutMillis (), printlnDebug );
86
+ this (envDefaultTimeoutMillis (), envDefaultNoSignalsTimeoutMillis (), printlnDebug );
71
87
}
72
88
73
89
/**
@@ -80,13 +96,22 @@ public TestEnvironment(boolean printlnDebug) {
80
96
* or the default value ({@link TestEnvironment#DEFAULT_TIMEOUT_MILLIS}) will be used.
81
97
*/
82
98
public TestEnvironment () {
83
- this (envDefaultTimeoutMillis ());
99
+ this (envDefaultTimeoutMillis (), envDefaultNoSignalsTimeoutMillis () );
84
100
}
85
101
102
+ /** This timeout is used when waiting for a signal to arrive. */
86
103
public long defaultTimeoutMillis () {
87
104
return defaultTimeoutMillis ;
88
105
}
89
106
107
+ /**
108
+ * This timeout is used when asserting that no further signals are emitted.
109
+ * Note that this timeout default
110
+ */
111
+ public long defaultNoSignalsTimeoutMillis () {
112
+ return defaultNoSignalsTimeoutMillis ;
113
+ }
114
+
90
115
/**
91
116
* Tries to parse the env variable {@code DEFAULT_TIMEOUT_MILLIS} as long and returns the value if present OR its default value.
92
117
*
@@ -97,11 +122,26 @@ public static long envDefaultTimeoutMillis() {
97
122
if (envMillis == null ) return DEFAULT_TIMEOUT_MILLIS ;
98
123
else try {
99
124
return Long .parseLong (envMillis );
100
- } catch (NumberFormatException ex ) {
125
+ } catch (NumberFormatException ex ) {
101
126
throw new IllegalArgumentException (String .format ("Unable to parse %s env value [%s] as long!" , DEFAULT_TIMEOUT_MILLIS_ENV , envMillis ), ex );
102
127
}
103
128
}
104
129
130
+ /**
131
+ * Tries to parse the env variable {@code DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS} as long and returns the value if present OR its default value.
132
+ *
133
+ * @throws java.lang.IllegalArgumentException when unable to parse the env variable
134
+ */
135
+ public static long envDefaultNoSignalsTimeoutMillis () {
136
+ final String envMillis = System .getenv (DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS_ENV );
137
+ if (envMillis == null ) return envDefaultTimeoutMillis ();
138
+ else try {
139
+ return Long .parseLong (envMillis );
140
+ } catch (NumberFormatException ex ) {
141
+ throw new IllegalArgumentException (String .format ("Unable to parse %s env value [%s] as long!" , DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS_ENV , envMillis ), ex );
142
+ }
143
+ }
144
+
105
145
/**
106
146
* To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously.
107
147
* This method does *NOT* fail the test - it's up to inspections of the error to fail the test if required.
@@ -227,7 +267,7 @@ public Throwable dropAsyncError() {
227
267
* were signalled pior to, or during that time (by calling {@code flop()}).
228
268
*/
229
269
public void verifyNoAsyncErrors () {
230
- verifyNoAsyncErrors (defaultTimeoutMillis ());
270
+ verifyNoAsyncErrors (defaultNoSignalsTimeoutMillis ());
231
271
}
232
272
233
273
/**
@@ -485,11 +525,11 @@ public <E extends Throwable> E expectError(Class<E> expected, long timeoutMillis
485
525
}
486
526
487
527
public void expectNone () throws InterruptedException {
488
- expectNone (env .defaultTimeoutMillis ());
528
+ expectNone (env .defaultNoSignalsTimeoutMillis ());
489
529
}
490
530
491
531
public void expectNone (String errMsgPrefix ) throws InterruptedException {
492
- expectNone (env .defaultTimeoutMillis (), errMsgPrefix );
532
+ expectNone (env .defaultNoSignalsTimeoutMillis (), errMsgPrefix );
493
533
}
494
534
495
535
public void expectNone (long withinMillis ) throws InterruptedException {
0 commit comments