This repository was archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Fix stream race tests #1208
Closed
Closed
Fix stream race tests #1208
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4d65aea
swarm/network/stream: newStreamerTester cleanup only if err is nil
janos 73d5c97
swarm/network/stream: raise newStreamerTester waitForPeers timeout
janos d233560
swarm/network/stream: fix data races in GetPeerSubscriptions
janos edfee9c
swarm/storage: prevent data race on LDBStore.batchesC
janos 91f8735
swarm/network/stream: fix TestGetSubscriptionsRPC data race
janos 11d9441
swarm/network/stream: correctly use Simulation.Run callback
janos e411147
swarm/network: protect addrCountC in Kademlia.AddrCountC function
janos 080f4c2
p2p/simulations: fix a deadlock calling getRandomNode with lock
janos b151dc2
swarm/network/stream: terminate disconnect goruotines in tests
janos 4f5807b
swarm/network/stream: reduce memory consumption when testing data races
janos dee2145
swarm/network/stream: add watchDisconnections helper function
janos c3f2368
swarm/network/stream: add concurrent counter for tests
janos baed029
swarm/network/stream: rename race/norace test files and use const
janos 1467d2b
swarm/network/stream: remove watchSim and its panic
janos 3710a72
swarm/network/stream: pass context in watchDisconnections
janos 714d871
swarm/network/stream: add concurrent safe bool for watchDisconnections
janos d8f29cf
swarm/storage: fix LDBStore.batchesC data race by not closing it
janos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package stream | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "runtime" | ||
| "sync" | ||
|
|
@@ -92,6 +93,15 @@ func TestSyncingViaGlobalSync(t *testing.T) { | |
| if *longrunning { | ||
| chnkCnt = []int{1, 8, 32, 256, 1024} | ||
| nodeCnt = []int{16, 32, 64, 128, 256} | ||
| } else if raceTest { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this still needed on top of using db vs in memory store?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is. |
||
| // TestSyncingViaGlobalSync allocates a lot of memory | ||
| // with race detector. By reducing the number of chunks | ||
| // and nodes, memory consumption is lower and data races | ||
| // are still checked, while correctness of syncing is | ||
| // tested with more chunks and nodes in regular (!race) | ||
| // tests. | ||
| chnkCnt = []int{4} | ||
| nodeCnt = []int{16} | ||
| } else { | ||
| //default test | ||
| chnkCnt = []int{4, 32} | ||
|
|
@@ -113,7 +123,23 @@ var simServiceMap = map[string]simulation.ServiceFunc{ | |
| return nil, nil, err | ||
| } | ||
|
|
||
| r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{ | ||
| var dir string | ||
| var store *state.DBStore | ||
| if raceTest { | ||
| // Use on-disk DBStore to reduce memory consumption in race tests. | ||
| dir, err = ioutil.TempDir("", "swarm-stream-") | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| store, err = state.NewDBStore(dir) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| } else { | ||
| store = state.NewInmemoryStore() | ||
| } | ||
|
|
||
| r := NewRegistry(addr.ID(), delivery, netStore, store, &RegistryOptions{ | ||
| Retrieval: RetrievalDisabled, | ||
| Syncing: SyncingAutoSubscribe, | ||
| SyncUpdateDelay: 3 * time.Second, | ||
|
|
@@ -164,9 +190,16 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) { | |
|
|
||
| var disconnected atomic.Value | ||
| go func() { | ||
| for d := range disconnections { | ||
| if d.Error != nil { | ||
| log.Error("peer drop", "node", d.NodeID, "peer", d.PeerID) | ||
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return | ||
| case d := <-disconnections: | ||
| if d.Error != nil { | ||
| log.Error("peer drop event error", "node", d.NodeID, "peer", d.PeerID, "err", err) | ||
| } else { | ||
| log.Error("peer drop", "node", d.NodeID, "peer", d.PeerID) | ||
| } | ||
| disconnected.Store(true) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.