MCPcopy
hub / github.com/redis/go-redis / TestOnCloseHooks_ConcurrentRegisterSameID

Function TestOnCloseHooks_ConcurrentRegisterSameID

internal_test.go:942–963  ·  view source on GitHub ↗

TestOnCloseHooks_ConcurrentRegisterSameID hammers the registry with many goroutines re-registering under the same id. The registry must remain bounded and the surviving callback must still be invoked exactly once.

(t *testing.T)

Source from the content-addressed store, hash-verified

940// goroutines re-registering under the same id. The registry must remain
941// bounded and the surviving callback must still be invoked exactly once.
942func TestOnCloseHooks_ConcurrentRegisterSameID(t *testing.T) {
943 h := &onCloseHooks{}
944 const id = "hot"
945 const goroutines = 64
946 const perG = 1_000
947
948 var wg sync.WaitGroup
949 wg.Add(goroutines)
950 for g := 0; g < goroutines; g++ {
951 go func() {
952 defer wg.Done()
953 for i := 0; i < perG; i++ {
954 h.register(id, func() error { return nil })
955 }
956 }()
957 }
958 wg.Wait()
959
960 if got := len(h.order); got != 1 {
961 t.Fatalf("order length after concurrent storm = %d, want 1", got)
962 }
963}
964
965// entraidLikeProvider mimics the exact semantics of
966// github.com/redis/go-redis-entraid's StreamingCredentialsProvider relevant

Callers

nothing calls this directly

Calls 3

registerMethod · 0.95
WaitMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected