Skip to content

Commit

Permalink
graphql: fix spurious travis failure (ethereum#22166)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
holiman authored Jan 13, 2021
1 parent 2aaff0a commit 96157a8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestGraphQLBlockSerialization(t *testing.T) {
code: 200,
},
} {
resp, err := http.Post(fmt.Sprintf("http://%s/graphql", "127.0.0.1:9393"), "application/json", strings.NewReader(tt.body))
resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", strings.NewReader(tt.body))
if err != nil {
t.Fatalf("could not post: %v", err)
}
Expand All @@ -156,7 +156,7 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Unsuccessful(t *testing.T) {
t.Fatalf("could not start node: %v", err)
}
body := strings.NewReader(`{"query": "{block{number}}","variables": null}`)
resp, err := http.Post(fmt.Sprintf("http://%s/graphql", "127.0.0.1:9393"), "application/json", body)
resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", body)
if err != nil {
t.Fatalf("could not post: %v", err)
}
Expand All @@ -177,21 +177,21 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Unsuccessful(t *testing.T) {
func createNode(t *testing.T, gqlEnabled bool) *node.Node {
stack, err := node.New(&node.Config{
HTTPHost: "127.0.0.1",
HTTPPort: 9393,
HTTPPort: 0,
WSHost: "127.0.0.1",
WSPort: 9393,
WSPort: 0,
})
if err != nil {
t.Fatalf("could not create node: %v", err)
}
if !gqlEnabled {
return stack
}
createGQLService(t, stack, "127.0.0.1:9393")
createGQLService(t, stack)
return stack
}

func createGQLService(t *testing.T, stack *node.Node, endpoint string) {
func createGQLService(t *testing.T, stack *node.Node) {
// create backend
ethConf := &eth.Config{
Genesis: &core.Genesis{
Expand Down

0 comments on commit 96157a8

Please sign in to comment.