Skip to content

Commit

Permalink
improve performance of query callback test
Browse files Browse the repository at this point in the history
the behavior being tested did not depend on any data actually
being indexed, so that was removed

additional documentation was added to clarify what this test
was testing, since it was not clear and we did not remember
  • Loading branch information
mschoch committed Apr 30, 2020
1 parent 98b3d3b commit 94161c7
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1896,29 +1896,15 @@ func TestSearchQueryCallback(t *testing.T) {
}
}()

elements := []string{"air", "water", "fire", "earth"}
b := index.NewBatch()
for j := 0; j < 10000; j++ {
err = b.Index(fmt.Sprintf("%d", j),
map[string]interface{}{"name": elements[j%len(elements)]})
if err != nil {
t.Fatal(err)
}
}
err = index.Batch(b)
if err != nil {
t.Fatal(err)
}

query := NewTermQuery("water")
req := NewSearchRequest(query)

expErr := fmt.Errorf("MEM_LIMIT_EXCEEDED")
f := func(size uint64) error {
if size > 1000 {
return expErr
}
return nil
// the intended usage of this callback is to see the estimated
// memory usage before executing, and possibly abort early
// in this test we simulate returning such an error
return expErr
}

ctx := context.WithValue(context.Background(), SearchQueryStartCallbackKey,
Expand Down

0 comments on commit 94161c7

Please sign in to comment.