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)
| 940 | // goroutines re-registering under the same id. The registry must remain |
| 941 | // bounded and the surviving callback must still be invoked exactly once. |
| 942 | func 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 |