Skip to content

Commit 24dab10

Browse files
committed
improves tests
Signed-off-by: Oleh Dokuka <[email protected]> Signed-off-by: Oleh Dokuka <[email protected]>
1 parent 9c636f4 commit 24dab10

File tree

1 file changed

+46
-51
lines changed

1 file changed

+46
-51
lines changed

rsocket-core/src/test/java/io/rsocket/internal/UnboundedProcessorTest.java

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,28 @@
1616

1717
package io.rsocket.internal;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
19+
import java.time.Duration;
2020

2121
import io.netty.buffer.ByteBuf;
2222
import io.netty.buffer.ByteBufAllocator;
2323
import io.netty.buffer.Unpooled;
24-
import io.netty.buffer.UnpooledByteBufAllocator;
2524
import io.netty.util.CharsetUtil;
2625
import io.netty.util.ReferenceCountUtil;
2726
import io.rsocket.buffer.LeaksTrackingByteBufAllocator;
2827
import io.rsocket.internal.subscriber.AssertSubscriber;
29-
import java.time.Duration;
3028
import org.junit.jupiter.api.AfterAll;
3129
import org.junit.jupiter.api.BeforeAll;
3230
import org.junit.jupiter.api.Disabled;
33-
import org.junit.jupiter.api.DisplayName;
34-
import org.junit.jupiter.api.RepeatedTest;
35-
import org.junit.jupiter.api.Test;
36-
import org.junit.jupiter.api.Timeout;
3731
import org.junit.jupiter.params.ParameterizedTest;
3832
import org.junit.jupiter.params.provider.ValueSource;
3933
import reactor.core.Fuseable;
4034
import reactor.core.publisher.Hooks;
41-
import reactor.core.publisher.Operators;
4235
import reactor.core.scheduler.Schedulers;
4336
import reactor.test.StepVerifier;
4437
import reactor.test.util.RaceTestUtils;
4538

39+
import static org.assertj.core.api.Assertions.assertThat;
40+
4641
public class UnboundedProcessorTest {
4742

4843
@BeforeAll
@@ -138,7 +133,7 @@ public void ensureUnboundedProcessorDisposesQueueProperly(boolean withFusionEnab
138133
assertSubscriber.request(1);
139134
});
140135

141-
assertSubscriber.values().forEach(ReferenceCountUtil::safeRelease);
136+
assertSubscriber.values().forEach(ReferenceCountUtil::release);
142137

