forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
race_test.go
64 lines (56 loc) · 1.16 KB
/
race_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package graphql_test
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
)
func TestRace(t *testing.T) {
tempdir, err := ioutil.TempDir("", "race")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempdir)
filename := filepath.Join(tempdir, "example.go")
err = ioutil.WriteFile(filename, []byte(`
package main
import (
"runtime"
"sync"
"github.com/graphql-go/graphql"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
for i := 0; i < 2; i++ {
go func() {
defer wg.Done()
schema, _ := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: graphql.Fields{
"hello": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "world", nil
},
},
},
}),
})
runtime.KeepAlive(schema)
}()
}
wg.Wait()
}
`), 0755)
if err != nil {
t.Fatal(err)
}
result, err := exec.Command("go", "run", "-race", filename).CombinedOutput()
if err != nil || len(result) != 0 {
t.Log(string(result))
t.Fatal(err)
}
}