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
9 changes: 7 additions & 2 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,13 @@ func (p *Peer) Ready() bool {
}

// Wait until Settle() has finished.
func (p *Peer) WaitReady() {
<-p.readyc
func (p *Peer) WaitReady(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
case <-p.readyc:
return nil
}
}

// Return a status string representing the peer state.
Expand Down
11 changes: 8 additions & 3 deletions cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ func testJoinLeave(t *testing.T) {
)
require.NoError(t, err)
require.False(t, p.Ready())
{
ctx, cancel := context.WithCancel(context.Background())
cancel()
require.Equal(t, context.Canceled, p.WaitReady(ctx))
}
require.Equal(t, p.Status(), "settling")
go p.Settle(context.Background(), 0*time.Second)
p.WaitReady()
require.NoError(t, p.WaitReady(context.Background()))
require.Equal(t, p.Status(), "ready")

// Create the peer who joins the first.
Expand Down Expand Up @@ -119,7 +124,7 @@ func testReconnect(t *testing.T) {
)
require.NoError(t, err)
go p.Settle(context.Background(), 0*time.Second)
p.WaitReady()
require.NoError(t, p.WaitReady(context.Background()))

p2, err := Create(
logger,
Expand All @@ -142,7 +147,7 @@ func testReconnect(t *testing.T) {
)
require.NoError(t, err)
go p2.Settle(context.Background(), 0*time.Second)
p2.WaitReady()
require.NoError(t, p2.WaitReady(context.Background()))

p.peerJoin(p2.Self())
p.peerLeave(p2.Self())
Expand Down
6 changes: 4 additions & 2 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ResolvedSender interface {
// Peer represents the cluster node from where we are the sending the notification.
type Peer interface {
// WaitReady waits until the node silences and notifications have settled before attempting to send a notification.
WaitReady()
WaitReady(context.Context) error
}

// MinTimeout is the minimum timeout that is set for the context of a call
Expand Down Expand Up @@ -430,7 +430,9 @@ func NewGossipSettleStage(p Peer) *GossipSettleStage {

func (n *GossipSettleStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error) {
if n.peer != nil {
n.peer.WaitReady()
if err := n.peer.WaitReady(ctx); err != nil {
return ctx, nil, err
}
}
return ctx, alerts, nil
}
Expand Down