MCPcopy Index your code
hub / github.com/github/github-mcp-server / TestAuthenticateSingleFlight

Function TestAuthenticateSingleFlight

internal/oauth/manager_test.go:284–321  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

282}
283
284func TestAuthenticateSingleFlight(t *testing.T) {
285 f := newFakeGitHub(t)
286 m := newManager(t, f)
287
288 // Hold the owner inside begin() (browser open blocks) so a concurrent caller
289 // observes the in-progress flow rather than starting its own.
290 entered := make(chan struct{})
291 release := make(chan struct{})
292 var once sync.Once
293 m.openURL = func(u string) error {
294 once.Do(func() { close(entered) })
295 <-release
296 return browserGet(u)
297 }
298
299 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
300 defer cancel()
301
302 ownerDone := make(chan error, 1)
303 go func() {
304 _, err := m.Authenticate(ctx, nil)
305 ownerDone <- err
306 }()
307
308 <-entered // owner is now mid-flow with status "starting"
309
310 out, err := m.Authenticate(ctx, nil)
311 require.NoError(t, err)
312 require.NotNil(t, out.UserAction)
313 assert.Contains(t, out.UserAction.Message, "already in progress")
314
315 close(release)
316 require.NoError(t, <-ownerDone)
317
318 assert.Equal(t, "gho_access", waitForToken(t, m))
319 // Exactly one authorization happened despite the concurrent callers.
320 assert.Equal(t, []string{"authorization_code"}, f.recordedGrants())
321}

Callers

nothing calls this directly

Calls 6

newFakeGitHubFunction · 0.85
newManagerFunction · 0.85
browserGetFunction · 0.85
waitForTokenFunction · 0.85
recordedGrantsMethod · 0.80
AuthenticateMethod · 0.65

Tested by

no test coverage detected