MCPcopy
hub / github.com/github/gh-ost / TestSetAbortError_ThreadSafe

Function TestSetAbortError_ThreadSafe

go/base/context_test.go:234–272  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func TestSetAbortError_ThreadSafe(t *testing.T) {
235 ctx := NewMigrationContext()
236
237 var wg sync.WaitGroup
238 errs := []error{
239 errors.New("error 1"),
240 errors.New("error 2"),
241 errors.New("error 3"),
242 }
243
244 // Launch 3 goroutines trying to set error concurrently
245 for _, err := range errs {
246 wg.Add(1)
247 go func(e error) {
248 defer wg.Done()
249 ctx.SetAbortError(e)
250 }(err)
251 }
252
253 wg.Wait()
254
255 // Should store exactly one of the errors
256 got := ctx.GetAbortError()
257 if got == nil {
258 t.Fatal("Expected error to be stored, got nil")
259 }
260
261 // Verify it's one of the errors we sent
262 found := false
263 for _, err := range errs {
264 if got == err { //nolint:errorlint // Testing pointer equality for sentinel error
265 found = true
266 break
267 }
268 }
269 if !found {
270 t.Errorf("Stored error %v not in list of sent errors", got)
271 }
272}

Callers

nothing calls this directly

Calls 5

SetAbortErrorMethod · 0.95
GetAbortErrorMethod · 0.95
NewMigrationContextFunction · 0.85
FatalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…