Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Tune running of tests to reduce overhead (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed Aug 2, 2023
1 parent 71e88b8 commit 15721be
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ protected void performClose() {
if (nc != null)
closeQuietly(nc, nc.socketReconnector(), nc.networkStatsListener());
closeQuietly(tcpHandler, sc);
IOTools.unmonitor(inBBB);
IOTools.unmonitor(outBBB);
}

boolean flushedOut(boolean flushed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ void setUp() throws IOException {
TCPRegistry.createServerSocketChannelFor(hostPort);
uri = TCPRegistry.acquireServerSocketChannel(hostPort).getLocalAddress().toString();
}
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@Test
@Timeout(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ void setUp() throws IOException {
ignoreException("core-event-loop thread has blocked for");
}

@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@Test
void onConnectAndOnDisconnectAreCalledOnce_OnOrderlyConnectionAndDisconnection() {
try (TestClusterContext acceptorCtx = forHosts(acceptorHost, initiatorHost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public void assertReferencesReleased() {
AbstractReferenceCounted.assertReferencesReleased();
}

@BeforeEach
void threadDump() {
// @BeforeEach add to tests that need it
protected void threadDump() {
threadDump = new ThreadDump();
}

public void checkThreadDump() {
threadDump.assertNoNewThreads();
if (threadDump != null)
threadDump.assertNoNewThreads();
}

@BeforeEach
Expand Down Expand Up @@ -86,11 +87,10 @@ void afterChecks() {
CleaningThread.performCleanup(Thread.currentThread());

// find any discarded resources.
System.gc();
AbstractCloseable.waitForCloseablesToClose(100);

TCPRegistry.reset();

AbstractCloseable.waitForCloseablesToClose(100);

assertReferencesReleased();
checkThreadDump();
checkExceptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ void setUp() {
remoteConnector = new RemoteConnector<>(this::createTcpEventHandler);
}

@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@Test
@Timeout(3)
void remoteConnectorLooksUpAddressOnEachIteration() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,29 @@ void testBuffersReleasedWhenSocketChannelClosed() throws IOException {
void performIdleWorkIsOnlyCalledWhenHandlerIsBusyOrOneHundredIterations() throws IOException, InvalidEventHandlerException {
NetworkContext nc = new VanillaNetworkContext();
nc.socketChannel(TCPRegistry.createSocketChannel(hostPort));
BusyTcpEventHandler tcpEventHandler = new BusyTcpEventHandler(nc);
final BusyTcpHandler tcpHandler = new BusyTcpHandler();
tcpEventHandler.tcpHandler(tcpHandler);

// not called when busy
tcpEventHandler.busy = true;
tcpEventHandler.action();
assertEquals(0, tcpHandler.performedIdleWorkCount.get());

// called when not busy
tcpEventHandler.busy = false;
tcpEventHandler.action();
assertEquals(1, tcpHandler.performedIdleWorkCount.get());

// called when not called for 101 iterations
tcpEventHandler.busy = true;
for (int i = 0; i < 101; i++) {
try (BusyTcpEventHandler tcpEventHandler = new BusyTcpEventHandler(nc)) {
final BusyTcpHandler tcpHandler = new BusyTcpHandler();
tcpEventHandler.tcpHandler(tcpHandler);

// not called when busy
tcpEventHandler.busy = true;
tcpEventHandler.action();
assertEquals(0, tcpHandler.performedIdleWorkCount.get());

// called when not busy
tcpEventHandler.busy = false;
tcpEventHandler.action();
assertEquals(1, tcpHandler.performedIdleWorkCount.get());

// called when not called for 101 iterations
tcpEventHandler.busy = true;
for (int i = 0; i < 101; i++) {
tcpEventHandler.action();
}
assertEquals(1, tcpHandler.performedIdleWorkCount.get());
tcpEventHandler.action();
assertEquals(2, tcpHandler.performedIdleWorkCount.get());
}
assertEquals(1, tcpHandler.performedIdleWorkCount.get());
tcpEventHandler.action();
assertEquals(2, tcpHandler.performedIdleWorkCount.get());
tcpEventHandler.close();
}

public TcpEventHandler createTcpEventHandler() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ void before() {
REGISTRY.set(null);
}

@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@AfterEach
public void after() {
System.clearProperty("TcpEventHandler.tcpBufferSize");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.openhft.chronicle.threads.EventGroupBuilder;
import net.openhft.chronicle.wire.WireType;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -38,6 +39,11 @@
import static org.mockito.Mockito.verify;

class ClusterAcceptorEventHandlerTest extends NetworkTestCommon {
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@Test
void willPopulateNetworkStatsListenerWhenNetworkStatsListenerFactorySpecified() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void setUp() throws IOException {
executorService.submit(hostOneProxy);
executorService.submit(hostTwoProxy);
}
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@AfterEach
void tearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.util.ThrowingFunction;
import net.openhft.chronicle.network.NetworkTestCommon;
import net.openhft.chronicle.network.TcpEventHandler;
import net.openhft.chronicle.threads.Pauser;
import net.openhft.chronicle.threads.TimingPauser;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -34,7 +36,12 @@

import static org.junit.jupiter.api.Assertions.*;

class ClusterContextTest {
class ClusterContextTest extends NetworkTestCommon {
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@Test
void testStatesAreStillInTheCorrectOrder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
package net.openhft.chronicle.network.cluster.handlers;

import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.network.NetworkTestCommon;
import net.openhft.chronicle.wire.BinaryWire;
import net.openhft.chronicle.wire.Wire;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

class HeartbeatHandlerTest {
class HeartbeatHandlerTest extends NetworkTestCommon {

public static final long CID = 1234L;
public static final int VALID_HEARTBEAT_TIMEOUT_MS = 1000;
Expand Down Expand Up @@ -82,7 +83,7 @@ void intervalGreaterThanTimeoutThrowsIllegalStateExceptionConstructor() {
}

private void createByDeserialization(long heartbeatTimeoutMs, long heartbeatIntervalMs) {
Wire wire = new BinaryWire(Bytes.elasticByteBuffer());
Wire wire = new BinaryWire(Bytes.allocateElasticOnHeap());
wire.write("heartbeatTimeoutMs").int64(heartbeatTimeoutMs);
wire.write("heartbeatIntervalMs").int64(heartbeatIntervalMs);
new HeartbeatHandler<>(wire);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.network.NetworkTestCommon;
import net.openhft.chronicle.network.TCPRegistry;
import net.openhft.chronicle.network.tcp.ChronicleSocketChannel;
import net.openhft.chronicle.network.util.TestServer;
import net.openhft.chronicle.wire.Marshallable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

Expand All @@ -34,7 +36,12 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

class FatalFailureConnectionStrategyTest {
class FatalFailureConnectionStrategyTest extends NetworkTestCommon {
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

/**
* Checks that {@link FatalFailureConnectionStrategy} can be used in YAML config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package net.openhft.chronicle.network.internal;

import net.openhft.chronicle.core.util.ThrowingRunnable;
import net.openhft.chronicle.network.NetworkTestCommon;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -27,7 +28,7 @@

import static org.junit.jupiter.api.Assertions.*;

class AddressCacheTest {
class AddressCacheTest extends NetworkTestCommon {

private static final String NETWORK_ADDRESS_CACHE_TTL = "networkaddress.cache.ttl";
private static final String DEFAULT_NETWORK_ADDRESS_CACHE_TTL = "-1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.openhft.chronicle.network.tcp.ChronicleSocketChannel;
import net.openhft.chronicle.network.tcp.ChronicleSocketChannelFactory;
import net.openhft.chronicle.threads.Threads;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -39,6 +40,11 @@
import static org.junit.jupiter.api.Assertions.*;

class SocketExceptionUtilTest extends NetworkTestCommon {
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

/**
* Original means of detection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

class FileBasedHostnamePortLookupTableTest extends NetworkTestCommon {

public static final String TEST_TABLE_FILENAME = "FileBasedHostnamePortLookupTableTest";
public static final String TEST_TABLE_FILENAME = OS.getTarget()+"/FileBasedHostnamePortLookupTableTest";
private FileBasedHostnamePortLookupTable lookupTable;

@BeforeEach
Expand All @@ -49,6 +49,11 @@ void setUp() {
IOTools.deleteDirWithFilesOrThrow(TEST_TABLE_FILENAME);
lookupTable = new FileBasedHostnamePortLookupTable(TEST_TABLE_FILENAME);
}
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@AfterEach
public void closeLookupTable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void setUp() {
System.setProperty("jdk.tls.server.protocols", "TLSv1.2");
}

@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@AfterEach
void teardown() {
System.clearProperty("jdk.tls.server.protocols");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public final class NonClusteredSslIntegrationTest extends NetworkTestCommon {
private final CountingTcpHandler clientInitiator = new CountingTcpHandler("client-initiator");
private final CountingTcpHandler serverInitiator = new CountingTcpHandler("server-initiator");
private Mode mode;
@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

public static List<Object[]> params() {
final List<Object[]> params = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void setUp() throws IOException {
TCPRegistry.createServerSocketChannelFor("client", "server");
}

@Override
@BeforeEach
protected void threadDump() {
super.threadDump();
}

@AfterEach
void teardown() {
System.clearProperty("jdk.tls.server.protocols");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.openhft.chronicle.network.tcp;

import net.openhft.chronicle.network.NetworkTestCommon;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -11,7 +12,7 @@

import static org.junit.jupiter.api.Assertions.assertThrows;

class FastJ8SocketChannelTest {
class FastJ8SocketChannelTest extends NetworkTestCommon {

@Test
void closedChannelExceptionIsThrownWhenAttemptIsMadeToReadFromClosedChannel() throws IOException {
Expand All @@ -22,6 +23,7 @@ void closedChannelExceptionIsThrownWhenAttemptIsMadeToReadFromClosedChannel() th
final FastJ8SocketChannel fastJ8SocketChannel = new FastJ8SocketChannel(remote);
remote.close();
assertThrows(ClosedChannelException.class, () -> fastJ8SocketChannel.read(ByteBuffer.allocateDirect(100)));
fastJ8SocketChannel.close();
}
}
}
Expand All @@ -35,6 +37,7 @@ void closedChannelExceptionIsThrownWhenAttemptIsMadeToWriteToClosedChannel() thr
final FastJ8SocketChannel fastJ8SocketChannel = new FastJ8SocketChannel(remote);
remote.close();
assertThrows(ClosedChannelException.class, () -> fastJ8SocketChannel.write(ByteBuffer.allocateDirect(100)));
fastJ8SocketChannel.close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BufferSizeTest extends NetworkTestCommon {
private ThreadDump threadDump;

@BeforeEach
void threadDump() {
protected void threadDump() {
threadDump = new ThreadDump();
}

Expand Down

0 comments on commit 15721be

Please sign in to comment.