Skip to content

Commit fd60e0b

Browse files
committed
=tck #279 improve completion latch error message
1 parent 4264e1d commit fd60e0b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import java.util.Random;
25+
import java.util.concurrent.atomic.AtomicInteger;
2526
import java.util.concurrent.atomic.AtomicReference;
2627

2728
import static org.testng.Assert.assertEquals;
@@ -246,9 +247,9 @@ public Void apply(final Integer runNumber) throws Throwable {
246247
public void run(Publisher<T> pub) throws Throwable {
247248
final Latch completionLatch = new Latch(env);
248249

250+
final AtomicInteger gotElements = new AtomicInteger(0);
249251
pub.subscribe(new Subscriber<T>() {
250252
private Subscription subs;
251-
private long gotElements = 0;
252253

253254
private ConcurrentAccessBarrier concurrentAccessBarrier = new ConcurrentAccessBarrier();
254255

@@ -302,8 +303,7 @@ public void onNext(T ignore) {
302303
final String signal = String.format("onNext(%s)", ignore);
303304
concurrentAccessBarrier.enterSignal(signal);
304305

305-
gotElements += 1;
306-
if (gotElements <= elements) // requesting one more than we know are in the stream (some Publishers need this)
306+
if (gotElements.incrementAndGet() <= elements) // requesting one more than we know are in the stream (some Publishers need this)
307307
subs.request(1);
308308

309309
concurrentAccessBarrier.leaveSignal(signal);
@@ -331,7 +331,10 @@ public void onComplete() {
331331
}
332332
});
333333

334-
completionLatch.expectClose(elements * env.defaultTimeoutMillis(), "Expected 10 elements to be drained");
334+
completionLatch.expectClose(
335+
elements * env.defaultTimeoutMillis(),
336+
String.format("Failed in iteration %d of %d. Expected completion signal after signalling %d elements (signalled %d), yet did not receive it",
337+
runNumber, iterations, elements, gotElements.get()));
335338
}
336339
});
337340
return null;

0 commit comments

Comments
 (0)