Last active
October 23, 2017 03:19
-
-
Save vaskoz/1fd80dd81e14d87b3a720c0481f6d016 to your computer and use it in GitHub Desktop.
This file contains 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
go test -parallel=1 -race -v parallel_test.go | |
=== RUN TestOne | |
=== PAUSE TestOne | |
=== RUN TestTwo | |
=== PAUSE TestTwo | |
=== CONT TestTwo | |
=== CONT TestOne | |
--- PASS: TestTwo (0.00s) | |
--- PASS: TestOne (0.00s) | |
PASS | |
ok command-line-arguments 1.020s | |
go test -parallel=2 -race -v parallel_test.go | |
=== RUN TestOne | |
=== PAUSE TestOne | |
=== RUN TestTwo | |
=== PAUSE TestTwo | |
=== CONT TestTwo | |
=== CONT TestOne | |
================== | |
WARNING: DATA RACE | |
Write at 0x00c420088240 by goroutine 6: | |
runtime.mapassign_faststr() | |
/Users/vasko/code/go/src/runtime/hashmap_fast.go:534 +0x0 | |
command-line-arguments.TestOne() | |
/Users/vasko/tmp/parallel_test.go:9 +0x91 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
Previous write at 0x00c420088240 by goroutine 7: | |
runtime.mapassign_faststr() | |
/Users/vasko/code/go/src/runtime/hashmap_fast.go:534 +0x0 | |
command-line-arguments.TestTwo() | |
/Users/vasko/tmp/parallel_test.go:20 +0x91 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
Goroutine 6 (running) created at: | |
testing.(*T).Run() | |
/Users/vasko/code/go/src/testing/testing.go:812 +0x535 | |
testing.runTests.func1() | |
/Users/vasko/code/go/src/testing/testing.go:1036 +0xa4 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
testing.runTests() | |
/Users/vasko/code/go/src/testing/testing.go:1034 +0x4c7 | |
testing.(*M).Run() | |
/Users/vasko/code/go/src/testing/testing.go:954 +0x271 | |
main.main() | |
b001/_testmain.go:44 +0x228 | |
Goroutine 7 (running) created at: | |
testing.(*T).Run() | |
/Users/vasko/code/go/src/testing/testing.go:812 +0x535 | |
testing.runTests.func1() | |
/Users/vasko/code/go/src/testing/testing.go:1036 +0xa4 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
testing.runTests() | |
/Users/vasko/code/go/src/testing/testing.go:1034 +0x4c7 | |
testing.(*M).Run() | |
/Users/vasko/code/go/src/testing/testing.go:954 +0x271 | |
main.main() | |
b001/_testmain.go:44 +0x228 | |
================== | |
================== | |
WARNING: DATA RACE | |
Write at 0x00c4200c2088 by goroutine 6: | |
command-line-arguments.TestOne() | |
/Users/vasko/tmp/parallel_test.go:9 +0xa4 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
Previous write at 0x00c4200c2088 by goroutine 7: | |
command-line-arguments.TestTwo() | |
/Users/vasko/tmp/parallel_test.go:20 +0xa4 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
Goroutine 6 (running) created at: | |
testing.(*T).Run() | |
/Users/vasko/code/go/src/testing/testing.go:812 +0x535 | |
testing.runTests.func1() | |
/Users/vasko/code/go/src/testing/testing.go:1036 +0xa4 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
testing.runTests() | |
/Users/vasko/code/go/src/testing/testing.go:1034 +0x4c7 | |
testing.(*M).Run() | |
/Users/vasko/code/go/src/testing/testing.go:954 +0x271 | |
main.main() | |
b001/_testmain.go:44 +0x228 | |
Goroutine 7 (running) created at: | |
testing.(*T).Run() | |
/Users/vasko/code/go/src/testing/testing.go:812 +0x535 | |
testing.runTests.func1() | |
/Users/vasko/code/go/src/testing/testing.go:1036 +0xa4 | |
testing.tRunner() | |
/Users/vasko/code/go/src/testing/testing.go:769 +0x169 | |
testing.runTests() | |
/Users/vasko/code/go/src/testing/testing.go:1034 +0x4c7 | |
testing.(*M).Run() | |
/Users/vasko/code/go/src/testing/testing.go:954 +0x271 | |
main.main() | |
b001/_testmain.go:44 +0x228 | |
================== | |
--- FAIL: TestOne (0.00s) | |
testing.go:722: race detected during execution of test | |
--- FAIL: TestTwo (0.00s) | |
FAIL | |
exit status 1 | |
FAIL command-line-arguments 0.018s |
This file contains 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
package main | |
import "testing" | |
var data = make(map[string]string) | |
func TestOne(t *testing.T) { | |
t.Parallel() | |
data["foo"] = "bar" | |
if len(data) != 1 { | |
t.Error("Data map should have 1 entry") | |
} | |
if v, exists := data["foo"]; !exists || v != "bar" { | |
t.Errorf("Value should have been 'bar' but instead found %s\n", v) | |
} | |
} | |
func TestTwo(t *testing.T) { | |
t.Parallel() | |
data["foo"] = "baz" | |
if len(data) != 1 { | |
t.Error("Data map should have 1 entry") | |
} | |
if v, exists := data["foo"]; !exists || v != "baz" { | |
t.Errorf("Value should have been 'baz' but instead found %s\n", v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment