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,44 @@ 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
+ try {
231
+ Thread .sleep (defaultTimeoutMillis ());
232
+ verifyNoAsyncErrorsNoDelay ();
233
+ } catch (InterruptedException e ) {
234
+ throw new RuntimeException (e );
235
+ }
236
+ }
237
+
238
+ /**
239
+ * This version of {@code verifyNoAsyncErrors} should be used when errors still could be signalled
240
+ * asynchronously during {@link TestEnvironment#defaultTimeoutMillis()} time.
241
+ * <p></p>
242
+ * It will immediatly check if any async errors were signaled (using {@link TestEnvironment#flop(String)},
243
+ * and if no errors encountered wait for another default timeout as the errors may yet be signalled.
244
+ * The initial check is performed in order to fail-fast in case of an already failed test.
245
+ */
226
246
public void verifyNoAsyncErrors (long delay ) {
227
247
try {
248
+ verifyNoAsyncErrorsNoDelay ();
249
+
228
250
Thread .sleep (delay );
229
- verifyNoAsyncErrors ();
251
+ verifyNoAsyncErrorsNoDelay ();
230
252
} catch (InterruptedException e ) {
231
253
throw new RuntimeException (e );
232
254
}
233
255
}
234
256
235
- public void verifyNoAsyncErrors () {
257
+ /**
258
+ * Verifies that no asynchronous errors were signalled pior to calling this method (by calling {@code flop()}).
259
+ * This version of verifyNoAsyncError <b>does not wait before checking for asynchronous errors</b>, and is to be used
260
+ * for example in tight loops etc.
261
+ */
262
+ public void verifyNoAsyncErrorsNoDelay () {
236
263
for (Throwable e : asyncErrors ) {
237
264
if (e instanceof AssertionError ) {
238
265
throw (AssertionError ) e ;
@@ -267,6 +294,9 @@ public Optional<StackTraceElement> findCallerMethodInStackTrace(String method) {
267
294
268
295
// ---- classes ----
269
296
297
+ /**
298
+ * {@link Subscriber} implementation which can be steered by test code and asserted on.
299
+ */
270
300
public static class ManualSubscriber <T > extends TestSubscriber <T > {
271
301
Receptacle <T > received ;
272
302
0 commit comments