oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1package web
2
3import (
4 "context"
5 "log/slog"
6 "testing"
7 "time"
8)
9
10// Capabilities are worked out under the member's lock: never while one of
11// their clients is half recorded (Astra round 3).
12func TestAskCapsWaitsForRecord(t *testing.T) {
13 a := &app{logger: slog.New(slog.DiscardHandler)}
14 a.clientRecorded(7, "client", false)
15 m := a.memberLock(7)
16 m.Lock()
17 done := make(chan []string, 1)
18 go func() { done <- a.askCaps(context.Background(), 7) }()
19 select {
20 case <-done:
21 t.Fatal("askCaps didn't wait for the member's record")
22 case <-time.After(50 * time.Millisecond):
23 }
24 m.Unlock()
25 if got := <-done; got != nil {
26 t.Errorf("a held member's capabilities: %v", got)
27 }
28}
29
30// A hold on a client Base couldn't record lasts as long as a client's
31// word does, 30 days, and no longer (Astra round 3).
32func TestAskCapsHoldExpires(t *testing.T) {
33 a := &app{logger: slog.New(slog.DiscardHandler)}
34 a.clientRecorded(7, "client", false)
35 if !a.clientsDown(7) || a.clientsDown(8) {
36 t.Fatal("hold not kept for its member alone")
37 }
38 a.unrecorded.mu.Lock()
39 a.unrecorded.held[7]["client"] = time.Now().Add(-clientWindow - time.Minute)
40 a.unrecorded.mu.Unlock()
41 if a.clientsDown(7) {
42 t.Error("a hold outlived the client window")
43 }
44}
45