From 806313276698e176d9824dfefbbed730eef259ad Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Tue, 27 Feb 2018 11:57:21 -0800 Subject: [PATCH] fix new issues found by go vet when using stdlib context pkg --- index_alias_impl_test.go | 17 +++++++++++------ index_test.go | 8 +++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/index_alias_impl_test.go b/index_alias_impl_test.go index 2ee64991..9599b89d 100644 --- a/index_alias_impl_test.go +++ b/index_alias_impl_test.go @@ -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{ diff --git a/index_test.go b/index_test.go index f16a8f63..a69357bf 100644 --- a/index_test.go +++ b/index_test.go @@ -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