mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test: use the neutral primary host throughout shell fixtures
This commit is contained in:
1 parent
e4458de5cd
commit
1d5bb78c14
1 file changed
+26
-6
@@ -45,7 +45,7 @@ func requireInspectionOutput(t *testing.T, raw []byte) map[string]inspectionResu
|
||||
}
|
||||
|
||||
func TestShellClusterStatusReadsTheMasterWithoutKubernetes(t *testing.T) {
|
||||
addr, closeMaster := startCmdFakeMaster(t)
|
||||
addr, closeMaster := startInspectionMaster(t)
|
||||
defer closeMaster()
|
||||
var out, errout bytes.Buffer
|
||||
code := run([]string{"shell", "-master", addr, "-c", "cluster.status -o json"}, &out, &errout)
|
||||
@@ -61,6 +61,22 @@ func TestShellClusterStatusReadsTheMasterWithoutKubernetes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func startInspectionMaster(t *testing.T) (string, func()) {
|
||||
t.Helper()
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := grpc.NewServer()
|
||||
control.RegisterEvidenceServiceServer(srv, cmdFakeEvidenceServer{})
|
||||
control.RegisterClusterEvidenceServiceServer(srv, inspectionControlServer{})
|
||||
go func() { _ = srv.Serve(ln) }()
|
||||
return ln.Addr().String(), func() {
|
||||
srv.Stop()
|
||||
_ = ln.Close()
|
||||
}
|
||||
}
|
||||
|
||||
type inspectionControlServer struct {
|
||||
cmdFakeClusterEvidenceServer
|
||||
control.UnimplementedWorkspaceServiceServer
|
||||
@@ -70,7 +86,11 @@ type inspectionControlServer struct {
|
||||
func (s inspectionControlServer) GetClusterStatus(ctx context.Context, q *control.GetClusterStatusRequest) (*control.ClusterStatusResponse, error) {
|
||||
r, err := s.cmdFakeClusterEvidenceServer.GetClusterStatus(ctx, q)
|
||||
r.Volumes[0].ReplicationFactor = 1
|
||||
r.Volumes[0].PrimaryNode = "host-b"
|
||||
r.Volumes[0].Replicas = []*control.ReplicaEvidence{{ReplicaId: "r2", ServerId: "host-b", Observed: true}}
|
||||
for _, event := range r.Events {
|
||||
event.NodeName = "host-b"
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
func (s inspectionControlServer) QueryWorkspace(_ context.Context, q *control.WorkspaceVolume) (*control.WorkspaceStatus, error) {
|
||||
@@ -246,10 +266,10 @@ func TestShellCheckUsesTypedLeaseReadinessCutAndVersionAnswers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type futureInspectionMaster struct{ cmdFakeClusterEvidenceServer }
|
||||
type futureInspectionMaster struct{ inspectionControlServer }
|
||||
|
||||
func (futureInspectionMaster) GetClusterStatus(ctx context.Context, q *control.GetClusterStatusRequest) (*control.ClusterStatusResponse, error) {
|
||||
r, err := (cmdFakeClusterEvidenceServer{}).GetClusterStatus(ctx, q)
|
||||
r, err := (inspectionControlServer{}).GetClusterStatus(ctx, q)
|
||||
r.CapturedAt = timestamppb.New(time.Date(3000, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||
return r, err
|
||||
}
|
||||
@@ -272,7 +292,7 @@ func TestShellClockCannotCallAnOverflowingDifferenceOK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShellCheckNeverCallsOffHostChecksOK(t *testing.T) {
|
||||
addr, closeMaster := startCmdFakeMaster(t)
|
||||
addr, closeMaster := startInspectionMaster(t)
|
||||
defer closeMaster()
|
||||
var out, errout bytes.Buffer
|
||||
var requests atomic.Int32
|
||||
@@ -326,7 +346,7 @@ func TestShellCheckCuresAndOrderMatchTheTroubleshootingPage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShellReadsQuotedCommandsFromStdinAndKeepsFailures(t *testing.T) {
|
||||
addr, closeMaster := startCmdFakeMaster(t)
|
||||
addr, closeMaster := startInspectionMaster(t)
|
||||
defer closeMaster()
|
||||
var out, errout bytes.Buffer
|
||||
code := runShell([]string{"-master", addr}, strings.NewReader("volume.delete 'v1'\nvolume.status 'v1' -o json\nquit\n"), &out, &errout)
|
||||
@@ -341,7 +361,7 @@ func TestShellReadsQuotedCommandsFromStdinAndKeepsFailures(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShellCheckRefusesWrongHolderAndDoesNotFollowStatusRedirects(t *testing.T) {
|
||||
addr, closeMaster := startCmdFakeMaster(t)
|
||||
addr, closeMaster := startInspectionMaster(t)
|
||||
defer closeMaster()
|
||||
for _, mode := range []string{"missing", "wrong-epoch", "missing-readiness", "redirect"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user