@cryptotaxi247 / kubo / commits / 9d167cd5e

testfix: dont break 8k goroutine limit under race

Juan Batiz-Benet committed Mar 2, 2015 at 01:58 UTC 9d167cd5e8a77c8236334b45200ad250b592c0f3
8 files changed +93 -1
Godeps/Godeps.json
+4
@@ -151,6 +151,10 @@
151 "ImportPath": "github.com/jbenet/go-datastore",
152 "Rev": "35738aceb35505bd3c77c2a618fb1947ca3f72da"
153 },
154 + {
155 + "ImportPath": "github.com/jbenet/go-detect-race",
156 + "Rev": "3463798d9574bd0b7eca275dccc530804ff5216f"
157 + },
158 {
159 "ImportPath": "github.com/jbenet/go-fuse-version",
160 "Rev": "b733dfc0597e1f6780510ee7afad8b6e3c7af3eb"
Godeps/_workspace/src/github.com/jbenet/go-detect-race/LICENSE new
+21
@@ -0,0 +1,21 @@
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2014 Juan Batiz-Benet
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in
13 +all copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 +THE SOFTWARE.
Godeps/_workspace/src/github.com/jbenet/go-detect-race/README.md new
+33
@@ -0,0 +1,33 @@
1 +# go-detect-race
2 +
3 +Check if the race detector is running.
4 +
5 +I didnt find a variable to check quickly enough so I made this.
6 +
7 +
8 +## Usage
9 +
10 +```go
11 +import (
12 + detectrace "github.com/jbenet/go-detect-race"
13 +)
14 +
15 +func main() {
16 + if detectrace.WithRace() {
17 + // running with -race
18 + } else {
19 + // running without -race
20 + }
21 +}
22 +```
23 +
24 +## Why?
25 +
26 +Because the race detector doesnt like massive stress tests. Example:
27 +https://groups.google.com/forum/#!topic/golang-nuts/XDPHUt2LE70
28 +
29 +## Why didn't you just use...
30 +
31 +Please tell me about a better way of doing this. It wasn't
32 +readily apparent to me, so I made this. But i would much prefer
33 +an env var or some already existing var from the stdlib :)
Godeps/_workspace/src/github.com/jbenet/go-detect-race/race.go new
+7
@@ -0,0 +1,7 @@
1 +package detectrace
2 +
3 +// WithRace returns whether the binary was compiled
4 +// with the race flag on.
5 +func WithRace() bool {
6 + return withRace
7 +}
Godeps/_workspace/src/github.com/jbenet/go-detect-race/race_test.go new
+9
@@ -0,0 +1,9 @@
1 +package detectrace
2 +
3 +import (
4 + "testing"
5 +)
6 +
7 +func TestWithRace(t *testing.T) {
8 + t.Logf("WithRace() is %v\n", WithRace())
9 +}
Godeps/_workspace/src/github.com/jbenet/go-detect-race/withoutrace.go new
+5
@@ -0,0 +1,5 @@
1 +// +build !race
2 +
3 +package detectrace
4 +
5 +const withRace = false
Godeps/_workspace/src/github.com/jbenet/go-detect-race/withrace.go new
+5
@@ -0,0 +1,5 @@
1 +// +build race
2 +
3 +package detectrace
4 +
5 +const withRace = true
exchange/bitswap/bitswap_test.go
+9 -1
@@ -6,7 +6,9 @@ import (
6 "testing"
7 "time"
8
9 + detectrace "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-detect-race"
10 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
11 +
12 blocks "github.com/jbenet/go-ipfs/blocks"
13 blocksutil "github.com/jbenet/go-ipfs/blocks/blocksutil"
14 tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
@@ -93,9 +95,15 @@ func TestLargeSwarm(t *testing.T) {
95 if testing.Short() {
96 t.SkipNow()
97 }
96 - t.Parallel()
98 numInstances := 500
99 numBlocks := 2
100 + if detectrace.WithRace() {
101 + // when running with the race detector, 500 instances launches
102 + // well over 8k goroutines. This hits a race detector limit.
103 + numInstances = 100
104 + } else {
105 + t.Parallel()
106 + }
107 PerformDistributionTest(t, numInstances, numBlocks)
108 }
109