Skip to content

Commit c3376e7

Browse files
committed
+tck reactive-streams#308 allow configuring "no events during N time" separately
1 parent f683f4d commit c3376e7

File tree

6 files changed

+69
-21
lines changed

6 files changed

+69
-21
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
global:
1212
- TERM=dumb
1313
- DEFAULT_TIMEOUT_MILLIS=300
14+
- DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS=200
1415
- PUBLISHER_REFERENCE_GC_TIMEOUT_MILLIS=300
1516
addons:
1617
# Fix OpenJDK build. Issue: https://github.com/travis-ci/travis-ci/issues/5227 & https://docs.travis-ci.com/user/hostname

Diff for: tck/README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,32 @@ within the TCK which await for something to happen. The other timeout is `publis
209209
[Rule 3.13](https://github.com/reactive-streams/reactive-streams-jvm#3.13) which defines that `Subscriber` references MUST be dropped
210210
by the Publisher.
211211

212+
Note that the TCK differenciates between timeouts for "waiting for a signal" (``defaultTimeoutMillis``),
213+
and "asserting no signals happen during a given amount of time" (``envDefaultNoSignalsTimeoutMillis``).
214+
While the latter defaults to the prior, it may be useful to tweak them independently when running on continious
215+
integration servers (for example, keeping the no-signals timeout significantly lower).
216+
212217
In order to configure these timeouts (for example when running on a slow continious integtation machine), you can either:
213218

214219
**Use env variables** to set these timeouts, in which case the you can do:
215220

216221
```bash
217-
export DEFAULT_TIMEOUT_MILLIS=300
218-
export PUBLISHER_REFERENCE_GC_TIMEOUT_MILLIS=500
222+
export DEFAULT_TIMEOUT_MILLIS=100
223+
export DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS=100
224+
export PUBLISHER_REFERENCE_GC_TIMEOUT_MILLIS=300
219225
```
220226

221227
Or **define the timeouts explicitly in code**:
222228

223229
```java
224230
public class RangePublisherTest extends PublisherVerification<Integer> {
225231

226-
public static final long DEFAULT_TIMEOUT_MILLIS = 300L;
232+
public static final long DEFAULT_TIMEOUT_MILLIS = 100L;
233+
public static final long DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS = DEFAULT_TIMEOUT_MILLIS;
227234
public static final long PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS = 500L;
228235

229236
public RangePublisherTest() {
230-
super(new TestEnvironment(DEFAULT_TIMEOUT_MILLIS), PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS);
237+
super(new TestEnvironment(DEFAULT_TIMEOUT_MILLIS, DEFAULT_TIMEOUT_MILLIS), PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS);
231238
}
232239

233240
// ...

Diff for: tck/src/main/java/org/reactivestreams/tck/PublisherVerification.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static long envPublisherReferenceGCTimeoutMillis() {
7979
if (envMillis == null) return DEFAULT_PUBLISHER_REFERENCE_GC_TIMEOUT_MILLIS;
8080
else try {
8181
return Long.parseLong(envMillis);
82-
} catch(NumberFormatException ex) {
82+
} catch (NumberFormatException ex) {
8383
throw new IllegalArgumentException(String.format("Unable to parse %s env value [%s] as long!", PUBLISHER_REFERENCE_GC_TIMEOUT_MILLIS_ENV, envMillis), ex);
8484
}
8585
}
@@ -368,7 +368,7 @@ public void onError(Throwable cause) {
368368
onSubscribeLatch.expectClose("Should have received onSubscribe");
369369
onErrorlatch.expectClose(String.format("Error-state Publisher %s did not call `onError` on new Subscriber", pub));
370370

371-
env.verifyNoAsyncErrors(env.defaultTimeoutMillis());
371+
env.verifyNoAsyncErrors();
372372
}
373373
});
374374
} catch (SkipException se) {
@@ -699,8 +699,7 @@ public void onNext(T element) {
699699

700700
env.subscribe(pub, sub);
701701

702-
long delay = env.defaultTimeoutMillis();
703-
env.verifyNoAsyncErrors(delay);
702+
env.verifyNoAsyncErrors();
704703
}
705704
});
706705
}
@@ -1060,7 +1059,7 @@ public void onNext(T element) {
10601059

10611060
// no onError should be signalled
10621061
try {
1063-
env.verifyNoAsyncErrors(env.defaultTimeoutMillis());
1062+
env.verifyNoAsyncErrors();
10641063
} finally {
10651064
sub.cancel();
10661065
}

Diff for: tck/src/main/java/org/reactivestreams/tck/SubscriberWhiteboxVerification.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ public void expectError(Throwable expected, long timeoutMillis) throws Interrupt
711711
}
712712

713713
public void expectNone() throws InterruptedException {
714-
expectNone(env.defaultTimeoutMillis());
714+
expectNone(env.defaultNoSignalsTimeoutMillis());
715715
}
716716

