Files
seaweedfs/weed/command/mini_vector_test.go
T
Chris Lu 4901404050 mini: start weed-worker with the vector engine
With -vector, mini now also starts weed-worker, the Lance maintenance
worker that builds vector and metadata indexes, finding it the way it
finds weed-vector: beside weed, then on PATH. -vector.worker=false leaves
it out and -vector.worker.binary names another binary.

The Lance Namespace trusts the worker only by a token derived from
jwt.filer_signing.key. A cluster with that key hands it to the worker
through security.toml as before. Without one, mini makes a key for the
run, gives it to the worker in its environment, and lets the namespace
accept it while no cluster key is set. The filer and the other services
are unaffected, so unauthenticated filer writes keep working.
2026-11-30 23:42:33 -08:00

64 lines
2.5 KiB
Go

package command
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func TestPrepareMiniVectorWorker(t *testing.T) {
oldVector, oldWorker, oldBinary, oldPath, oldKey := *miniVector, *miniVectorWorker, *miniVectorWorkerBinary, miniVectorWorkerPath, miniS3Options.lanceWorkerKey
defer func() {
*miniVector, *miniVectorWorker, *miniVectorWorkerBinary, miniVectorWorkerPath, miniS3Options.lanceWorkerKey = oldVector, oldWorker, oldBinary, oldPath, oldKey
}()
dir := t.TempDir()
worker, missing := filepath.Join(dir, "weed-worker"), filepath.Join(dir, "missing")
if err := os.WriteFile(worker, []byte("#!/bin/sh\n"), 0755); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", dir)
t.Setenv("WEED_JWT_FILER_SIGNING_KEY", "")
defer util.GetViper().Set("jwt.filer_signing.key", "")
for _, tc := range []struct {
name string
vector, start bool
binary string
clusterKey string
wantWorker string
wantKey bool
}{
{"installed", true, true, "weed-worker", "", worker, true},
{"cluster key configured", true, true, "weed-worker", "cluster-key", worker, false},
{"not installed", true, true, missing, "", "", false},
{"-vector.worker=false", true, false, "weed-worker", "", "", false},
{"without -vector", false, true, "weed-worker", "", "", false},
} {
*miniVector, *miniVectorWorker, *miniVectorWorkerBinary = tc.vector, tc.start, tc.binary
miniVectorWorkerPath, miniS3Options.lanceWorkerKey = "", nil
util.GetViper().Set("jwt.filer_signing.key", tc.clusterKey)
prepareMiniVectorWorker()
if miniVectorWorkerPath != tc.wantWorker || (len(miniS3Options.lanceWorkerKey) == 64) != tc.wantKey {
t.Errorf("%s: worker %q, key length %d", tc.name, miniVectorWorkerPath, len(miniS3Options.lanceWorkerKey))
}
}
}
func TestMiniVectorRejectsExplicitListenerConflict(t *testing.T) {
oldVector, oldPort, oldMetrics, oldFlags := *miniVector, *miniVectorPort, *miniVectorMetricsPort, explicitFlags
defer func() {
*miniVector, *miniVectorPort, *miniVectorMetricsPort, explicitFlags = oldVector, oldPort, oldMetrics, oldFlags
}()
*miniVector = true
*miniVectorPort = 8090
*miniVectorMetricsPort = 8090
explicitFlags = map[string]bool{"vector.port": true, "vector.metricsPort": true}
err := ensureAllPortsAvailableOnIP("127.0.0.1", false)
if err == nil || !strings.Contains(err.Error(), "shared by explicit flags vector.port and vector.metricsPort") {
t.Fatalf("listener conflict not rejected: %v", err)
}
}