Skip to content

Commit

Permalink
randomize
Browse files Browse the repository at this point in the history
  • Loading branch information
ywangd committed Oct 18, 2024
1 parent d7a3be1 commit b4b94c4
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.bytes.ReleasableBytesReference;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.ClusterSettings;
Expand Down Expand Up @@ -72,6 +73,7 @@
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.transport.netty4.Netty4Utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.BlockingDeque;
Expand Down Expand Up @@ -177,11 +179,19 @@ public void testClientConnectionCloseMidStream() throws Exception {

assertFalse(handler.streamClosed);

handler.stream.next(); // read the first half of the request
handler.stream.next(); // attempt to read more data and it should notice channel being closed eventually
final List<Runnable> runnables = new ArrayList<>(
List.of(
// terminate client connection
ctx.clientChannel::close,
// read the first half of the request
handler.stream::next,
// attempt to read more data and it should notice channel being closed eventually
handler.stream::next
)
);
Randomness.shuffle(runnables);
runnables.forEach(Runnable::run);

// terminate connection and wait resources are released
ctx.clientChannel.close();
assertBusy(() -> {
assertNull(handler.stream.buf());
assertTrue(handler.streamClosed);
Expand Down

0 comments on commit b4b94c4

Please sign in to comment.