MCPcopy
hub / github.com/kubernetes/client-go / TestCachingTokenSourceRace

Function TestCachingTokenSourceRace

transport/token_source_test.go:125–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

123}
124
125func TestCachingTokenSourceRace(t *testing.T) {
126 for i := 0; i < 100; i++ {
127 tts := &testTokenSource{
128 tok: &oauth2.Token{
129 AccessToken: "a",
130 Expiry: time.Now().Add(1000 * time.Hour),
131 },
132 }
133
134 ts := &cachingTokenSource{
135 now: time.Now,
136 base: tts,
137 leeway: 1 * time.Minute,
138 }
139
140 var wg sync.WaitGroup
141 wg.Add(100)
142
143 for i := 0; i < 100; i++ {
144 go func() {
145 defer wg.Done()
146 if _, err := ts.Token(); err != nil {
147 t.Fatalf("err: %v", err)
148 }
149 }()
150 }
151 wg.Wait()
152 if tts.calls != 1 {
153 t.Errorf("expected one call to Token() but saw: %d", tts.calls)
154 }
155 }
156}

Callers

nothing calls this directly

Calls 5

TokenMethod · 0.95
AddMethod · 0.65
NowMethod · 0.65
DoneMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected