Unverified Commit fcc8f44d authored by Maxim Ivanov's avatar Maxim Ivanov Committed by GitHub
Browse files

Add test to verify that match labels can be updated after its creation. (#770)

parent 6ae76f48
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import (
	"context"
	"encoding/gob"
	"fmt"
	"go.uber.org/atomic"
	"go.uber.org/zap"
	"strings"
	"testing"

@@ -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)