oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

1package hub
2
3import (
4 "strings"
5 "testing"
6 "time"
7)
8
9// Spec §15.26: the tags are random, a call's are shared, and a token is
10// good for its participation and ten minutes after, and is swept then.
11func TestReportTokensTagsAndTheAfterLeaveWindow(t *testing.T) {
12 now := time.Date(2026, 10, 3, 15, 40, 0, 0, time.UTC)
13 h := testHub(&now)
14 a, _ := h.Open("r1", "sessA", 1, "Ann", KindMember)
15 b, _ := h.Open("r1", "sessB", 2, "Bob", KindMember)
16 if a.ReportToken == "" || a.ReportToken == b.ReportToken {
17 t.Fatalf("tokens %q %q", a.ReportToken, b.ReportToken)
18 }
19 ra, ok := h.Reporter("r1", "sessA", a.ReportToken)
20 rb, _ := h.Reporter("r1", "sessB", b.ReportToken)
21 if !ok || !ra.Live || ra.CallTag != rb.CallTag || ra.PeerTag == rb.PeerTag || len(ra.CallTag) != 16 {
22 t.Fatalf("reporters %+v %+v", ra, rb)
23 }
24 for _, tag := range []string{ra.CallTag, ra.PeerTag} {
25 for _, s := range []string{"r1", "sessA", "Ann", string(a.Peer)} {
26 if strings.Contains(tag, s) || strings.Contains(s, tag) {
27 t.Fatalf("tag %q derived from %q", tag, s)
28 }
29 }
30 }
31 if ra.Peers[b.Peer] != rb.PeerTag {
32 t.Fatalf("A's reporter maps B to %q, want %q", ra.Peers[b.Peer], rb.PeerTag)
33 }
34 if _, ok := h.Reporter("r1", "sessB", a.ReportToken); ok {
35 t.Fatal("another session's token was honoured")
36 }
37 if _, ok := h.Reporter("r2", "sessA", a.ReportToken); ok {
38 t.Fatal("a token was honoured for another room")
39 }
40 if err := h.Leave("r1", "sessA", a.Peer); err != nil {
41 t.Fatal(err)
42 }
43 if r, ok := h.Reporter("r1", "sessA", a.ReportToken); !ok || r.Live {
44 t.Fatalf("just after leaving: %+v %v, want an ended grant", r, ok)
45 }
46 now = now.Add(ReportAfterLeave + time.Second)
47 h.Tick(testCtx)
48 h.mu.Lock()
49 _, kept := h.reports[a.ReportToken]
50 n := len(h.reports)
51 h.mu.Unlock()
52 if kept || n != 1 {
53 t.Fatalf("after the window: kept %v, %d grants, want A's swept and B's live one left", kept, n)
54 }
55}
56
57// The token table is bounded: past maxReportGrants the grant that ended
58// longest ago goes first, and a live one never does.
59func TestReportGrantsAreBounded(t *testing.T) {
60 now := time.Date(2026, 10, 3, 15, 40, 0, 0, time.UTC)
61 h := testHub(&now)
62 live, _ := h.Open("keep", "sessLive", 1, "Ann", KindMember)
63 for i := 0; i < maxReportGrants+10; i++ {
64 now = now.Add(time.Millisecond)
65 res, err := h.Open("r1", "s", int64(i%3), "x", KindMember)
66 if err != nil {
67 t.Fatal(err)
68 }
69 if err := h.Leave("r1", "s", res.Peer); err != nil {
70 t.Fatal(err)
71 }
72 }
73 h.mu.Lock()
74 n := len(h.reports)
75 h.mu.Unlock()
76 if n > maxReportGrants {
77 t.Fatalf("%d grants, bound %d", n, maxReportGrants)
78 }
79 if _, ok := h.Reporter("keep", "sessLive", live.ReportToken); !ok {
80 t.Fatal("a live participation's token was evicted")
81 }
82}
83