From cd694738aa2378368e39fd27cb6340bceab949a9 Mon Sep 17 00:00:00 2001 From: Dane Hunt Date: Wed, 14 Oct 2026 11:28:16 -0400 Subject: [PATCH 1/2] chore: update ci tools and go version Signed-off-by: Dane Hunt --- .github/workflows/ci.yaml | 10 +++++----- go.mod | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 97979a4..fe86d5b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,7 @@ on: - main - release-* env: - GO_VERSION: 1.26.9 + GO_VERSION: 1.27.2 ARTIFACT_DIR: ./artifacts LINT_DIR: ./.github/linters COV_DIR: ./artifacts/cov @@ -117,7 +117,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.11 + version: latest args: --config=${{ env.LINT_DIR }}/golangci-config.yaml --allow-parallel-runners go-test: @@ -180,8 +180,8 @@ jobs: # https://github.com/vladopajic/go-test-coverage/blob/main/README.md#configuration - name: Check test coverage + uses: vladopajic/go-test-coverage@v2 if: always() id: check-coverage - run: |- - go install github.com/vladopajic/go-test-coverage/v2@v2.19.0 - go-test-coverage --config=${{ env.LINT_DIR }}/testcoverage.yml + with: + config: ${{ env.LINT_DIR }}/testcoverage.yml diff --git a/go.mod b/go.mod index 5636beb..96485e1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/sassoftware/phorcys -go 1.26.9 +go 1.27.2 require ( github.com/DeedleFake/etf v0.0.0-20250818194526-023937b5970e From c86e1e72b13405a813b4e3ee94f04a513c267e6e Mon Sep 17 00:00:00 2001 From: Dane Hunt Date: Wed, 14 Oct 2026 13:21:25 -0400 Subject: [PATCH 2/2] chore: resolve lint errors Signed-off-by: Dane Hunt --- internal/broker/diagnostics_test.go | 14 ++++-- internal/broker/evaluate_queue_health_test.go | 50 +++++++++++-------- internal/cmd/recover/recover_test.go | 33 +++++++----- internal/monitor/monitor_amqp_test.go | 2 + internal/monitor/monitor_test.go | 18 +++---- internal/recovery/consensus_test.go | 19 ++++--- internal/recovery/position_test.go | 20 ++++---- internal/recovery/wal_test.go | 28 +++++++---- 8 files changed, 111 insertions(+), 73 deletions(-) diff --git a/internal/broker/diagnostics_test.go b/internal/broker/diagnostics_test.go index b45c887..12ad313 100644 --- a/internal/broker/diagnostics_test.go +++ b/internal/broker/diagnostics_test.go @@ -15,6 +15,12 @@ import ( "github.com/stretchr/testify/require" ) +// Cluster node names used by the fake management API responses below. +const ( + testNode1 = "rabbit@n1" + testNode2 = "rabbit@n2" +) + // --------------------------------------------------------------------------- // NewDiagnosticsManager // --------------------------------------------------------------------------- @@ -40,8 +46,8 @@ func TestNewDiagnosticsManager_SetsFields(t *testing.T) { func TestFetchNodes_Success(t *testing.T) { nodes := []RabbitNode{ - {Name: "rabbit@n1", Running: true}, - {Name: "rabbit@n2", Running: true}, + {Name: testNode1, Running: true}, + {Name: testNode2, Running: true}, } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err := json.NewEncoder(w).Encode(nodes) @@ -107,7 +113,7 @@ func TestFetchAllQueues_NonOKStatusReturnsError(t *testing.T) { // --------------------------------------------------------------------------- func TestFetchSpecificQueue_Success(t *testing.T) { - queue := RabbitQueue{Name: "target.q", VHost: "/", Type: "quorum", Status: "running", Node: "rabbit@n1"} + queue := RabbitQueue{Name: "target.q", VHost: "/", Type: "quorum", Status: "running", Node: testNode1} server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err := json.NewEncoder(w).Encode(queue) require.NoError(t, err) @@ -154,7 +160,7 @@ func TestFetchSpecificQueue_NonOKNon500ReturnsError(t *testing.T) { func TestResolveQuorumBasePath_UsesFirstNodeName(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.NoError(t, json.NewEncoder(w).Encode([]RabbitNode{{Name: "rabbit@n1"}, {Name: "rabbit@n2"}})) + require.NoError(t, json.NewEncoder(w).Encode([]RabbitNode{{Name: testNode1}, {Name: testNode2}})) })) defer server.Close() diff --git a/internal/broker/evaluate_queue_health_test.go b/internal/broker/evaluate_queue_health_test.go index 1cb8fda..278f69a 100644 --- a/internal/broker/evaluate_queue_health_test.go +++ b/internal/broker/evaluate_queue_health_test.go @@ -17,15 +17,25 @@ import ( "github.com/sassoftware/phorcys/internal/testutil" ) +// Fixture values for the fake RabbitMQ management API responses. These are +// declared here rather than reused from the in-package broker tests because +// this file lives in the external broker_test package. +const ( + testNode = "rabbit@n1" + testTypeQuorum = "quorum" + testStatusRunning = "running" + testStatusDown = "down" +) + // --------------------------------------------------------------------------- // EvaluateQueueHealth // --------------------------------------------------------------------------- func TestEvaluateQueueHealth_Green(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true}} queue := &broker.RabbitQueue{ - Name: "healthy.q", VHost: "/", Type: "quorum", - Status: "running", Leader: "rabbit@n1", Node: "rabbit@n1", + Name: "healthy.q", VHost: "/", Type: testTypeQuorum, + Status: testStatusRunning, Leader: testNode, Node: testNode, } server := testutil.TestHealthServer(t, nodes, queue, 0, nil) defer server.Close() @@ -38,7 +48,7 @@ func TestEvaluateQueueHealth_Green(t *testing.T) { } func TestEvaluateQueueHealth_Transient_MemAlarm(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true, MemAlarm: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true, MemAlarm: true}} server := testutil.TestHealthServer(t, nodes, nil, 0, nil) defer server.Close() @@ -50,7 +60,7 @@ func TestEvaluateQueueHealth_Transient_MemAlarm(t *testing.T) { } func TestEvaluateQueueHealth_Transient_DiskAlarm(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true, DiskFreeAlarm: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true, DiskFreeAlarm: true}} server := testutil.TestHealthServer(t, nodes, nil, 0, nil) defer server.Close() @@ -62,7 +72,7 @@ func TestEvaluateQueueHealth_Transient_DiskAlarm(t *testing.T) { } func TestEvaluateQueueHealth_Unrecoverable_Queue500(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true}} server := testutil.TestHealthServer(t, nodes, nil, http.StatusInternalServerError, nil) defer server.Close() @@ -74,10 +84,10 @@ func TestEvaluateQueueHealth_Unrecoverable_Queue500(t *testing.T) { } func TestEvaluateQueueHealth_Transient_HostNodeDown(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: false}} + nodes := []broker.RabbitNode{{Name: testNode, Running: false}} queue := &broker.RabbitQueue{ - Name: "q1", VHost: "/", Type: "quorum", - Status: "running", Node: "rabbit@n1", + Name: "q1", VHost: "/", Type: testTypeQuorum, + Status: testStatusRunning, Node: testNode, } server := testutil.TestHealthServer(t, nodes, queue, 0, nil) defer server.Close() @@ -90,14 +100,14 @@ func TestEvaluateQueueHealth_Transient_HostNodeDown(t *testing.T) { } func TestEvaluateQueueHealth_Unrecoverable_NoLeaderHealthyNeighbors(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true}} queue := &broker.RabbitQueue{ - Name: "dead.q", VHost: "/", Type: "quorum", - Status: "down", Leader: "", Node: "rabbit@n1", + Name: "dead.q", VHost: "/", Type: testTypeQuorum, + Status: testStatusDown, Leader: "", Node: testNode, } allQueues := []broker.RabbitQueue{ *queue, - {Name: "alive.q", VHost: "/", Type: "quorum", Status: "running", Node: "rabbit@n1"}, + {Name: "alive.q", VHost: "/", Type: testTypeQuorum, Status: testStatusRunning, Node: testNode}, } server := testutil.TestHealthServer(t, nodes, queue, 0, allQueues) defer server.Close() @@ -110,14 +120,14 @@ func TestEvaluateQueueHealth_Unrecoverable_NoLeaderHealthyNeighbors(t *testing.T } func TestEvaluateQueueHealth_Transient_AllNeighborsDown(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true}} queue := &broker.RabbitQueue{ - Name: "q1", VHost: "/", Type: "quorum", - Status: "down", Leader: "", Node: "rabbit@n1", + Name: "q1", VHost: "/", Type: testTypeQuorum, + Status: testStatusDown, Leader: "", Node: testNode, } allQueues := []broker.RabbitQueue{ *queue, - {Name: "q2", VHost: "/", Type: "quorum", Status: "down", Node: "rabbit@n1"}, + {Name: "q2", VHost: "/", Type: testTypeQuorum, Status: testStatusDown, Node: testNode}, } server := testutil.TestHealthServer(t, nodes, queue, 0, allQueues) defer server.Close() @@ -130,10 +140,10 @@ func TestEvaluateQueueHealth_Transient_AllNeighborsDown(t *testing.T) { } func TestEvaluateQueueHealth_Unrecoverable_LeaderNone(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true}} queue := &broker.RabbitQueue{ - Name: "q1", VHost: "/", Type: "quorum", - Status: "down", Leader: "none", Node: "rabbit@n1", + Name: "q1", VHost: "/", Type: testTypeQuorum, + Status: testStatusDown, Leader: "none", Node: testNode, } // no neighbors → neighborsTotal=0, so goes straight to Unrecoverable allQueues := []broker.RabbitQueue{*queue} diff --git a/internal/cmd/recover/recover_test.go b/internal/cmd/recover/recover_test.go index 0e9b7ad..27b4643 100644 --- a/internal/cmd/recover/recover_test.go +++ b/internal/cmd/recover/recover_test.go @@ -20,6 +20,15 @@ import ( "github.com/sassoftware/phorcys/internal/runtime" ) +// Command-line fixtures shared by the RunCommand tests. +const ( + flagQueue = "-queue" + flagVhost = "-vhost" + flagYes = "-yes" + testQueueName = "orders" + testVhost = "prod" +) + type call struct { cfg runtime.Config vhost, queue string @@ -52,12 +61,12 @@ func TestRun_WithYesRunsPipeline(t *testing.T) { calls := stub(t, baseCfg(), nil) var out bytes.Buffer - err := RunCommand(context.Background(), []string{"-queue", "orders", "-vhost", "prod", "-yes"}, strings.NewReader(""), &out) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName, flagVhost, testVhost, flagYes}, strings.NewReader(""), &out) require.NoError(t, err) require.Len(t, *calls, 1) - assert.Equal(t, "prod", (*calls)[0].vhost) - assert.Equal(t, "orders", (*calls)[0].queue) + assert.Equal(t, testVhost, (*calls)[0].vhost) + assert.Equal(t, testQueueName, (*calls)[0].queue) assert.Equal(t, "/q", (*calls)[0].cfg.QuorumBasePath) assert.Contains(t, out.String(), "complete") } @@ -65,7 +74,7 @@ func TestRun_WithYesRunsPipeline(t *testing.T) { func TestRun_DefaultVhost(t *testing.T) { calls := stub(t, baseCfg(), nil) - err := RunCommand(context.Background(), []string{"-queue", "orders", "-yes"}, nil, &bytes.Buffer{}) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName, flagYes}, nil, &bytes.Buffer{}) require.NoError(t, err) require.Len(t, *calls, 1) @@ -77,7 +86,7 @@ func TestRun_ConfirmYes(t *testing.T) { calls := stub(t, baseCfg(), nil) var out bytes.Buffer - err := RunCommand(context.Background(), []string{"-queue", "orders"}, strings.NewReader(answer), &out) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName}, strings.NewReader(answer), &out) require.NoError(t, err) assert.Len(t, *calls, 1, "answer %q", answer) @@ -92,7 +101,7 @@ func TestRun_ConfirmDeclined(t *testing.T) { calls := stub(t, baseCfg(), nil) var out bytes.Buffer - err := RunCommand(context.Background(), []string{"-queue", "orders"}, strings.NewReader(answer), &out) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName}, strings.NewReader(answer), &out) require.NoError(t, err) assert.Empty(t, *calls, "answer %q", answer) @@ -107,7 +116,7 @@ func (errReader) Read([]byte) (int, error) { return 0, errors.New("boom") } func TestRun_ConfirmReadError(t *testing.T) { calls := stub(t, baseCfg(), nil) - err := RunCommand(context.Background(), []string{"-queue", "orders"}, errReader{}, &bytes.Buffer{}) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName}, errReader{}, &bytes.Buffer{}) require.ErrorContains(t, err, "reading confirmation") assert.Empty(t, *calls) @@ -117,7 +126,7 @@ func TestRun_MissingQueue(t *testing.T) { calls := stub(t, baseCfg(), nil) var out bytes.Buffer - err := RunCommand(context.Background(), []string{"-yes"}, nil, &out) + err := RunCommand(context.Background(), []string{flagYes}, nil, &out) require.ErrorContains(t, err, "-queue is required") assert.Empty(t, *calls) @@ -127,7 +136,7 @@ func TestRun_MissingQueue(t *testing.T) { func TestRun_UnexpectedArgs(t *testing.T) { calls := stub(t, baseCfg(), nil) - err := RunCommand(context.Background(), []string{"-queue", "orders", "extra"}, nil, &bytes.Buffer{}) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName, "extra"}, nil, &bytes.Buffer{}) require.ErrorContains(t, err, "unexpected arguments: extra") assert.Empty(t, *calls) @@ -140,13 +149,13 @@ func TestRun_Help(t *testing.T) { err := RunCommand(context.Background(), []string{"-h"}, nil, &out) require.ErrorIs(t, err, flag.ErrHelp) - assert.Contains(t, out.String(), "-queue") + assert.Contains(t, out.String(), flagQueue) } func TestRun_PipelineError(t *testing.T) { stub(t, baseCfg(), errors.New("locate failed")) - err := RunCommand(context.Background(), []string{"-queue", "orders", "-yes"}, nil, &bytes.Buffer{}) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName, flagYes}, nil, &bytes.Buffer{}) require.ErrorContains(t, err, "recovery of //orders failed: locate failed") } @@ -162,7 +171,7 @@ func TestRun_ResolvesQuorumPathWhenUnset(t *testing.T) { cfg.ManagementURL = srv.URL calls := stub(t, cfg, nil) - err := RunCommand(context.Background(), []string{"-queue", "orders", "-yes"}, nil, &bytes.Buffer{}) + err := RunCommand(context.Background(), []string{flagQueue, testQueueName, flagYes}, nil, &bytes.Buffer{}) require.NoError(t, err) require.Len(t, *calls, 1) diff --git a/internal/monitor/monitor_amqp_test.go b/internal/monitor/monitor_amqp_test.go index 66a2b93..c71c0e9 100644 --- a/internal/monitor/monitor_amqp_test.go +++ b/internal/monitor/monitor_amqp_test.go @@ -32,6 +32,8 @@ const ( pollInterval = 5 * time.Millisecond testNode = "rabbit@n1" quorumType = "quorum" + classicType = "classic" + streamType = "stream" ) var healthyNodes = []broker.RabbitNode{{Name: testNode, Running: true}} diff --git a/internal/monitor/monitor_test.go b/internal/monitor/monitor_test.go index 65ee0a0..03f77cd 100644 --- a/internal/monitor/monitor_test.go +++ b/internal/monitor/monitor_test.go @@ -142,10 +142,10 @@ func TestCoalesceLogEvent_Deduplication(t *testing.T) { func TestSyncInventory_OnlyQuorumQueuesCached(t *testing.T) { queues := []broker.RabbitQueue{ - {Name: "q1", VHost: "/", Type: "quorum"}, - {Name: "q2", VHost: "/", Type: "classic"}, - {Name: "q3", VHost: "vh2", Type: "quorum"}, - {Name: "q4", VHost: "/", Type: "stream"}, + {Name: "q1", VHost: "/", Type: quorumType}, + {Name: "q2", VHost: "/", Type: classicType}, + {Name: "q3", VHost: "vh2", Type: quorumType}, + {Name: "q4", VHost: "/", Type: streamType}, } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err := json.NewEncoder(w).Encode(queues) @@ -184,9 +184,9 @@ func TestSyncInventory_EmptyListOnAPIError(t *testing.T) { func TestSyncInventory_ReplacesExistingList(t *testing.T) { // First sync - queues1 := []broker.RabbitQueue{{Name: "old.q", VHost: "/", Type: "quorum"}} + queues1 := []broker.RabbitQueue{{Name: "old.q", VHost: "/", Type: quorumType}} // Second sync returns a different set - queues2 := []broker.RabbitQueue{{Name: "new.q", VHost: "/", Type: "quorum"}} + queues2 := []broker.RabbitQueue{{Name: "new.q", VHost: "/", Type: quorumType}} callN := 0 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -223,10 +223,10 @@ func TestSyncInventory_ReplacesExistingList(t *testing.T) { // --------------------------------------------------------------------------- func TestHealthCheckWorker_GreenReleasesLatch(t *testing.T) { - nodes := []broker.RabbitNode{{Name: "rabbit@n1", Running: true}} + nodes := []broker.RabbitNode{{Name: testNode, Running: true}} queue := &broker.RabbitQueue{ - Name: "ok.q", VHost: "/", Type: "quorum", - Status: "running", Leader: "rabbit@n1", Node: "rabbit@n1", + Name: "ok.q", VHost: "/", Type: quorumType, + Status: "running", Leader: testNode, Node: testNode, } server := testutil.TestHealthServer(t, nodes, queue, 0, nil) defer server.Close() diff --git a/internal/recovery/consensus_test.go b/internal/recovery/consensus_test.go index f67ee6b..649aad5 100644 --- a/internal/recovery/consensus_test.go +++ b/internal/recovery/consensus_test.go @@ -16,11 +16,14 @@ import ( "github.com/sassoftware/phorcys/internal/amqpx/amqptest" ) +// testHostname is the broker host recorded in the consensus fixtures below. +const testHostname = "host1" + func testAnnouncement() RecoveryAnnouncement { return RecoveryAnnouncement{ - Hostname: "host1", + Hostname: testHostname, VHost: "/", - Queue: "orders", + Queue: testQueue, Timestamp: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC), Term: 3, Index: 17, @@ -127,9 +130,9 @@ func TestPublishRecoveryAnnouncement_PublishError(t *testing.T) { func TestPublishRecoveryAnnouncement_UnreachableBrokerReturnsError(t *testing.T) { ann := RecoveryAnnouncement{ - Hostname: "host1", + Hostname: testHostname, VHost: "/", - Queue: "orders", + Queue: testQueue, Timestamp: time.Now(), Term: 1, Index: 2, @@ -142,9 +145,9 @@ func TestPublishRecoveryAnnouncement_UnreachableBrokerReturnsError(t *testing.T) func TestRecoveryAnnouncement_JSONFieldNames(t *testing.T) { ann := RecoveryAnnouncement{ - Hostname: "host1", + Hostname: testHostname, VHost: "/", - Queue: "orders", + Queue: testQueue, Timestamp: time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC), Term: 7, Index: 42, @@ -155,9 +158,9 @@ func TestRecoveryAnnouncement_JSONFieldNames(t *testing.T) { var decoded map[string]any require.NoError(t, json.Unmarshal(body, &decoded)) - assert.Equal(t, "host1", decoded["hostname"]) + assert.Equal(t, testHostname, decoded["hostname"]) assert.Equal(t, "/", decoded["vhost"]) - assert.Equal(t, "orders", decoded["queue"]) + assert.Equal(t, testQueue, decoded["queue"]) assert.Equal(t, float64(7), decoded["term"]) assert.Equal(t, float64(42), decoded["index"]) assert.Equal(t, "2026-01-02T03:04:05Z", decoded["timestamp"]) diff --git a/internal/recovery/position_test.go b/internal/recovery/position_test.go index db31edb..cf6ea81 100644 --- a/internal/recovery/position_test.go +++ b/internal/recovery/position_test.go @@ -66,11 +66,11 @@ func TestLatestQueuePosition_SegmentOnly(t *testing.T) { func TestLatestQueuePosition_WALOnly_FiltersByUID(t *testing.T) { walDir := t.TempDir() writeWALBackup(t, walDir, "0000000000000001.wal", []walEntry{ - {uid: "queue-A", idx: 5, term: 1, data: []byte("a1")}, - {uid: "queue-B", idx: 99, term: 9, data: []byte("b1")}, // higher, but different queue + {uid: testUIDA, idx: 5, term: 1, data: []byte("a1")}, + {uid: testUIDB, idx: 99, term: 9, data: []byte("b1")}, // higher, but different queue }) - pos, found, err := LatestQueuePosition("", walDir, "queue-A") + pos, found, err := LatestQueuePosition("", walDir, testUIDA) require.NoError(t, err) require.True(t, found) assert.Equal(t, RaftPosition{Idx: 5, Term: 1}, pos) @@ -83,10 +83,10 @@ func TestLatestQueuePosition_CombinesSegmentAndWAL_HigherTermWins(t *testing.T) {idx: 1000, term: 1, data: []byte("seg")}, }) writeWALBackup(t, walDir, "0000000000000001.wal", []walEntry{ - {uid: "queue-A", idx: 2, term: 3, data: []byte("wal")}, // lower idx but newer term + {uid: testUIDA, idx: 2, term: 3, data: []byte("wal")}, // lower idx but newer term }) - pos, found, err := LatestQueuePosition(segDir, walDir, "queue-A") + pos, found, err := LatestQueuePosition(segDir, walDir, testUIDA) require.NoError(t, err) require.True(t, found) assert.Equal(t, RaftPosition{Idx: 2, Term: 3}, pos) @@ -99,10 +99,10 @@ func TestLatestQueuePosition_CombinesSegmentAndWAL_SegmentWinsOnTermTie(t *testi {idx: 50, term: 2, data: []byte("seg")}, }) writeWALBackup(t, walDir, "0000000000000001.wal", []walEntry{ - {uid: "queue-A", idx: 10, term: 2, data: []byte("wal")}, + {uid: testUIDA, idx: 10, term: 2, data: []byte("wal")}, }) - pos, found, err := LatestQueuePosition(segDir, walDir, "queue-A") + pos, found, err := LatestQueuePosition(segDir, walDir, testUIDA) require.NoError(t, err) require.True(t, found) assert.Equal(t, RaftPosition{Idx: 50, Term: 2}, pos) @@ -149,10 +149,10 @@ func TestLatestQueuePosition_CorruptedWALFileSkippedNotFatal(t *testing.T) { walDir := t.TempDir() require.NoError(t, os.WriteFile(filepath.Join(walDir, "0000000000000001.wal"), []byte{0xe0, 0xfa, 0x32, 0xb1}, 0600)) writeWALBackup(t, walDir, "0000000000000002.wal", []walEntry{ - {uid: "queue-A", idx: 3, term: 1, data: []byte("good")}, + {uid: testUIDA, idx: 3, term: 1, data: []byte("good")}, }) - pos, found, err := LatestQueuePosition("", walDir, "queue-A") + pos, found, err := LatestQueuePosition("", walDir, testUIDA) require.NoError(t, err) require.True(t, found) assert.Equal(t, RaftPosition{Idx: 3, Term: 1}, pos) @@ -176,7 +176,7 @@ func TestLatestQueuePosition_AllWALFilesCorrupted_NotFoundNoError(t *testing.T) walDir := t.TempDir() require.NoError(t, os.WriteFile(filepath.Join(walDir, "0000000000000001.wal"), []byte{0xe0, 0xfa, 0x32, 0xb1}, 0600)) - pos, found, err := LatestQueuePosition("", walDir, "queue-A") + pos, found, err := LatestQueuePosition("", walDir, testUIDA) require.NoError(t, err) assert.False(t, found) assert.Equal(t, RaftPosition{}, pos) diff --git a/internal/recovery/wal_test.go b/internal/recovery/wal_test.go index 8e9f2ce..3dc2310 100644 --- a/internal/recovery/wal_test.go +++ b/internal/recovery/wal_test.go @@ -19,6 +19,14 @@ import ( // testWALPath is the shared WAL fixture used by all integration tests. const testWALPath = "testdata/0000000000000002.wal" +// Synthetic queue UIDs used by the hand-built WAL and segment fixtures in the +// WAL and position tests. +const ( + testUIDSingle = "myqueue" + testUIDA = "queue-A" + testUIDB = "queue-B" +) + // Known properties of the fixture WAL file. const ( fixtureUID1 = "2F_TESXJJVE92WTS2H" @@ -71,9 +79,9 @@ func TestParseWALRecords_EmptyWAL(t *testing.T) { func TestParseWALRecords_SingleUID_AllRecords(t *testing.T) { entries := []walEntry{ - {uid: "myqueue", idx: 1, term: 1, data: []byte("data-a")}, - {uid: "myqueue", idx: 2, term: 1, data: []byte("data-b")}, - {uid: "myqueue", idx: 3, term: 2, data: []byte("data-c")}, + {uid: testUIDSingle, idx: 1, term: 1, data: []byte("data-a")}, + {uid: testUIDSingle, idx: 2, term: 1, data: []byte("data-b")}, + {uid: testUIDSingle, idx: 3, term: 2, data: []byte("data-c")}, } path := writeTmp(t, buildWAL(entries, "", false)) @@ -81,25 +89,25 @@ func TestParseWALRecords_SingleUID_AllRecords(t *testing.T) { require.NoError(t, err) require.Len(t, recs, 3) for i, r := range recs { - assert.Equalf(t, "myqueue", r.UID, "[%d] UID = %q, want %q", i, r.UID, "myqueue") + assert.Equalf(t, testUIDSingle, r.UID, "[%d] UID = %q, want %q", i, r.UID, testUIDSingle) assert.Equalf(t, uint64(i+1), r.Idx, "[%d] Idx = %d, want %d", i, r.Idx, i+1) } } func TestParseWALRecords_FilterByUID(t *testing.T) { entries := []walEntry{ - {uid: "queue-A", idx: 1, term: 1, data: []byte("a1")}, - {uid: "queue-B", idx: 1, term: 1, data: []byte("b1")}, - {uid: "queue-A", idx: 2, term: 1, data: []byte("a2")}, - {uid: "queue-B", idx: 2, term: 1, data: []byte("b2")}, + {uid: testUIDA, idx: 1, term: 1, data: []byte("a1")}, + {uid: testUIDB, idx: 1, term: 1, data: []byte("b1")}, + {uid: testUIDA, idx: 2, term: 1, data: []byte("a2")}, + {uid: testUIDB, idx: 2, term: 1, data: []byte("b2")}, } path := writeTmp(t, buildWAL(entries, "", false)) - recs, err := ParseWALRecords(path, "queue-A") + recs, err := ParseWALRecords(path, testUIDA) require.NoError(t, err) require.Len(t, recs, 2) for _, r := range recs { - assert.Equal(t, "queue-A", r.UID, "got record for wrong UID") + assert.Equal(t, testUIDA, r.UID, "got record for wrong UID") } }