mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat: gate allocator roster publication
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user