提交 9d167cd5 作者: Juan Batiz-Benet

testfix: dont break 8k goroutine limit under race

上级 0adde5cf
......@@ -152,6 +152,10 @@
"Rev": "35738aceb35505bd3c77c2a618fb1947ca3f72da"
},
{
"ImportPath": "github.com/jbenet/go-detect-race",
"Rev": "3463798d9574bd0b7eca275dccc530804ff5216f"
},
{
"ImportPath": "github.com/jbenet/go-fuse-version",
"Rev": "b733dfc0597e1f6780510ee7afad8b6e3c7af3eb"
},
......
The MIT License (MIT)
Copyright (c) 2014 Juan Batiz-Benet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# go-detect-race
Check if the race detector is running.
I didnt find a variable to check quickly enough so I made this.
## Usage
```go
import (
detectrace "github.com/jbenet/go-detect-race"
)
func main() {
if detectrace.WithRace() {
// running with -race
} else {
// running without -race
}
}
```
## Why?
Because the race detector doesnt like massive stress tests. Example:
https://groups.google.com/forum/#!topic/golang-nuts/XDPHUt2LE70
## Why didn't you just use...
Please tell me about a better way of doing this. It wasn't
readily apparent to me, so I made this. But i would much prefer
an env var or some already existing var from the stdlib :)
package detectrace
// WithRace returns whether the binary was compiled
// with the race flag on.
func WithRace() bool {
return withRace
}
package detectrace
import (
"testing"
)
func TestWithRace(t *testing.T) {
t.Logf("WithRace() is %v\n", WithRace())
}
// +build !race
package detectrace
const withRace = false
// +build race
package detectrace
const withRace = true
......@@ -6,7 +6,9 @@ import (
"testing"
"time"
detectrace "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-detect-race"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
blocks "github.com/jbenet/go-ipfs/blocks"
blocksutil "github.com/jbenet/go-ipfs/blocks/blocksutil"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
......@@ -93,9 +95,15 @@ func TestLargeSwarm(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()
numInstances := 500
numBlocks := 2
if detectrace.WithRace() {
// when running with the race detector, 500 instances launches
// well over 8k goroutines. This hits a race detector limit.
numInstances = 100
} else {
t.Parallel()
}
PerformDistributionTest(t, numInstances, numBlocks)
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论