Skip to content

Commit 484bac7

Browse files
committed
test: don't call flag.Parse in init
this addresses golang/go#31859
1 parent 7d0686e commit 484bac7

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

demoinfocs_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ const demSetPath = csDemosPath + "/set"
3232
const defaultDemPath = csDemosPath + "/default.dem"
3333
const unexpectedEndOfDemoPath = csDemosPath + "/unexpected_end_of_demo.dem"
3434

35-
var concurrentDemos int
35+
var concurrentDemos = flag.Int("concurrentdemos", 2, "The `number` of current demos")
3636

3737
func init() {
38-
flag.IntVar(&concurrentDemos, "concurrentdemos", 2, "The `number` of current demos")
39-
flag.Parse()
40-
4138
if _, err := os.Stat(defaultDemPath); err != nil {
4239
panic(fmt.Sprintf("Failed to read test demo %q", defaultDemPath))
4340
}
@@ -220,7 +217,7 @@ func TestConcurrent(t *testing.T) {
220217
t.Skip("skipping test")
221218
}
222219

223-
t.Logf("Running concurrency test with %d demos\n", concurrentDemos)
220+
t.Logf("Running concurrency test with %d demos\n", *concurrentDemos)
224221

225222
var i int64
226223
runner := func() {
@@ -249,7 +246,7 @@ func parseDefaultDemo(tb testing.TB) {
249246

250247
func runConcurrently(runner func()) {
251248
var wg sync.WaitGroup
252-
for i := 0; i < concurrentDemos; i++ {
249+
for i := 0; i < *concurrentDemos; i++ {
253250
wg.Add(1)
254251
go func() { runner(); wg.Done() }()
255252
}
@@ -313,7 +310,7 @@ func BenchmarkInMemory(b *testing.B) {
313310
}
314311

315312
func BenchmarkConcurrent(b *testing.B) {
316-
b.Logf("Running concurrency benchmark with %d demos\n", concurrentDemos)
313+
b.Logf("Running concurrency benchmark with %d demos\n", *concurrentDemos)
317314

318315
for i := 0; i < b.N; i++ {
319316
runConcurrently(func() { parseDefaultDemo(b) })

0 commit comments

Comments
 (0)