feat: gate allocator roster publication

This commit is contained in:
Josh Creek
2026-09-01 09:55:09 +01:00
parent 8b5b5333c6
commit febc69bdef
5 changed files with 49 additions and 4 deletions
+23
View File
@@ -27,6 +27,16 @@ type durableSpy struct {
err error
}
type rosterSpy struct {
calls int
err error
}
func (r *rosterSpy) PublishRoster(_ context.Context, _ domain.Assignment, _ []domain.SignedJoinAuthorisation, _ func([]byte, []byte) bool) error {
r.calls++
return r.err
}
func (d *durableSpy) RecordProviderAllocation(_ context.Context, allocation domain.Allocation, _ time.Time) (domain.Allocation, error) {
d.calls++
d.allocation = allocation
@@ -52,3 +62,16 @@ func TestServiceDoesNotReturnProviderResultAfterDurableFailure(t *testing.T) {
t.Fatalf("result=%+v err=%v calls=%d", result, err, durable.calls)
}
}
func TestServicePublishesRosterOnlyForAllocatedAssignment(t *testing.T) {
roster := &rosterSpy{}
service := Service{Roster: roster}
assignment := domain.Assignment{Allocation: domain.Allocation{State: domain.ServerAllocated}, Endpoint: "127.0.0.1:7777"}
if err := service.PublishRoster(context.Background(), assignment, []domain.SignedJoinAuthorisation{{Signature: []byte("sig")}}, func([]byte, []byte) bool { return true }); err != nil || roster.calls != 1 {
t.Fatalf("publish err=%v calls=%d", err, roster.calls)
}
assignment.Allocation.State = domain.ServerReady
if err := service.PublishRoster(context.Background(), assignment, nil, nil); err != domain.ErrManifestRejected || roster.calls != 1 {
t.Fatalf("premature publish err=%v calls=%d", err, roster.calls)
}
}