Ensure eth scheduler is stopped in tests (#1324)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Adrian Sutton 6 years ago committed by GitHub
parent 9c16da6ce8
commit 67290f4ef1
  1. 6
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java
  2. 6
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java
  3. 6
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java
  4. 6
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java
  5. 23
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/IncrementerTest.java
  6. 24
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderTest.java

@ -39,6 +39,7 @@ import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.LockSupport;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -75,6 +76,11 @@ public class FastSyncChainDownloaderTest {
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
}
@After
public void tearDown() {
ethProtocolManager.stop();
}
private ChainDownloader downloader(
final SynchronizerConfiguration syncConfig, final long pivotBlockNumber) {
return FastSyncChainDownloader.create(

@ -58,6 +58,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -110,6 +111,11 @@ public class FullSyncChainDownloaderTest {
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
}
@After
public void tearDown() {
ethProtocolManager.stop();
}
private ChainDownloader downloader(final SynchronizerConfiguration syncConfig) {
return FullSyncChainDownloader.create(
syncConfig, protocolSchedule, protocolContext, ethContext, syncState, metricsSystem);

@ -29,6 +29,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -60,6 +61,11 @@ public class FullSyncDownloaderTest {
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
}
@After
public void tearDown() {
ethProtocolManager.stop();
}
private FullSyncDownloader<Void> downloader(final SynchronizerConfiguration syncConfig) {
return new FullSyncDownloader<>(
syncConfig, protocolSchedule, protocolContext, ethContext, syncState, metricsSystem);

@ -36,6 +36,7 @@ import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -75,6 +76,11 @@ public class FullSyncTargetManagerTest {
new NoOpMetricsSystem());
}
@After
public void tearDown() {
ethProtocolManager.stop();
}
@Test
public void shouldDisconnectPeerIfWorldStateIsUnavailableForCommonAncestor() {
when(localWorldState.isWorldStateAvailable(localBlockchain.getChainHeadHeader().getStateRoot()))

@ -40,6 +40,8 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class IncrementerTest {
@ -50,20 +52,23 @@ public class IncrementerTest {
private SyncState syncState;
private MutableBlockchain localBlockchain;
private MetricsSystem metricsSystem;
private EthProtocolManager ethProtocolManager;
private Blockchain otherBlockchain;
private long targetBlock;
@Test
public void parallelDownloadPipelineCounterShouldIncrement() {
@Before
public void setUp() {
metricsConfiguration.setEnabled(true);
metricsSystem = PrometheusMetricsSystem.init(metricsConfiguration);
final BlockchainSetupUtil<Void> localBlockchainSetup = BlockchainSetupUtil.forTesting();
localBlockchain = spy(localBlockchainSetup.getBlockchain());
final BlockchainSetupUtil<Void> otherBlockchainSetup = BlockchainSetupUtil.forTesting();
final Blockchain otherBlockchain = otherBlockchainSetup.getBlockchain();
otherBlockchain = otherBlockchainSetup.getBlockchain();
protocolSchedule = localBlockchainSetup.getProtocolSchedule();
protocolContext = localBlockchainSetup.getProtocolContext();
final EthProtocolManager ethProtocolManager =
ethProtocolManager =
EthProtocolManagerTestUtil.create(
localBlockchain,
localBlockchainSetup.getWorldArchive(),
@ -72,10 +77,18 @@ public class IncrementerTest {
syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers());
otherBlockchainSetup.importFirstBlocks(15);
final long targetBlock = otherBlockchain.getChainHeadBlockNumber();
targetBlock = otherBlockchain.getChainHeadBlockNumber();
// Sanity check
assertThat(targetBlock).isGreaterThan(localBlockchain.getChainHeadBlockNumber());
}
@After
public void tearDown() {
ethProtocolManager.stop();
}
@Test
public void parallelDownloadPipelineCounterShouldIncrement() {
final RespondingEthPeer peer =
EthProtocolManagerTestUtil.createPeer(ethProtocolManager, otherBlockchain);
final RespondingEthPeer.Responder responder =

@ -107,10 +107,14 @@ public class WorldStateDownloaderTest {
.setNameFormat(WorldStateDownloaderTest.class.getSimpleName() + "-persistence-%d")
.build());
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
@After
public void tearDown() throws Exception {
persistenceThread.shutdownNow();
assertThat(persistenceThread.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
ethProtocolManager.stop();
}
@Test
@ -145,8 +149,6 @@ public class WorldStateDownloaderTest {
@Test
public void downloadEmptyWorldState() {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
final BlockHeader header =
dataGen
.block(BlockOptions.create().setStateRoot(EMPTY_TRIE_ROOT).setBlockNumber(10))
@ -177,9 +179,6 @@ public class WorldStateDownloaderTest {
@Test
public void downloadAlreadyAvailableWorldState() {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
// Setup existing state
final WorldStateStorage storage =
new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage());
@ -274,9 +273,6 @@ public class WorldStateDownloaderTest {
@Test
public void doesNotRequestKnownCodeFromNetwork() {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
// Setup "remote" state
final WorldStateStorage remoteStorage =
new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage());
@ -429,9 +425,6 @@ public class WorldStateDownloaderTest {
@Test
public void doesNotRequestKnownAccountTrieNodesFromNetwork() {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
// Setup "remote" state
final WorldStateStorage remoteStorage =
new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage());
@ -511,9 +504,6 @@ public class WorldStateDownloaderTest {
@Test
public void doesNotRequestKnownStorageTrieNodesFromNetwork() {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
// Setup "remote" state
final WorldStateStorage remoteStorage =
new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage());
@ -666,9 +656,6 @@ public class WorldStateDownloaderTest {
@Test
public void resumesFromNonEmptyQueue() {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
// Setup "remote" state
final WorldStateStorage remoteStorage =
new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage());
@ -803,9 +790,6 @@ public class WorldStateDownloaderTest {
final int hashesPerRequest,
final int maxOutstandingRequests,
final NetworkResponder networkResponder) {
final EthProtocolManager ethProtocolManager =
EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, new NoOpMetricsSystem()));
final int trailingPeerCount = 5;
// Setup "remote" state

Loading…
Cancel
Save