Skip to content

Commit

Permalink
Fix cluster-test
Browse files Browse the repository at this point in the history
  • Loading branch information
olivere committed Oct 26, 2016
1 parent d7f23c3 commit 99d2ff5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cluster-test/cluster-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"sync/atomic"
"time"

"golang.org/x/net/context"

elastic "gopkg.in/olivere/elastic.v5"
)

Expand Down Expand Up @@ -226,13 +228,15 @@ func (t *TestCase) setup() error {
}
t.client = client

ctx := context.Background()

// Use the IndexExists service to check if a specified index exists.
exists, err := t.client.IndexExists(t.index).Do()
exists, err := t.client.IndexExists(t.index).Do(ctx)
if err != nil {
return err
}
if exists {
deleteIndex, err := t.client.DeleteIndex(t.index).Do()
deleteIndex, err := t.client.DeleteIndex(t.index).Do(ctx)
if err != nil {
return err
}
Expand All @@ -242,7 +246,7 @@ func (t *TestCase) setup() error {
}

// Create a new index.
createIndex, err := t.client.CreateIndex(t.index).Do()
createIndex, err := t.client.CreateIndex(t.index).Do(ctx)
if err != nil {
return err
}
Expand All @@ -257,7 +261,7 @@ func (t *TestCase) setup() error {
Type("tweet").
Id("1").
BodyJson(tweet1).
Do()
Do(ctx)
if err != nil {
return err
}
Expand All @@ -269,13 +273,13 @@ func (t *TestCase) setup() error {
Type("tweet").
Id("2").
BodyString(tweet2).
Do()
Do(ctx)
if err != nil {
return err
}

// Flush to make sure the documents got written.
_, err = t.client.Flush().Index(t.index).Do()
_, err = t.client.Flush().Index(t.index).Do(ctx)
if err != nil {
return err
}
Expand All @@ -284,14 +288,16 @@ func (t *TestCase) setup() error {
}

func (t *TestCase) search() {
ctx := context.Background()

// Loop forever to check for connection issues
for {
// Get tweet with specified ID
get1, err := t.client.Get().
Index(t.index).
Type("tweet").
Id("1").
Do()
Do(ctx)
if err != nil {
//failf("Get failed: %v", err)
t.runCh <- RunInfo{Success: false}
Expand All @@ -311,7 +317,7 @@ func (t *TestCase) search() {
Sort("user", true). // sort by "user" field, ascending
From(0).Size(10). // take documents 0-9
Pretty(true). // pretty print request and response JSON
Do() // execute
Do(ctx) // execute
if err != nil {
//failf("Search failed: %v\n", err)
t.runCh <- RunInfo{Success: false}
Expand Down

0 comments on commit 99d2ff5

Please sign in to comment.