fix new issues found by go vet when using stdlib context pkg
This commit is contained in:
parent
c74e08f039
commit
8063132766
|
@ -782,7 +782,9 @@ func TestMultiSearchTimeout(t *testing.T) {
|
|||
}}
|
||||
|
||||
// first run with absurdly long time out, should succeed
|
||||
ctx, _ = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
query := NewTermQuery("test")
|
||||
sr := NewSearchRequest(query)
|
||||
res, err := MultiSearch(ctx, sr, ei1, ei2)
|
||||
|
@ -803,7 +805,8 @@ func TestMultiSearchTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
// now run a search again with an absurdly low timeout (should timeout)
|
||||
ctx, _ = context.WithTimeout(context.Background(), 1*time.Microsecond)
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Microsecond)
|
||||
defer cancel()
|
||||
res, err = MultiSearch(ctx, sr, ei1, ei2)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v", err)
|
||||
|
@ -829,7 +832,6 @@ func TestMultiSearchTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
// now run a search again with a normal timeout, but cancel it first
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||
cancel()
|
||||
res, err = MultiSearch(ctx, sr, ei1, ei2)
|
||||
|
@ -936,7 +938,9 @@ func TestMultiSearchTimeoutPartial(t *testing.T) {
|
|||
|
||||
// ei3 is set to take >50ms, so run search with timeout less than
|
||||
// this, this should return partial results
|
||||
ctx, _ = context.WithTimeout(context.Background(), 25*time.Millisecond)
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 25*time.Millisecond)
|
||||
defer cancel()
|
||||
query := NewTermQuery("test")
|
||||
sr := NewSearchRequest(query)
|
||||
expected := &SearchResult{
|
||||
|
@ -1089,8 +1093,9 @@ func TestIndexAliasMultipleLayer(t *testing.T) {
|
|||
// ei2 and ei3 have 50ms delay
|
||||
// search across aliasTop should still get results from ei1 and ei4
|
||||
// total should still be 4
|
||||
|
||||
ctx, _ = context.WithTimeout(context.Background(), 25*time.Millisecond)
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 25*time.Millisecond)
|
||||
defer cancel()
|
||||
query := NewTermQuery("test")
|
||||
sr := NewSearchRequest(query)
|
||||
expected := &SearchResult{
|
||||
|
|
|
@ -1507,7 +1507,8 @@ func TestSearchTimeout(t *testing.T) {
|
|||
}()
|
||||
|
||||
// first run a search with an absurdly long timeout (should succeeed)
|
||||
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
query := NewTermQuery("water")
|
||||
req := NewSearchRequest(query)
|
||||
_, err = index.SearchInContext(ctx, req)
|
||||
|
@ -1516,7 +1517,8 @@ func TestSearchTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
// now run a search again with an absurdly low timeout (should timeout)
|
||||
ctx, _ = context.WithTimeout(context.Background(), 1*time.Microsecond)
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Microsecond)
|
||||
defer cancel()
|
||||
sq := &slowQuery{
|
||||
actual: query,
|
||||
delay: 50 * time.Millisecond, // on Windows timer resolution is 15ms
|
||||
|
@ -1528,7 +1530,7 @@ func TestSearchTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
// now run a search with a long timeout, but with a long query, and cancel it
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
sq = &slowQuery{
|
||||
actual: query,
|
||||
delay: 100 * time.Millisecond, // on Windows timer resolution is 15ms
|
||||
|
|
Loading…
Reference in New Issue