| 1 | package hub |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | "time" |
| 7 | ) |
| 8 | |
| 9 | // AdmittedCount is the drive surface's one window into a live room |
| 10 | // (spec §8.2): how many peers are actually in the call, and never who |
| 11 | // they are. A room nobody has opened is zero rather than an error — |
| 12 | // the caller holds a meeting row, and a meeting with no room is simply |
| 13 | // a meeting nobody has entered. |
| 14 | func TestAdmittedCountCountsAdmittedOnlyAndNeverAWaitingGuest(t *testing.T) { |
| 15 | now := time.Date(2026, 9, 11, 9, 0, 0, 0, time.UTC) |
| 16 | h := testHub(&now) |
| 17 | ctx := context.Background() |
| 18 | |
| 19 | if n := h.AdmittedCount("r1"); n != 0 { |
| 20 | t.Fatalf("a room nobody has opened: %d, want 0", n) |
| 21 | } |
| 22 | |
| 23 | m, err := h.Open("r1", "sm", 1, "Mia", KindMember) |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | if n := h.AdmittedCount("r1"); n != 0 { |
| 28 | t.Fatalf("an unjoined participation counts: %d, want 0", n) |
| 29 | } |
| 30 | if err := h.Join(ctx, "r1", "sm", m.Peer); err != nil { |
| 31 | t.Fatal(err) |
| 32 | } |
| 33 | if n := h.AdmittedCount("r1"); n != 1 { |
| 34 | t.Fatalf("a joined member: %d, want 1", n) |
| 35 | } |
| 36 | |
| 37 | g, err := h.Open("r1", "sg", 100, "Gus", KindGuest) |
| 38 | if err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | if err := h.Join(ctx, "r1", "sg", g.Peer); err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | if n := h.AdmittedCount("r1"); n != 1 { |
| 45 | t.Fatalf("a waiting guest is counted: %d, want 1", n) |
| 46 | } |
| 47 | |
| 48 | if err := h.Admit(ctx, "r1", "sm", m.Peer, g.Peer); err != nil { |
| 49 | t.Fatal(err) |
| 50 | } |
| 51 | if n := h.AdmittedCount("r1"); n != 2 { |
| 52 | t.Fatalf("after admitting the guest: %d, want 2", n) |
| 53 | } |
| 54 | if n := h.AdmittedCount("r2"); n != 0 { |
| 55 | t.Fatalf("another room's count leaked: %d, want 0", n) |
| 56 | } |
| 57 | |
| 58 | if err := h.Leave("r1", "sg", g.Peer); err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | if n := h.AdmittedCount("r1"); n != 1 { |
| 62 | t.Fatalf("after the guest left: %d, want 1", n) |
| 63 | } |
| 64 | } |
| 65 | |