mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
prepareMiniVector returned early without clearing the paths and key an earlier run in the same process had set, so a rerun with -vector.worker=false still started that run's weed-worker.
69 lines
3.2 KiB
Go
69 lines
3.2 KiB
Go
package command
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
)
|
|
|
|
func TestPrepareMiniVector(t *testing.T) {
|
|
oldVector, oldVectorBinary, oldWorker, oldWorkerBinary := *miniVector, *miniVectorBinary, *miniVectorWorker, *miniVectorWorkerBinary
|
|
oldPaths, oldKey := [2]string{miniVectorPath, miniVectorWorkerPath}, miniS3Options.lanceWorkerKey
|
|
defer func() {
|
|
*miniVector, *miniVectorBinary, *miniVectorWorker, *miniVectorWorkerBinary = oldVector, oldVectorBinary, oldWorker, oldWorkerBinary
|
|
miniVectorPath, miniVectorWorkerPath, miniS3Options.lanceWorkerKey = oldPaths[0], oldPaths[1], oldKey
|
|
}()
|
|
dir := t.TempDir()
|
|
for _, name := range []string{"weed-vector", "weed-worker"} {
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte("#!/bin/sh\n"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
vector, worker, missing := filepath.Join(dir, "weed-vector"), filepath.Join(dir, "weed-worker"), filepath.Join(dir, "missing")
|
|
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, startWorker bool
|
|
vectorBinary, workerBinary string
|
|
clusterKey string
|
|
wantVector bool
|
|
wantVectorPath, wantWorker string
|
|
wantKey bool
|
|
}{
|
|
{"both installed", true, true, "weed-vector", "weed-worker", "", true, vector, worker, true},
|
|
{"-vector.worker=false after a run that started it", true, false, "weed-vector", "weed-worker", "", true, vector, "", false},
|
|
{"cluster key configured", true, true, "weed-vector", "weed-worker", "cluster-key", true, vector, worker, false},
|
|
{"weed-worker not installed", true, true, "weed-vector", missing, "", true, vector, "", false},
|
|
{"weed-vector not installed", true, true, missing, "weed-worker", "", false, "", "", false},
|
|
{"-vector=false", false, true, "weed-vector", "weed-worker", "", false, "", "", false},
|
|
} {
|
|
*miniVector, *miniVectorWorker, *miniVectorBinary, *miniVectorWorkerBinary = tc.vector, tc.startWorker, tc.vectorBinary, tc.workerBinary
|
|
util.GetViper().Set("jwt.filer_signing.key", tc.clusterKey)
|
|
prepareMiniVector()
|
|
if *miniVector != tc.wantVector || miniVectorPath != tc.wantVectorPath || miniVectorWorkerPath != tc.wantWorker || (len(miniS3Options.lanceWorkerKey) == 64) != tc.wantKey {
|
|
t.Errorf("%s: vector %v %q, worker %q, key length %d", tc.name, *miniVector, miniVectorPath, 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)
|
|
}
|
|
}
|