143138
allocator.assertHasNoLeaks();
144139
}
@@ -167,7 +162,6 @@ public void smokeTest1(boolean withFusionEnabled) {
167162
unboundedProcessor.subscribe(assertSubscriber);
168163

169164
RaceTestUtils.race(
170-
Schedulers.boundedElastic(),
171165
() -> {
172166
unboundedProcessor.onNext(buffer1);
173167
unboundedProcessor.onNextPrioritized(buffer2);
@@ -284,10 +278,11 @@ public void smokeTest3(boolean withFusionEnabled) {
284278
}
285279
}
286280

287-
@Test
288-
@DisplayName(
289-
"Ensures that racing between onNext | dispose | subscribe(cancelled) | terminal will not cause any issues and leaks")
290-
public void smokeTest31() {
281+
@ParameterizedTest(
282+
name =
283+
"Ensures that racing between onNext | dispose | subscribe(cancelled) | terminal will not cause any issues and leaks; mode[fusionEnabled={0}]")
284+
@ValueSource(booleans = {true, false})
285+
public void smokeTest31(boolean withFusionEnabled) {
291286
final LeaksTrackingByteBufAllocator allocator =
292287
LeaksTrackingByteBufAllocator.instrument(ByteBufAllocator.DEFAULT);
293288
final RuntimeException runtimeException = new RuntimeException("test");
@@ -300,7 +295,8 @@ public void smokeTest31() {
300295
final ByteBuf buffer4 = allocator.buffer(4);
301296

302297
final AssertSubscriber<ByteBuf> assertSubscriber =
303-
new AssertSubscriber<ByteBuf>(0).requestedFusionMode(Fuseable.ANY);
298+
new AssertSubscriber<ByteBuf>(0)
299+
.requestedFusionMode(withFusionEnabled ? Fuseable.ANY : Fuseable.NONE);
304300

305301
RaceTestUtils.race(
306302
Schedulers.boundedElastic(),
@@ -329,44 +325,43 @@ public void smokeTest31() {
329325
}
330326
}
331327

332-
@RepeatedTest(
328+
@ParameterizedTest(
333329
name =
334-
"Ensures that racing between onNext + dispose | downstream async drain should not cause any issues and leaks",
335-
value = 10000)
336-
@Timeout(60)
337-
public void ensuresAsyncFusionAndDisposureHasNoDeadlock() {
330+
"Ensures that racing between onNext + dispose | downstream async drain should not cause any issues and leaks; mode[fusionEnabled={0}]")
331+
@ValueSource(booleans = {true, false})
332+
public void ensuresAsyncFusionAndDisposureHasNoDeadlock(boolean withFusionEnabled) {
338333
final LeaksTrackingByteBufAllocator allocator =
339-
LeaksTrackingByteBufAllocator.instrument(UnpooledByteBufAllocator.DEFAULT);
340-
final UnboundedProcessor<ByteBuf> unboundedProcessor = new UnboundedProcessor<>();
341-
342-
final ByteBuf buffer1 = allocator.buffer(1);
343-
final ByteBuf buffer2 = allocator.buffer(2);
344-
final ByteBuf buffer3 = allocator.buffer(3);
345-
final ByteBuf buffer4 = allocator.buffer(4);
346-
final ByteBuf buffer5 = allocator.buffer(5);
347-
final ByteBuf buffer6 = allocator.buffer(6);
348-
349-
final AssertSubscriber<ByteBuf> assertSubscriber =
350-
new AssertSubscriber<>(Operators.enableOnDiscard(null, ReferenceCountUtil::safeRelease));
351-
352-
unboundedProcessor.subscribe(assertSubscriber);
353-
354-
RaceTestUtils.race(
355-
() -> {
356-
unboundedProcessor.onNext(buffer1);
357-
unboundedProcessor.onNext(buffer2);
358-
unboundedProcessor.onNext(buffer3);
359-
unboundedProcessor.onNext(buffer4);
360-
unboundedProcessor.onNext(buffer5);
361-
unboundedProcessor.onNext(buffer6);
362-
unboundedProcessor.dispose();
363-
},
364-
unboundedProcessor::dispose);
365-
366-
assertSubscriber
367-
.await(Duration.ofSeconds(50))
368-
.values()
369-
.forEach(ReferenceCountUtil::safeRelease);
334+
LeaksTrackingByteBufAllocator.instrument(ByteBufAllocator.DEFAULT);
335+
336+
for (int i = 0; i < 10000; i++) {
337+
final UnboundedProcessor<ByteBuf> unboundedProcessor = new UnboundedProcessor<>();
338+
final ByteBuf buffer1 = allocator.buffer(1);
339+
final ByteBuf buffer2 = allocator.buffer(2);
340+
final ByteBuf buffer3 = allocator.buffer(3);
341+
final ByteBuf buffer4 = allocator.buffer(4);
342+
final ByteBuf buffer5 = allocator.buffer(5);
343+
final ByteBuf buffer6 = allocator.buffer(6);
344+
345+
final AssertSubscriber<ByteBuf> assertSubscriber =
346+
new AssertSubscriber<ByteBuf>()
347+
.requestedFusionMode(withFusionEnabled ? Fuseable.ANY : Fuseable.NONE);
348+
349+
unboundedProcessor.subscribe(assertSubscriber);
350+
351+
RaceTestUtils.race(
352+
() -> {
353+
unboundedProcessor.onNext(buffer1);
354+
unboundedProcessor.onNext(buffer2);
355+
unboundedProcessor.onNext(buffer3);
356+
unboundedProcessor.onNext(buffer4);
357+
unboundedProcessor.onNext(buffer5);
358+
unboundedProcessor.onNext(buffer6);
359+
unboundedProcessor.dispose();
360+
},
361+
unboundedProcessor::dispose);
362+
363+
assertSubscriber.await(Duration.ofSeconds(50)).values().forEach(ReferenceCountUtil::release);
364+
}
370365

371366
allocator.assertHasNoLeaks();
372367
}

0 commit comments

Comments
 (0)