From 25b234acd21a7d5c828379d142c0499c27474459 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 27 Apr 2021 13:33:28 +0200 Subject: [PATCH] Make the BufferBulkAccessTest.writeBytesMustTransferDataAndUpdateOffsets test run faster Only run a sample of 10% of the possible combinations, and then run them in parallel. --- .../io/netty/buffer/api/BufferBulkAccessTest.java | 14 +++++++++++--- .../io/netty/buffer/api/BufferTestSupport.java | 10 ++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java b/src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java index d1374c3..739b73e 100644 --- a/src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java +++ b/src/test/java/io/netty/buffer/api/BufferBulkAccessTest.java @@ -19,10 +19,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import java.nio.ByteBuffer; +import java.util.Arrays; import static java.nio.ByteOrder.BIG_ENDIAN; import static java.nio.ByteOrder.LITTLE_ENDIAN; -import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; public class BufferBulkAccessTest extends BufferTestSupport { @@ -303,11 +303,16 @@ public class BufferBulkAccessTest extends BufferTestSupport { } } + private static final Memoize OTHER_FIXTURES = new Memoize( + () -> Arrays.stream(allocators()).filter(filterOfTheDay(10)).toArray(Fixture[]::new)); + @ParameterizedTest @MethodSource("allocators") public void writeBytesMustTransferDataAndUpdateOffsets(Fixture fixture) { try (BufferAllocator alloc1 = fixture.createAllocator()) { - for (Fixture otherFixture : allocators()) { + // Only test 10% of available combinations. Otherwise, this takes too long. + Fixture[] allocators = OTHER_FIXTURES.get(); + Arrays.stream(allocators).parallel().forEach(otherFixture -> { try (BufferAllocator alloc2 = otherFixture.createAllocator(); Buffer target = alloc1.allocate(37); Buffer source = alloc2.allocate(35)) { @@ -330,8 +335,11 @@ public class BufferBulkAccessTest extends BufferTestSupport { target.fill((byte) 0).reset().order(LITTLE_ENDIAN); source.fill((byte) 0).reset().order(BIG_ENDIAN); verifyWriteBytes(target, source); + } catch (Exception e) { + e.addSuppressed(new RuntimeException("other fixture was: " + otherFixture)); + throw e; } - } + }); } } diff --git a/src/test/java/io/netty/buffer/api/BufferTestSupport.java b/src/test/java/io/netty/buffer/api/BufferTestSupport.java index 7e56591..722e1b2 100644 --- a/src/test/java/io/netty/buffer/api/BufferTestSupport.java +++ b/src/test/java/io/netty/buffer/api/BufferTestSupport.java @@ -92,13 +92,15 @@ public abstract class BufferTestSupport { if ("nosample".equalsIgnoreCase(sampleSetting)) { return fixture -> true; } + // Filter out 95% of tests. + return filterOfTheDay(5); + } + + protected static Predicate filterOfTheDay(int percentage) { Instant today = Instant.now().truncatedTo(ChronoUnit.DAYS); // New seed every day. SplittableRandom rng = new SplittableRandom(today.hashCode()); AtomicInteger counter = new AtomicInteger(); - return fixture -> { - // Filter out 95% of tests. - return counter.getAndIncrement() < 1 || rng.nextInt(0, 100) < 5; - }; + return fixture -> counter.getAndIncrement() < 1 || rng.nextInt(0, 100) < percentage; } static Fixture[] allocators() {