Export the reviewed allowlisted snapshot from private source commit 05928cebd01b586cf9e9d4b8c8537a7605a6068c. This records the exact candidate, bounded capacity result, stateful migration scratch requirement, authenticated batch identity proof, and immediate live acceptance evidence. AI-Assisted: OpenAI Codex Signed-off-by: Cole Speelman <crspeelman@gmail.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package httpserver
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestRefreshHubIsBoundedCoalescedAndOrganizationScoped(t *testing.T) {
|
|
hub := newRefreshHub(2, 1)
|
|
first, removeFirst, err := hub.subscribe("organization-a")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer removeFirst()
|
|
if _, _, err = hub.subscribe("organization-a"); !errors.Is(err, errRefreshCapacity) {
|
|
t.Fatalf("same-organization capacity err=%v", err)
|
|
}
|
|
second, removeSecond, err := hub.subscribe("organization-b")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer removeSecond()
|
|
if _, _, err = hub.subscribe("organization-c"); !errors.Is(err, errRefreshCapacity) {
|
|
t.Fatalf("total capacity err=%v", err)
|
|
}
|
|
|
|
hub.publish("organization-a")
|
|
hub.publish("organization-a")
|
|
select {
|
|
case <-first:
|
|
default:
|
|
t.Fatal("organization A did not receive refresh")
|
|
}
|
|
select {
|
|
case <-first:
|
|
t.Fatal("duplicate refresh was not coalesced")
|
|
default:
|
|
}
|
|
select {
|
|
case <-second:
|
|
t.Fatal("organization B received organization A refresh")
|
|
default:
|
|
}
|
|
|
|
removeFirst()
|
|
if _, removeReplacement, err := hub.subscribe("organization-a"); err != nil {
|
|
t.Fatalf("released capacity was not reusable: %v", err)
|
|
} else {
|
|
removeReplacement()
|
|
}
|
|
}
|