Skip to content

Commit

Permalink
Only check top 20 matches for v3 node search tests (#1483)
Browse files Browse the repository at this point in the history
The order of lower matches can be nondeterministic, so this is just to
help make tests less flaky
  • Loading branch information
n-h-diaz authored Dec 30, 2024
1 parent 7f01c88 commit b0298ee
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2,243 deletions.
560 changes: 0 additions & 560 deletions internal/server/spanner/golden/query/search_nodes_with_type.json

Large diffs are not rendered by default.

560 changes: 0 additions & 560 deletions internal/server/spanner/golden/query/search_nodes_without_type.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion internal/server/spanner/golden/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (
"github.com/google/go-cmp/cmp"
)

const (
// Number of matches to validate for SearchNodes tests.
NUM_SEARCH_MATCHES = 20
)

func TestGetNodeProps(t *testing.T) {
client := test.NewSpannerClient()
if client == nil {
Expand Down Expand Up @@ -321,7 +326,10 @@ func TestSearchNodes(t *testing.T) {
t.Fatalf("SearchNodes error (%v): %v", c.goldenFile, err)
}

got, err := test.StructToJSON(actual)
// Filter actual to top matches to avoid flaky low matches.
topResp := actual[:NUM_SEARCH_MATCHES]

got, err := test.StructToJSON(topResp)
if err != nil {
t.Fatalf("StructToJSON error (%v): %v", c.goldenFile, err)
}
Expand Down
15 changes: 13 additions & 2 deletions internal/server/v3/nodesearch/golden/node_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
"google.golang.org/protobuf/testing/protocmp"
)

const (
// Number of matches to validate for NodeSearch tests.
NUM_SEARCH_MATCHES = 20
)

func TestV3NodeSearch(t *testing.T) {
// TODO: Remove check once enabled.
if !test.EnableSpannerGraph {
Expand Down Expand Up @@ -63,19 +68,25 @@ func TestV3NodeSearch(t *testing.T) {
t.Errorf("Could not run V3NodeSearch: %s", err)
continue
}

// Filter resp to top matches to avoid flaky low matches.
topResp := &pbv3.NodeSearchResponse{
Nodes: resp.Nodes[:NUM_SEARCH_MATCHES],
}

if latencyTest {
continue
}
if test.GenerateGolden {
test.UpdateGolden(resp, goldenPath, goldenFile)
test.UpdateGolden(topResp, goldenPath, goldenFile)
continue
}
var expected pbv3.NodeSearchResponse
if err = test.ReadJSON(goldenPath, goldenFile, &expected); err != nil {
t.Errorf("Could not Unmarshal golden file: %s", err)
continue
}
if diff := cmp.Diff(resp, &expected, protocmp.Transform()); diff != "" {
if diff := cmp.Diff(topResp, &expected, protocmp.Transform()); diff != "" {
t.Errorf("%s: got diff: %s", goldenFile, diff)
continue
}
Expand Down
Loading

0 comments on commit b0298ee

Please sign in to comment.