MCPcopy
hub / github.com/minio/minio-go / TestPanicDoChan

Function TestPanicDoChan

pkg/singleflight/singleflight_test.go:306–342  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

304}
305
306func TestPanicDoChan(t *testing.T) {
307 if os.Getenv("TEST_PANIC_DOCHAN") != "" {
308 defer func() {
309 recover()
310 }()
311
312 g := new(Group[string, any])
313 ch := g.DoChan("", func() (any, error) {
314 panic("Panicking in DoChan")
315 })
316 <-ch
317 t.Fatalf("DoChan unexpectedly returned")
318 }
319
320 t.Parallel()
321
322 cmd := exec.Command(executable(t), "-test.run="+t.Name(), "-test.v")
323 cmd.Env = append(os.Environ(), "TEST_PANIC_DOCHAN=1")
324 out := new(bytes.Buffer)
325 cmd.Stdout = out
326 cmd.Stderr = out
327 if err := cmd.Start(); err != nil {
328 t.Fatal(err)
329 }
330
331 err := cmd.Wait()
332 t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
333 if err == nil {
334 t.Errorf("Test subprocess passed; want a crash due to panic in DoChan")
335 }
336 if bytes.Contains(out.Bytes(), []byte("DoChan unexpectedly")) {
337 t.Errorf("Test subprocess failed with an unexpected failure mode.")
338 }
339 if !bytes.Contains(out.Bytes(), []byte("Panicking in DoChan")) {
340 t.Errorf("Test subprocess failed, but the crash isn't caused by panicking in DoChan")
341 }
342}
343
344func TestPanicDoSharedByDoChan(t *testing.T) {
345 if os.Getenv("TEST_PANIC_DOCHAN") != "" {

Callers

nothing calls this directly

Calls 3

executableFunction · 0.85
DoChanMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected