(t *testing.T)
| 232 | } |
| 233 | |
| 234 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…