Skip to content

Commit 3d8d843

Browse files
committed
Fix the build timeout when 'leak' profile is active
Motivation: AbstractByteBufTest.testInternalBuffer() uses writeByte() operations to populate the sample data. Usually, this isn't a problem, but it starts to take a lot of time when the resource leak detection level gets higher. In our CI machine, testInternalBuffer() takes more than 30 minutes, causing the build timeout when the 'leak' profile is active (paranoid level resource detection.) Modification: Populate the sample data using ThreadLocalRandom.nextBytes() instead of using millions of writeByte() operations. Result: Test runs much faster when leak detection level is high.
1 parent 0a8ff3b commit 3d8d843

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.netty.util.CharsetUtil;
1919
import io.netty.util.IllegalReferenceCountException;
20+
import io.netty.util.internal.ThreadLocalRandom;
2021
import org.junit.After;
2122
import org.junit.Assume;
2223
import org.junit.Before;
@@ -1742,15 +1743,15 @@ private void testInternalNioBuffer(int a) {
17421743
ByteBuffer buf = buffer.internalNioBuffer(0, 1);
17431744
assertEquals(1, buf.remaining());
17441745

1745-
for (int i = 0; i < a; i++) {
1746-
buffer.writeByte(i);
1747-
}
1746+
byte[] data = new byte[a];
1747+
ThreadLocalRandom.current().nextBytes(data);
1748+
buffer.writeBytes(data);
17481749

17491750
buf = buffer.internalNioBuffer(0, a);
17501751
assertEquals(a, buf.remaining());
17511752

17521753
for (int i = 0; i < a; i++) {
1753-
assertEquals((byte) i, buf.get());
1754+
assertEquals(data[i], buf.get());
17541755
}
17551756
assertFalse(buf.hasRemaining());
17561757
}

0 commit comments

Comments
 (0)