| 255 | } |
| 256 | |
| 257 | func TestGoexitDo(t *testing.T) { |
| 258 | var g Group[string, any] |
| 259 | fn := func() (any, error) { |
| 260 | runtime.Goexit() |
| 261 | return nil, nil |
| 262 | } |
| 263 | |
| 264 | const n = 5 |
| 265 | waited := int32(n) |
| 266 | done := make(chan struct{}) |
| 267 | for i := 0; i < n; i++ { |
| 268 | go func() { |
| 269 | var err error |
| 270 | defer func() { |
| 271 | if err != nil { |
| 272 | t.Errorf("Error should be nil, but got: %v", err) |
| 273 | } |
| 274 | if atomic.AddInt32(&waited, -1) == 0 { |
| 275 | close(done) |
| 276 | } |
| 277 | }() |
| 278 | _, err, _ = g.Do("key", fn) |
| 279 | }() |
| 280 | } |
| 281 | |
| 282 | select { |
| 283 | case <-done: |
| 284 | case <-time.After(time.Second): |
| 285 | t.Fatalf("Do hangs") |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | func executable(t testing.TB) string { |
| 290 | exe, err := os.Executable() |