1
0
Fork 0

Direct HTTP requests to avoid races during testing

master
Philip O'Toole 3 years ago
parent 9ca9a3f1fd
commit 3d3bbabaeb

@ -263,6 +263,25 @@ func (n *Node) postQuery(stmt string) (string, error) {
return string(body), nil
}
// PostExecuteStmt performs a HTTP execute request
func PostExecuteStmt(apiAddr, stmt string) (string, error) {
j, err := json.Marshal([]string{stmt})
if err != nil {
return "", err
}
resp, err := http.Post("http://"+apiAddr+"/db/execute", "application/json", strings.NewReader(string(j)))
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}
// Cluster represents a cluster of nodes.
type Cluster []*Node

@ -152,9 +152,9 @@ func Test_SingleNodeConcurrentRequests(t *testing.T) {
go func() {
defer wg.Done()
_, err = node.Execute(`INSERT INTO foo(name) VALUES("fiona")`)
resp, err := PostExecuteStmt(node.APIAddr, `INSERT INTO foo(name) VALUES("fiona")`)
if err != nil {
t.Fatalf("failed to insert record: %s", err.Error())
t.Fatalf("failed to insert record: %s %s", err.Error(), resp)
}
}()
}

Loading…
Cancel
Save