MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestStorage_AuthorizeCode_ConcurrentConsume

Function TestStorage_AuthorizeCode_ConcurrentConsume

internal/oauth/storage_test.go:137–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestStorage_AuthorizeCode_ConcurrentConsume(t *testing.T) {
138 st, _, _, userID, clientID := setup(t)
139 ctx := context.Background()
140 now := time.Now().UTC().Truncate(time.Second)
141
142 req := newRequester("req-conc", clientID, userID, now)
143 if err := st.CreateAuthorizeCodeSession(ctx, "code-conc", req); err != nil {
144 t.Fatalf("CreateAuthorizeCodeSession: %v", err)
145 }
146
147 const N = 16
148 var (
149 wg sync.WaitGroup
150 successes atomic.Int32
151 invalidated atomic.Int32
152 other atomic.Int32
153 start = make(chan struct{})
154 )
155 wg.Add(N)
156 for i := 0; i < N; i++ {
157 go func() {
158 defer wg.Done()
159 <-start
160 err := st.InvalidateAuthorizeCodeSession(ctx, "code-conc")
161 switch {
162 case err == nil:
163 successes.Add(1)
164 case errors.Is(err, fosite.ErrInvalidatedAuthorizeCode):
165 invalidated.Add(1)
166 default:
167 other.Add(1)
168 t.Errorf("unexpected error: %v", err)
169 }
170 }()
171 }
172 close(start)
173 wg.Wait()
174
175 if got := successes.Load(); got != 1 {
176 t.Errorf("successes = %d, want 1 (only one consume should win)", got)
177 }
178 if got := invalidated.Load(); got != N-1 {
179 t.Errorf("invalidated = %d, want %d", got, N-1)
180 }
181 if got := other.Load(); got != 0 {
182 t.Errorf("other = %d, want 0", got)
183 }
184}
185
186func TestStorage_RotateRefreshToken_ConcurrentRotate(t *testing.T) {
187 st, _, _, userID, clientID := setup(t)

Callers

nothing calls this directly

Calls 5

setupFunction · 0.85
newRequesterFunction · 0.85
makeFunction · 0.85

Tested by

no test coverage detected