Skip to content

Commit 96157a8

Browse files
authored
graphql: fix spurious travis failure (#22166)
The tests sometimes failed with certain go versions because the behavior of http.Server.Shutdown changed over time. A bug that was fixed in Go 1.15 could cause active connections on unrelated servers to close unexpectedly. This is fixed by avoiding use of the same port number in all tests.
1 parent 2aaff0a commit 96157a8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

graphql/graphql_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestGraphQLBlockSerialization(t *testing.T) {
131131
code: 200,
132132
},
133133
} {
134-
resp, err := http.Post(fmt.Sprintf("http://%s/graphql", "127.0.0.1:9393"), "application/json", strings.NewReader(tt.body))
134+
resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", strings.NewReader(tt.body))
135135
if err != nil {
136136
t.Fatalf("could not post: %v", err)
137137
}
@@ -156,7 +156,7 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Unsuccessful(t *testing.T) {
156156
t.Fatalf("could not start node: %v", err)
157157
}
158158
body := strings.NewReader(`{"query": "{block{number}}","variables": null}`)
159-
resp, err := http.Post(fmt.Sprintf("http://%s/graphql", "127.0.0.1:9393"), "application/json", body)
159+
resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", body)
160160
if err != nil {
161161
t.Fatalf("could not post: %v", err)
162162
}
@@ -177,21 +177,21 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Unsuccessful(t *testing.T) {
177177
func createNode(t *testing.T, gqlEnabled bool) *node.Node {
178178
stack, err := node.New(&node.Config{
179179
HTTPHost: "127.0.0.1",
180-
HTTPPort: 9393,
180+
HTTPPort: 0,
181181
WSHost: "127.0.0.1",
182-
WSPort: 9393,
182+
WSPort: 0,
183183
})
184184
if err != nil {
185185
t.Fatalf("could not create node: %v", err)
186186
}
187187
if !gqlEnabled {
188188
return stack
189189
}
190-
createGQLService(t, stack, "127.0.0.1:9393")
190+
createGQLService(t, stack)
191191
return stack
192192
}
193193

194-
func createGQLService(t *testing.T, stack *node.Node, endpoint string) {
194+
func createGQLService(t *testing.T, stack *node.Node) {
195195
// create backend
196196
ethConf := &eth.Config{
197197
Genesis: &core.Genesis{

0 commit comments

Comments
 (0)