carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "context"
5 "testing"
6 "time"
7
8 "github.com/carlosframework/platform/internal/hostactors"
9 "github.com/carlosframework/platform/internal/hostbox"
10 "github.com/carlosframework/platform/internal/hostops"
11 "github.com/carlosframework/platform/internal/release"
12)
13
14type plan9ResetListingStore struct {
15 release.Store
16 calls chan time.Time
17}
18
19func (s *plan9ResetListingStore) List(ctx context.Context, prefix string) ([]string, error) {
20 select {
21 case s.calls <- time.Now():
22 default:
23 }
24 return nil, ctx.Err()
25}
26func TestPlan9Fix1ResetWorkerAppliesBackoff(t *testing.T) {
27 t.Parallel()
28 store := &plan9ResetListingStore{Store: release.NewDirStore(t.TempDir()), calls: make(chan time.Time, 4)}
29 identity := handoverRecoveryIdentity(t, hostbox.Actor{Box: "box-1", Enrollment: "enrollment-1", Revision: 1, Binding: "1", Region: "ie"})
30 a := &ClaimAssembly{Mode: "agent", Identity: identity, Claims: store, RetirementAuthority: &hostops.ProductionAuthority{Directory: hostactors.Directory{Store: store}}, Wake: &ClaimWakeAssembly{}, Launches: &hostbox.LaunchJournal{}, Close: func(context.Context) error { return nil }}
31 if err := a.startWakeResetWorker(t.Context()); err != nil {
32 t.Fatal(err)
33 }
34 defer a.Close(context.Background())
35 var first time.Time
36 select {
37 case first = <-store.calls:
38 case <-time.After(3 * time.Second):
39 t.Fatal("worker never listed resets")
40 }
41 select {
42 case second := <-store.calls:
43 if elapsed := second.Sub(first); elapsed < 1500*time.Millisecond {
44 t.Fatalf("idle worker still lists every second: interval=%s", elapsed)
45 }
46 case <-time.After(4 * time.Second):
47 t.Fatal("worker stopped polling instead of backing off")
48 }
49}
50