Loading server/match_registry_test.go +45 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "context" "encoding/gob" "fmt" "go.uber.org/atomic" "go.uber.org/zap" "strings" "testing" Loading Loading @@ -264,6 +266,49 @@ func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQueryingArrays(t *test } } // Tests that match can be queried by updated labels func TestMatchRegistryListMatchesAfterLabelsUpdate(t *testing.T) { consoleLogger := loggerForTest(t) matchRegistry, runtimeMatchCreateFunc, err := createTestMatchRegistry(t, consoleLogger) if err != nil { t.Fatalf("error creating test match registry: %v", err) } defer matchRegistry.Stop(0) var rgmc *RuntimeGoMatchCore matchCreateWrapper := func(ctx context.Context, logger *zap.Logger, id uuid.UUID, node string, stopped *atomic.Bool, name string) (RuntimeMatchCore, error) { rmc, err := runtimeMatchCreateFunc(ctx, logger, id, node, stopped, name) if err != nil { return nil, err } rgmc = rmc.(*RuntimeGoMatchCore) return rmc, nil } _, err = matchRegistry.CreateMatch(context.Background(), consoleLogger, matchCreateWrapper, "match", nil) if err != nil { t.Fatal(err) } rgmc.MatchLabelUpdate(`{"updated_label": 1}`) matchRegistry.processLabelUpdates(bluge.NewBatch()) matches, err := matchRegistry.ListMatches(context.Background(), 2, wrapperspb.Bool(true), nil, wrapperspb.Int32(0), wrapperspb.Int32(5), wrapperspb.String(`label.updated_label:1`)) if len(matches) != 1 { t.Fatalf("expected one match, got %d", len(matches)) } matchZero := matches[0] if matchZero.MatchId == "" { t.Fatalf("expected non-empty match id, was empty") } if !matchZero.Authoritative { t.Fatalf("expected authoritative match, got non-authoritative") } } // should create authoritative match, list matches with querying func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQueryingAndBoost(t *testing.T) { consoleLogger := loggerForTest(t) Loading Loading
server/match_registry_test.go +45 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "context" "encoding/gob" "fmt" "go.uber.org/atomic" "go.uber.org/zap" "strings" "testing" Loading Loading @@ -264,6 +266,49 @@ func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQueryingArrays(t *test } } // Tests that match can be queried by updated labels func TestMatchRegistryListMatchesAfterLabelsUpdate(t *testing.T) { consoleLogger := loggerForTest(t) matchRegistry, runtimeMatchCreateFunc, err := createTestMatchRegistry(t, consoleLogger) if err != nil { t.Fatalf("error creating test match registry: %v", err) } defer matchRegistry.Stop(0) var rgmc *RuntimeGoMatchCore matchCreateWrapper := func(ctx context.Context, logger *zap.Logger, id uuid.UUID, node string, stopped *atomic.Bool, name string) (RuntimeMatchCore, error) { rmc, err := runtimeMatchCreateFunc(ctx, logger, id, node, stopped, name) if err != nil { return nil, err } rgmc = rmc.(*RuntimeGoMatchCore) return rmc, nil } _, err = matchRegistry.CreateMatch(context.Background(), consoleLogger, matchCreateWrapper, "match", nil) if err != nil { t.Fatal(err) } rgmc.MatchLabelUpdate(`{"updated_label": 1}`) matchRegistry.processLabelUpdates(bluge.NewBatch()) matches, err := matchRegistry.ListMatches(context.Background(), 2, wrapperspb.Bool(true), nil, wrapperspb.Int32(0), wrapperspb.Int32(5), wrapperspb.String(`label.updated_label:1`)) if len(matches) != 1 { t.Fatalf("expected one match, got %d", len(matches)) } matchZero := matches[0] if matchZero.MatchId == "" { t.Fatalf("expected non-empty match id, was empty") } if !matchZero.Authoritative { t.Fatalf("expected authoritative match, got non-authoritative") } } // should create authoritative match, list matches with querying func TestMatchRegistryAuthoritativeMatchAndListMatchesWithQueryingAndBoost(t *testing.T) { consoleLogger := loggerForTest(t) Loading