717717
public void expectNone(long withinMillis) throws InterruptedException {

Diff for: tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java

+50-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public class TestEnvironment {
2222
private static final String DEFAULT_TIMEOUT_MILLIS_ENV = "DEFAULT_TIMEOUT_MILLIS";
2323
private static final long DEFAULT_TIMEOUT_MILLIS = 100;
2424

25+
private static final String DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS_ENV = "DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS";
26+
2527
private final long defaultTimeoutMillis;
28+
private final long defaultNoSignalsTimeoutMillis;
2629
private final boolean printlnDebug;
2730

2831
private CopyOnWriteArrayList<Throwable> asyncErrors = new CopyOnWriteArrayList<Throwable>();
@@ -32,16 +35,29 @@ public class TestEnvironment {
3235
* interactions. Longer timeout does not invalidate the correctness of
3336
* the implementation, but can in some cases result in longer time to
3437
* run the tests.
35-
*
3638
* @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
3740
* @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.
3941
*/
40-
public TestEnvironment(long defaultTimeoutMillis, boolean printlnDebug) {
42+
public TestEnvironment(long defaultTimeoutMillis, long defaultNoSignalsTimeoutMillis, boolean printlnDebug) {
4143
this.defaultTimeoutMillis = defaultTimeoutMillis;
44+
this.defaultNoSignalsTimeoutMillis = defaultNoSignalsTimeoutMillis;
4245
this.printlnDebug = printlnDebug;
4346
}
4447

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+
4561
/**
4662
* Tests must specify the timeout for expected outcome of asynchronous
4763
* interactions. Longer timeout does not invalidate the correctness of
@@ -51,7 +67,7 @@ public TestEnvironment(long defaultTimeoutMillis, boolean printlnDebug) {
5167
* @param defaultTimeoutMillis default timeout to be used in all expect* methods
5268
*/
5369
public TestEnvironment(long defaultTimeoutMillis) {
54-
this(defaultTimeoutMillis, false);
70+
this(defaultTimeoutMillis, defaultTimeoutMillis, false);
5571
}
5672

5773
/**
@@ -67,7 +83,7 @@ public TestEnvironment(long defaultTimeoutMillis) {
6783
* often helpful to pinpoint simple race conditions etc.
6884
*/
6985
public TestEnvironment(boolean printlnDebug) {
70-
this(envDefaultTimeoutMillis(), printlnDebug);
86+
this(envDefaultTimeoutMillis(), envDefaultNoSignalsTimeoutMillis(), printlnDebug);
7187
}
7288

7389
/**
@@ -80,13 +96,22 @@ public TestEnvironment(boolean printlnDebug) {
8096
* or the default value ({@link TestEnvironment#DEFAULT_TIMEOUT_MILLIS}) will be used.
8197
*/
8298
public TestEnvironment() {
83-
this(envDefaultTimeoutMillis());
99+
this(envDefaultTimeoutMillis(), envDefaultNoSignalsTimeoutMillis());
84100
}
85101

102+
/** This timeout is used when waiting for a signal to arrive. */
86103
public long defaultTimeoutMillis() {
87104
return defaultTimeoutMillis;
88105
}
89106

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+
90115
/**
91116
* Tries to parse the env variable {@code DEFAULT_TIMEOUT_MILLIS} as long and returns the value if present OR its default value.
92117
*
@@ -97,11 +122,26 @@ public static long envDefaultTimeoutMillis() {
97122
if (envMillis == null) return DEFAULT_TIMEOUT_MILLIS;
98123
else try {
99124
return Long.parseLong(envMillis);
100-
} catch(NumberFormatException ex) {
125+
} catch (NumberFormatException ex) {
101126
throw new IllegalArgumentException(String.format("Unable to parse %s env value [%s] as long!", DEFAULT_TIMEOUT_MILLIS_ENV, envMillis), ex);
102127
}
103128
}
104129

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+
105145
/**
106146
* To flop means to "fail asynchronously", either by onErroring or by failing some TCK check triggered asynchronously.
107147
* 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() {
227267
* were signalled pior to, or during that time (by calling {@code flop()}).
228268
*/
229269
public void verifyNoAsyncErrors() {
230-
verifyNoAsyncErrors(defaultTimeoutMillis());
270+
verifyNoAsyncErrors(defaultNoSignalsTimeoutMillis());
231271
}
232272

233273
/**
@@ -485,11 +525,11 @@ public <E extends Throwable> E expectError(Class<E> expected, long timeoutMillis
485525
}
486526

487527
public void expectNone() throws InterruptedException {
488-
expectNone(env.defaultTimeoutMillis());
528+
expectNone(env.defaultNoSignalsTimeoutMillis());
489529
}
490530

491531
public void expectNone(String errMsgPrefix) throws InterruptedException {
492-
expectNone(env.defaultTimeoutMillis(), errMsgPrefix);
532+
expectNone(env.defaultNoSignalsTimeoutMillis(), errMsgPrefix);
493533
}
494534

495535
public void expectNone(long withinMillis) throws InterruptedException {

Diff for: tck/src/test/java/org/reactivestreams/tck/IdentityProcessorVerificationTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
public class IdentityProcessorVerificationTest extends TCKVerificationSupport {
2020

2121
static final long DEFAULT_TIMEOUT_MILLIS = TestEnvironment.envDefaultTimeoutMillis();
22+
static final long DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS = TestEnvironment.envDefaultNoSignalsTimeoutMillis();
2223

2324
private ExecutorService ex;
2425
@BeforeClass void before() { ex = Executors.newFixedThreadPool(4); }
@@ -155,7 +156,7 @@ static class NoopProcessor implements Processor<Integer, Integer> {
155156
}
156157

157158
private TestEnvironment newTestEnvironment() {
158-
return new TestEnvironment(DEFAULT_TIMEOUT_MILLIS);
159+
return new TestEnvironment(DEFAULT_TIMEOUT_MILLIS, DEFAULT_NO_SIGNALS_TIMEOUT_MILLIS);
159160
}
160161

161162

0 commit comments

Comments
 (0)