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
|
// 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")
|
query := NewTermQuery("test")
|
||||||
sr := NewSearchRequest(query)
|
sr := NewSearchRequest(query)
|
||||||
res, err := MultiSearch(ctx, sr, ei1, ei2)
|
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)
|
// 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)
|
res, err = MultiSearch(ctx, sr, ei1, ei2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected no error, got %v", err)
|
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
|
// 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)
|
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
cancel()
|
cancel()
|
||||||
res, err = MultiSearch(ctx, sr, ei1, ei2)
|
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
|
// ei3 is set to take >50ms, so run search with timeout less than
|
||||||
// this, this should return partial results
|
// 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")
|
query := NewTermQuery("test")
|
||||||
sr := NewSearchRequest(query)
|
sr := NewSearchRequest(query)
|
||||||
expected := &SearchResult{
|
expected := &SearchResult{
|
||||||
|
@ -1089,8 +1093,9 @@ func TestIndexAliasMultipleLayer(t *testing.T) {
|
||||||
// ei2 and ei3 have 50ms delay
|
// ei2 and ei3 have 50ms delay
|
||||||
// search across aliasTop should still get results from ei1 and ei4
|
// search across aliasTop should still get results from ei1 and ei4
|
||||||
// total should still be 4
|
// total should still be 4
|
||||||
|
var cancel context.CancelFunc
|
||||||
ctx, _ = context.WithTimeout(context.Background(), 25*time.Millisecond)
|
ctx, cancel = context.WithTimeout(context.Background(), 25*time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
query := NewTermQuery("test")
|
query := NewTermQuery("test")
|
||||||
sr := NewSearchRequest(query)
|
sr := NewSearchRequest(query)
|
||||||
expected := &SearchResult{
|
expected := &SearchResult{
|
||||||
|
|
|
@ -1507,7 +1507,8 @@ func TestSearchTimeout(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// first run a search with an absurdly long timeout (should succeeed)
|
// 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")
|
query := NewTermQuery("water")
|
||||||
req := NewSearchRequest(query)
|
req := NewSearchRequest(query)
|
||||||
_, err = index.SearchInContext(ctx, req)
|
_, 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)
|
// 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{
|
sq := &slowQuery{
|
||||||
actual: query,
|
actual: query,
|
||||||
delay: 50 * time.Millisecond, // on Windows timer resolution is 15ms
|
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
|
// 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{
|
sq = &slowQuery{
|
||||||
actual: query,
|
actual: query,
|
||||||
delay: 100 * time.Millisecond, // on Windows timer resolution is 15ms
|
delay: 100 * time.Millisecond, // on Windows timer resolution is 15ms
|
||||||
|
|
Loading…
Reference in New Issue