Skip to content

improves tests & ensures thereare no leaks of bufs at execution #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ public void accept(RSocket rSocket, Throwable t) {

@Override
public void request(long n) {
this.main.request(n);
super.request(n);
this.main.request(n);
}

public void cancel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ public void clientSplits() {
clientMultiplexer
.asClientConnection()
.receive()
.doOnNext(f -> clientFrames.incrementAndGet())
.doOnNext(
f -> {
clientFrames.incrementAndGet();
f.release();
})
.subscribe();
clientMultiplexer
.asServerConnection()
.receive()
.doOnNext(f -> serverFrames.incrementAndGet())
.doOnNext(
f -> {
serverFrames.incrementAndGet();
f.release();
})
.subscribe();

source.addToReceivedBuffer(errorFrame(1).retain());
Expand Down Expand Up @@ -101,12 +109,20 @@ public void serverSplits() {
serverMultiplexer
.asClientConnection()
.receive()
.doOnNext(f -> clientFrames.incrementAndGet())
.doOnNext(
f -> {
clientFrames.incrementAndGet();
f.release();
})
.subscribe();
serverMultiplexer
.asServerConnection()
.receive()
.doOnNext(f -> serverFrames.incrementAndGet())
.doOnNext(
f -> {
serverFrames.incrementAndGet();
f.release();
})
.subscribe();

source.addToReceivedBuffer(errorFrame(1).retain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.ReferenceCounted;
import io.rsocket.FrameAssert;
import io.rsocket.Payload;
import io.rsocket.RSocket;
import io.rsocket.RaceTestConstants;
Expand Down Expand Up @@ -434,6 +435,8 @@ public void shouldBeAbleToResolveOriginalSource() {
assertSubscriber1.assertTerminated().assertValueCount(1);

Assertions.assertThat(assertSubscriber1.values()).isEqualTo(assertSubscriber.values());

rule.allocator.assertHasNoLeaks();
}

@Test
Expand All @@ -457,6 +460,13 @@ public void shouldDisposeOriginalSource() {
.assertErrorMessage("Disposed");

Assertions.assertThat(rule.socket.isDisposed()).isTrue();

FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

rule.allocator.assertHasNoLeaks();
}

@Test
Expand Down Expand Up @@ -494,6 +504,13 @@ public Mono<Void> onClose() {
onCloseSubscriber.assertTerminated().assertComplete();

Assertions.assertThat(rule.socket.isDisposed()).isTrue();

FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

rule.allocator.assertHasNoLeaks();
}

@Test
Expand All @@ -515,6 +532,13 @@ public void shouldResolveOnStartSource() {
assertSubscriber1.assertTerminated().assertComplete();

Assertions.assertThat(rule.socket.isDisposed()).isTrue();

FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

rule.allocator.assertHasNoLeaks();
}

@Test
Expand All @@ -536,6 +560,13 @@ public void shouldNotStartIfAlreadyDisposed() {
assertSubscriber1.assertTerminated().assertComplete();

Assertions.assertThat(rule.socket.isDisposed()).isTrue();

FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

rule.allocator.assertHasNoLeaks();
}

@Test
Expand All @@ -553,6 +584,11 @@ public void shouldBeRestartedIfSourceWasClosed() {

rule.socket.dispose();

FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

terminateSubscriber.assertNotTerminated();
Assertions.assertThat(rule.client.isDisposed()).isFalse();

Expand All @@ -576,6 +612,13 @@ public void shouldBeRestartedIfSourceWasClosed() {
Assertions.assertThat(rule.client.connect()).isFalse();

Assertions.assertThat(rule.socket.isDisposed()).isTrue();

FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

rule.allocator.assertHasNoLeaks();
}

@Test
Expand Down Expand Up @@ -603,6 +646,13 @@ public void shouldDisposeOriginalSourceIfRacing() {
.assertTerminated()
.assertError(CancellationException.class)
.assertErrorMessage("Disposed");

ByteBuf buf;
while ((buf = rule.connection.pollFrame()) != null) {
FrameAssert.assertThat(buf).hasStreamIdZero().hasData("Disposed").hasNoLeaks();
}

rule.allocator.assertHasNoLeaks();
}
}

Expand Down Expand Up @@ -632,8 +682,14 @@ public void shouldStartOriginalSourceOnceIfRacing() {
AssertSubscriber<Void> assertSubscriber1 = AssertSubscriber.create();

rule.client.onClose().subscribe(assertSubscriber1);
FrameAssert.assertThat(rule.connection.awaitFrame())
.hasStreamIdZero()
.hasData("Disposed")
.hasNoLeaks();

assertSubscriber1.assertTerminated().assertComplete();

rule.allocator.assertHasNoLeaks();
}
}

Expand Down
Loading