Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bootstrap state machine goes idle after completion #943

Merged
merged 1 commit into from
Sep 27, 2023
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
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)
}