package web import ( "context" "log/slog" "testing" "time" ) // Capabilities are worked out under the member's lock: never while one of // their clients is half recorded (Astra round 3). func TestAskCapsWaitsForRecord(t *testing.T) { a := &app{logger: slog.New(slog.DiscardHandler)} a.clientRecorded(7, "client", false) m := a.memberLock(7) m.Lock() done := make(chan []string, 1) go func() { done <- a.askCaps(context.Background(), 7) }() select { case <-done: t.Fatal("askCaps didn't wait for the member's record") case <-time.After(50 * time.Millisecond): } m.Unlock() if got := <-done; got != nil { t.Errorf("a held member's capabilities: %v", got) } } // A hold on a client Base couldn't record lasts as long as a client's // word does, 30 days, and no longer (Astra round 3). func TestAskCapsHoldExpires(t *testing.T) { a := &app{logger: slog.New(slog.DiscardHandler)} a.clientRecorded(7, "client", false) if !a.clientsDown(7) || a.clientsDown(8) { t.Fatal("hold not kept for its member alone") } a.unrecorded.mu.Lock() a.unrecorded.held[7]["client"] = time.Now().Add(-clientWindow - time.Minute) a.unrecorded.mu.Unlock() if a.clientsDown(7) { t.Error("a hold outlived the client window") } }