Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Ensure eth scheduler is stopped in tests #1324

Merged
merged 3 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.LockSupport;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -75,6 +76,11 @@ public void setup() {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
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;
Expand Down Expand Up @@ -110,6 +111,11 @@ public void setupTest() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;

Expand Down Expand Up @@ -60,6 +61,11 @@ public void setupTest() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -75,6 +76,11 @@ public void setup() {
new NoOpMetricsSystem());
}

@After
public void tearDown() {
ethProtocolManager.stop();
}

@Test
public void shouldDisconnectPeerIfWorldStateIsUnavailableForCommonAncestor() {
when(localWorldState.isWorldStateAvailable(localBlockchain.getChainHeadHeader().getStateRoot()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class IncrementerTest {
Expand All @@ -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(),
Expand All @@ -72,10 +77,18 @@ public void parallelDownloadPipelineCounterShouldIncrement() {
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -145,8 +149,6 @@ public void downloadWorldStateFromPeers_singleRequestWithMultiplePeers() {

@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))
Expand Down Expand Up @@ -177,9 +179,6 @@ public void downloadEmptyWorldState() {

@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());
Expand Down Expand Up @@ -274,9 +273,6 @@ public void handlesPartialResponsesFromNetwork() {

@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());
Expand Down Expand Up @@ -429,9 +425,6 @@ private void testCancellation(final boolean shouldCancelFuture) {

@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());
Expand Down Expand Up @@ -511,9 +504,6 @@ public void doesNotRequestKnownAccountTrieNodesFromNetwork() {

@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());
Expand Down Expand Up @@ -666,9 +656,6 @@ public void stalledDownloader() {

@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());
Expand Down Expand Up @@ -803,9 +790,6 @@ private void downloadAvailableWorldStateFromPeers(
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
Expand Down