Skip to content

Commit

Permalink
Travis-CI reports sporadic failures on TestRegexpSearchScorch (#1057)
Browse files Browse the repository at this point in the history
* Bugfix: Travis-CI reports sporadic failures on TestRegexpSearchScorch.

* Check return values.

* TestRegexpSearchScorch - Changing InternalID to docID ('_id').

* Map initializing.
  • Loading branch information
rvncerr authored and abhinavdangeti committed Nov 30, 2018
1 parent 793852f commit 367c740
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
14 changes: 7 additions & 7 deletions search/searcher/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package searcher

import (
"io/ioutil"
"math"
"regexp"

Expand Down Expand Up @@ -48,9 +47,8 @@ func initTwoDocUpsideDown() index.Index {
return twoDocIndex
}

func initTwoDocScorch() index.Index {
func initTwoDocScorch(dir string) index.Index {
analysisQueue := index.NewAnalysisQueue(1)
dir, _ := ioutil.TempDir("", "scorchTwoDoc")
twoDocIndex, err := scorch.NewScorch(
scorch.Name,
map[string]interface{}{
Expand All @@ -68,11 +66,13 @@ func initTwoDocs(twoDocIndex index.Index) {
if err != nil {
panic(err)
}
batch := index.NewBatch()
for _, doc := range twoDocIndexDocs {
err := twoDocIndex.Update(doc)
if err != nil {
panic(err)
}
batch.Update(doc)
}
err = twoDocIndex.Batch(batch)
if err != nil {
panic(err)
}
}

Expand Down
57 changes: 30 additions & 27 deletions search/searcher/search_regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package searcher
import (
"encoding/binary"
"fmt"
"io/ioutil"
"os"
"regexp"
"testing"

Expand All @@ -37,13 +39,23 @@ func TestRegexpStringSearchUpsideDown(t *testing.T) {
}

func TestRegexpSearchScorch(t *testing.T) {
twoDocIndex := initTwoDocScorch()
dir, _ := ioutil.TempDir("", "scorchTwoDoc")
defer func() {
_ = os.RemoveAll(dir)
}()

twoDocIndex := initTwoDocScorch(dir)
testRegexpSearch(t, twoDocIndex, internalIDMakerScorch, searcherMaker)
_ = twoDocIndex.Close()
}

func TestRegexpStringSearchScorch(t *testing.T) {
twoDocIndex := initTwoDocScorch()
dir, _ := ioutil.TempDir("", "scorchTwoDoc")
defer func() {
_ = os.RemoveAll(dir)
}()

twoDocIndex := initTwoDocScorch(dir)
testRegexpSearch(t, twoDocIndex, internalIDMakerScorch, searcherStringMaker)
_ = twoDocIndex.Close()
}
Expand Down Expand Up @@ -101,29 +113,20 @@ func testRegexpSearch(t *testing.T, twoDocIndex index.Index,
regexpSearcherCo := searcherMaker(t, twoDocIndexReader, "co.*", "desc")

tests := []struct {
searcher search.Searcher
expecteds []*search.DocumentMatch
searcher search.Searcher
id2score map[string]float64
}{
{
searcher: regexpSearcher,
expecteds: []*search.DocumentMatch{
{
IndexInternalID: internalIDMaker(1),
Score: 1.916290731874155,
},
id2score: map[string]float64{
"1": 1.916290731874155,
},
},
{
searcher: regexpSearcherCo,
expecteds: []*search.DocumentMatch{
{
IndexInternalID: internalIDMaker(2),
Score: 0.33875554280828685,
},
{
IndexInternalID: internalIDMaker(3),
Score: 0.33875554280828685,
},
id2score: map[string]float64{
"2": 0.33875554280828685,
"3": 0.33875554280828685,
},
},
}
Expand All @@ -142,14 +145,14 @@ func testRegexpSearch(t *testing.T, twoDocIndex index.Index,
next, err := test.searcher.Next(ctx)
i := 0
for err == nil && next != nil {
if i < len(test.expecteds) {
if !next.IndexInternalID.Equals(test.expecteds[i].IndexInternalID) {
t.Errorf("test %d, expected result %d to have id %s got %s, next: %#v",
testIndex, i, test.expecteds[i].IndexInternalID, next.IndexInternalID, next)
}
if next.Score != test.expecteds[i].Score {
exID, _ := twoDocIndexReader.ExternalID(next.IndexInternalID)
if _, ok := test.id2score[exID]; !ok {
t.Errorf("test %d, found unexpected docID = %v, next = %v", testIndex, exID, next)
} else {
score := test.id2score[exID]
if next.Score != score {
t.Errorf("test %d, expected result %d to have score %v got %v,next: %#v",
testIndex, i, test.expecteds[i].Score, next.Score, next)
testIndex, i, score, next.Score, next)
t.Logf("scoring explanation: %s", next.Expl)
}
}
Expand All @@ -160,8 +163,8 @@ func testRegexpSearch(t *testing.T, twoDocIndex index.Index,
if err != nil {
t.Fatalf("error iterating searcher: %v for test %d", err, testIndex)
}
if len(test.expecteds) != i {
t.Errorf("expected %d results got %d for test %d", len(test.expecteds), i, testIndex)
if len(test.id2score) != i {
t.Errorf("expected %d results got %d for test %d", len(test.id2score), i, testIndex)
}
}
}

0 comments on commit 367c740

Please sign in to comment.