6
6
import org .reactivestreams .tck .support .SubscriberBufferOverflowException ;
7
7
import org .reactivestreams .tck .support .Optional ;
8
8
9
- import java .text .NumberFormat ;
10
9
import java .util .LinkedList ;
11
10
import java .util .List ;
12
11
import java .util .concurrent .ArrayBlockingQueue ;
@@ -107,7 +106,7 @@ public static long envDefaultTimeoutMillis() {
107
106
* To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously.
108
107
* This method does *NOT* fail the test - it's up to inspections of the error to fail the test if required.
109
108
*
110
- * Use {@code env.verifyNoAsyncErrors ()} at the end of your TCK tests to verify there no flops called during it's execution.
109
+ * Use {@code env.verifyNoAsyncErrorsNoDelay ()} at the end of your TCK tests to verify there no flops called during it's execution.
111
110
* To check investigate asyncErrors more closely you can use {@code expectError} methods or collect the error directly
112
111
* from the environment using {@code env.dropAsyncError()}.
113
112
*
@@ -127,7 +126,7 @@ public void flop(String msg) {
127
126
*
128
127
* This overload keeps the passed in throwable as the asyncError, instead of creating an AssertionError for this.
129
128
*
130
- * Use {@code env.verifyNoAsyncErrors ()} at the end of your TCK tests to verify there no flops called during it's execution.
129
+ * Use {@code env.verifyNoAsyncErrorsNoDelay ()} at the end of your TCK tests to verify there no flops called during it's execution.
131
130
* To check investigate asyncErrors more closely you can use {@code expectError} methods or collect the error directly
132
131
* from the environment using {@code env.dropAsyncError()}.
133
132
*
@@ -147,7 +146,7 @@ public void flop(Throwable thr, String msg) {
147
146
*
148
147
* This overload keeps the passed in throwable as the asyncError, instead of creating an AssertionError for this.
149
148
*
150
- * Use {@code env.verifyNoAsyncErrors ()} at the end of your TCK tests to verify there no flops called during it's execution.
149
+ * Use {@code env.verifyNoAsyncErrorsNoDelay ()} at the end of your TCK tests to verify there no flops called during it's execution.
151
150
* To check investigate asyncErrors more closely you can use {@code expectError} methods or collect the error directly
152
151
* from the environment using {@code env.dropAsyncError()}.
153
152
*
@@ -167,7 +166,7 @@ public void flop(Throwable thr) {
167
166
* This method DOES fail the test right away (it tries to, by throwing an AssertionException),
168
167
* in such it is different from {@link org.reactivestreams.tck.TestEnvironment#flop} which only records the error.
169
168
*
170
- * Use {@code env.verifyNoAsyncErrors ()} at the end of your TCK tests to verify there no flops called during it's execution.
169
+ * Use {@code env.verifyNoAsyncErrorsNoDelay ()} at the end of your TCK tests to verify there no flops called during it's execution.
171
170
* To check investigate asyncErrors more closely you can use {@code expectError} methods or collect the error directly
172
171
* from the environment using {@code env.dropAsyncError()}.
173
172
*
@@ -192,7 +191,7 @@ public <T> void subscribe(Publisher<T> pub, TestSubscriber<T> sub) throws Interr
192
191
public <T > void subscribe (Publisher <T > pub , TestSubscriber <T > sub , long timeoutMillis ) throws InterruptedException {
193
192
pub .subscribe (sub );
194
193
sub .subscription .expectCompletion (timeoutMillis , String .format ("Could not subscribe %s to Publisher %s" , sub , pub ));
195
- verifyNoAsyncErrors ();
194
+ verifyNoAsyncErrorsNoDelay ();
196
195
}
197
196
198
197
public <T > ManualSubscriber <T > newBlackholeSubscriber (Publisher <T > pub ) throws InterruptedException {
@@ -223,16 +222,39 @@ public Throwable dropAsyncError() {
223
222
}
224
223
}
225
224
225
+ /**
226
+ * Waits for {@link TestEnvironment#defaultTimeoutMillis()} and then verifies that no asynchronous errors
227
+ * were signalled pior to, or during that time (by calling {@code flop()}).
228
+ */
229
+ public void verifyNoAsyncErrors () {
230
+ verifyNoAsyncErrors (defaultTimeoutMillis ());
231
+ }
232
+
233
+ /**
234
+ * This version of {@code verifyNoAsyncErrors} should be used when errors still could be signalled
235
+ * asynchronously during {@link TestEnvironment#defaultTimeoutMillis()} time.
236
+ * <p></p>
237
+ * It will immediatly check if any async errors were signaled (using {@link TestEnvironment#flop(String)},
238
+ * and if no errors encountered wait for another default timeout as the errors may yet be signalled.
239
+ * The initial check is performed in order to fail-fast in case of an already failed test.
240
+ */
226
241
public void verifyNoAsyncErrors (long delay ) {
227
242
try {
243
+ verifyNoAsyncErrorsNoDelay ();
244
+
228
245
Thread .sleep (delay );
229
- verifyNoAsyncErrors ();
246
+ verifyNoAsyncErrorsNoDelay ();
230
247
} catch (InterruptedException e ) {
231
248
throw new RuntimeException (e );
232
249
}
233
250
}
234
251
235
- public void verifyNoAsyncErrors () {
252
+ /**
253
+ * Verifies that no asynchronous errors were signalled pior to calling this method (by calling {@code flop()}).
254
+ * This version of verifyNoAsyncError <b>does not wait before checking for asynchronous errors</b>, and is to be used
255
+ * for example in tight loops etc.
256
+ */
257
+ public void verifyNoAsyncErrorsNoDelay () {
236
258
for (Throwable e : asyncErrors ) {
237
259
if (e instanceof AssertionError ) {
238
260
throw (AssertionError ) e ;
@@ -267,6 +289,9 @@ public Optional<StackTraceElement> findCallerMethodInStackTrace(String method) {
267
289
268
290
// ---- classes ----
269
291
292
+ /**
293
+ * {@link Subscriber} implementation which can be steered by test code and asserted on.
294
+ */
270
295
public static class ManualSubscriber <T > extends TestSubscriber <T > {
271
296
Receptacle <T > received ;
272
297
0 commit comments