Skip to content

Commit

Permalink
fix: bootstrap state machine goes idle after completion
Browse files Browse the repository at this point in the history
  • Loading branch information
iand committed Sep 27, 2023
1 parent dedca86 commit 6c8e7a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions v2/internal/coord/routing/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (b *Bootstrap[K, N]) advanceQuery(ctx context.Context, qev query.QueryEvent
}
case *query.StateQueryFinished[K, N]:
span.SetAttributes(attribute.String("out_state", "StateBootstrapFinished"))
b.qry = nil
return &StateBootstrapFinished{
Stats: st.Stats,
}
Expand Down
38 changes: 38 additions & 0 deletions v2/internal/coord/routing/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,41 @@ func TestBootstrapProgress(t *testing.T) {
require.Equal(t, 4, stf.Stats.Requests)
require.Equal(t, 4, stf.Stats.Success)
}

func TestBootstrapFinishesThenGoesIdle(t *testing.T) {
ctx := context.Background()
clk := clock.NewMock()
cfg := DefaultBootstrapConfig()
cfg.Clock = clk

self := tiny.NewNode(0)
bs, err := NewBootstrap[tiny.Key](self, cfg)
require.NoError(t, err)

a := tiny.NewNode(0b00000100) // 4

// start the bootstrap
state := bs.Advance(ctx, &EventBootstrapStart[tiny.Key, tiny.Node]{
KnownClosestNodes: []tiny.Node{a},
})
require.IsType(t, &StateBootstrapFindCloser[tiny.Key, tiny.Node]{}, state)

// the bootstrap should attempt to contact the node it was given
st := state.(*StateBootstrapFindCloser[tiny.Key, tiny.Node])
require.Equal(t, coordt.QueryID("bootstrap"), st.QueryID)
require.Equal(t, a, st.NodeID)

// notify bootstrap that node was contacted successfully, but no closer nodes
state = bs.Advance(ctx, &EventBootstrapFindCloserResponse[tiny.Key, tiny.Node]{
NodeID: a,
})

// bootstrap should respond that its query has finished
require.IsType(t, &StateBootstrapFinished{}, state)

// poll bootstrap
state = bs.Advance(ctx, &EventBootstrapPoll{})

// bootstrap should now be idle
require.IsType(t, &StateBootstrapIdle{}, state)
}

0 comments on commit 6c8e7a0

Please sign in to comment.