From f33736df56c5a9c3359ce16285ebe2d281adb394 Mon Sep 17 00:00:00 2001 From: Ferenc Szabo Date: Tue, 19 Feb 2019 15:14:07 +0100 Subject: [PATCH] swarm: move race/norace helpers from stream to testutil As we will need to use the flag in other packages, too. --- swarm/network/stream/snapshot_sync_test.go | 6 ++---- swarm/network/stream/syncer_test.go | 4 ++-- .../stream/norace_test.go => testutil/norace.go} | 12 +++++++----- .../stream/race_test.go => testutil/race.go} | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) rename swarm/{network/stream/norace_test.go => testutil/norace.go} (67%) rename swarm/{network/stream/race_test.go => testutil/race.go} (83%) diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index b45d0aed50..dc44d377ad 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -42,8 +42,6 @@ import ( "github.com/ethereum/go-ethereum/swarm/testutil" ) -const MaxTimeout = 600 - type synctestConfig struct { addrs [][]byte hashes []storage.Address @@ -93,7 +91,7 @@ func TestSyncingViaGlobalSync(t *testing.T) { if *longrunning { chnkCnt = []int{1, 8, 32, 256, 1024} nodeCnt = []int{16, 32, 64, 128, 256} - } else if raceTest { + } else if testutil.RaceEnabled { // TestSyncingViaGlobalSync allocates a lot of memory // with race detector. By reducing the number of chunks // and nodes, memory consumption is lower and data races @@ -125,7 +123,7 @@ var simServiceMap = map[string]simulation.ServiceFunc{ var dir string var store *state.DBStore - if raceTest { + if testutil.RaceEnabled { // Use on-disk DBStore to reduce memory consumption in race tests. dir, err = ioutil.TempDir("", "swarm-stream-") if err != nil { diff --git a/swarm/network/stream/syncer_test.go b/swarm/network/stream/syncer_test.go index be0752a9d0..df30083817 100644 --- a/swarm/network/stream/syncer_test.go +++ b/swarm/network/stream/syncer_test.go @@ -48,7 +48,7 @@ func TestSyncerSimulation(t *testing.T) { // race detector. Allow it to finish successfully by // reducing its scope, and still check for data races // with the smallest number of nodes. - if !raceTest { + if !testutil.RaceEnabled { testSyncBetweenNodes(t, 4, dataChunkCount, true, 1) testSyncBetweenNodes(t, 8, dataChunkCount, true, 1) testSyncBetweenNodes(t, 16, dataChunkCount, true, 1) @@ -88,7 +88,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, chunkCount int, skipCheck bool, p var dir string var store *state.DBStore - if raceTest { + if testutil.RaceEnabled { // Use on-disk DBStore to reduce memory consumption in race tests. dir, err = ioutil.TempDir("", "swarm-stream-") if err != nil { diff --git a/swarm/network/stream/norace_test.go b/swarm/testutil/norace.go similarity index 67% rename from swarm/network/stream/norace_test.go rename to swarm/testutil/norace.go index b324f6939c..bc652184bb 100644 --- a/swarm/network/stream/norace_test.go +++ b/swarm/testutil/norace.go @@ -16,9 +16,11 @@ // +build !race -package stream +package testutil -// Provide a flag to reduce the scope of tests when running them -// with race detector. Some of the tests are doing a lot of allocations -// on the heap, and race detector uses much more memory to track them. -const raceTest = false +// RaceEnabled is true when -race flag is provided to the go tool. This const +// might be used in tests to skip some cases as the race detector may increase +// memory usage 5-10x and execution time by 2-20x. That might causes problems +// on Travis. Please, use this flag sparingly and keep your unit tests +// as light on resources as possible. +const RaceEnabled = false diff --git a/swarm/network/stream/race_test.go b/swarm/testutil/race.go similarity index 83% rename from swarm/network/stream/race_test.go rename to swarm/testutil/race.go index 8aed3542bf..08aa279ae3 100644 --- a/swarm/network/stream/race_test.go +++ b/swarm/testutil/race.go @@ -16,8 +16,8 @@ // +build race -package stream +package testutil -// Reduce the scope of some tests when running with race detector, -// as it raises the memory consumption significantly. -const raceTest = true +// RaceEnabled is true when -race flag is provided to the go tool. +// See norace.go for more. +const RaceEnabled = true