Skip to content

Commit 0cf22ae

Browse files
authored
[Test] Fix assertion for number of message chunks (elastic#122571) (elastic#122717)
Depending on the position of the split and the size of the extra chunk, the test may send out one more chunk than the assertion expects. This PR ensures the assertoin is more accurate to count for this scenario. Resolves: elastic#122349
1 parent 5943592 commit 0cf22ae

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4WriteThrottlingHandlerTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public void testThrottleLargeCompositeMessage() {
109109
Netty4WriteThrottlingHandler.MAX_BYTES_PER_WRITE * fullSizeChunks + extraChunkSize
110110
);
111111
int splitOffset = randomIntBetween(0, messageBytes.length);
112+
int lastChunkSizeOfTheFirstSplit = splitOffset % Netty4WriteThrottlingHandler.MAX_BYTES_PER_WRITE;
112113
final BytesReference message = CompositeBytesReference.of(
113114
new BytesArray(messageBytes, 0, splitOffset),
114115
new BytesArray(messageBytes, splitOffset, messageBytes.length - splitOffset)
@@ -120,7 +121,9 @@ public void testThrottleLargeCompositeMessage() {
120121
assertFalse(promise.isDone());
121122
embeddedChannel.flush();
122123
assertTrue(promise.isDone());
123-
assertThat(seen, hasSize(oneOf(fullSizeChunks, fullSizeChunks + 1)));
124+
// If the extra chunk size is greater than the last chunk size for the first half of the split, it means we will need to send
125+
// (extraChunkSize - lastChunkSizeOfTheFirstSplit) bytes as the very last chunk of the entire message.
126+
assertThat(seen, hasSize(oneOf(fullSizeChunks, fullSizeChunks + 1 + (extraChunkSize > lastChunkSizeOfTheFirstSplit ? 1 : 0))));
124127
assertTrue(capturingHandler.didWriteAfterThrottled);
125128
assertBufferEquals(Unpooled.compositeBuffer().addComponents(true, seen), message);
126129
}

0 commit comments

Comments
 (0)