Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 10 additions & 4 deletions internal/broker/diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ---------------------------------------------------------------------------
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
50 changes: 30 additions & 20 deletions internal/broker/evaluate_queue_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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}
Expand Down
33 changes: 21 additions & 12 deletions internal/cmd/recover/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,20 +61,20 @@ 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")
}

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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")
}
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/monitor/monitor_amqp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
18 changes: 9 additions & 9 deletions internal/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
Loading
Loading