Skip to content

Commit

Permalink
diff
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 6, 2022
1 parent 9c6c7da commit e70e758
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app.go
Expand Up @@ -845,7 +845,16 @@ func (app *App) Test(req *http.Request, msTimeout ...int) (resp *http.Response,
// Serve conn to server
channel := make(chan error)
go func() {
channel <- app.server.ServeConn(conn)
var returned bool
defer func() {
if !returned {
channel <- fmt.Errorf("runtime.Goexit() called in handler")
}
}()

r := app.server.ServeConn(conn)
returned = true
channel <- r
}()

// Wait for callback
Expand Down
33 changes: 33 additions & 0 deletions app_test.go
Expand Up @@ -16,6 +16,7 @@ import (
"net/http/httptest"
"reflect"
"regexp"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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) {
start := time.Now()
var err error
c := make(chan bool)
go func() {
time.Sleep(5 * time.Second)
c <- true
}()
go func() {
defer close(c)
app := New()
app.Get("/", func(c *Ctx) error {
runtime.Goexit()
return nil
})

req := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
_, err = app.Test(req, -1)
}()

<-c

if time.Since(start) >= time.Second {
t.Error("hanging test")
t.FailNow()
}
if err == nil {
t.Error("unexpected success request")
t.FailNow()
}
}

0 comments on commit e70e758

Please sign in to comment.