diff --git a/app.go b/app.go index d3523c1445..ae922aa007 100644 --- a/app.go +++ b/app.go @@ -845,7 +845,15 @@ func (app *App) Test(req *http.Request, msTimeout ...int) (resp *http.Response, // Serve conn to server channel := make(chan error) go func() { + var returned bool + defer func() { + if !returned { + channel <- fmt.Errorf("runtime.Goexit() called in handler or server panic") + } + }() + channel <- app.server.ServeConn(conn) + returned = true }() // Wait for callback diff --git a/app_test.go b/app_test.go index c7ce9dccde..716970fbf2 100644 --- a/app_test.go +++ b/app_test.go @@ -16,6 +16,7 @@ import ( "net/http/httptest" "reflect" "regexp" + "runtime" "strings" "testing" "time" @@ -1527,3 +1528,35 @@ func Test_App_UseMountedErrorHandlerForBestPrefixMatch(t *testing.T) { utils.AssertEqual(t, nil, err, "iotuil.ReadAll()") utils.AssertEqual(t, "hi, i'm a custom sub sub fiber error", string(b), "Third fiber Response body") } + +func Test_App_Test_no_timeout_infinitely(t *testing.T) { + var err error + c := make(chan int) + + go func() { + defer func() { c <- 0 }() + app := New() + app.Get("/", func(c *Ctx) error { + runtime.Goexit() + return nil + }) + + req := httptest.NewRequest(http.MethodGet, "/", http.NoBody) + _, err = app.Test(req, -1) + }() + + tk := time.NewTimer(5 * time.Second) + defer tk.Stop() + + select { + case <-tk.C: + t.Error("hanging test") + t.FailNow() + case <-c: + } + + if err == nil { + t.Error("unexpected success request") + t.FailNow() + } +}