💯 cover prefork error statement

pull/611/head
kiyon 2020-07-15 15:13:02 +08:00
parent 558917f147
commit 1499e2beb2
3 changed files with 17 additions and 19 deletions

View File

@ -17,7 +17,10 @@ const (
envPreforkChildVal = "1"
)
var testPreforkMaster = false
var (
testPreforkMaster = false
dummyChildCmd = "date"
)
// IsChild determines if the current process is a result of Prefork
func (app *App) IsChild() bool {
@ -84,7 +87,7 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
// When test prefork master,
// just start the child process
// a cmd on all os is best
cmd = exec.Command("date")
cmd = exec.Command(dummyChildCmd)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@ -114,9 +117,5 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
}
// return error if child crashes
for sig := range channel {
return sig.err
}
return
return (<-channel).err
}

View File

@ -12,11 +12,12 @@ func Test_App_Prefork_Child_Process(t *testing.T) {
utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, envPreforkChildVal))
defer os.Setenv(envPreforkChildKey, "")
app := New(&Settings{
DisableStartupMessage: true,
})
app := New()
app.init()
err := app.prefork("invalid")
utils.AssertEqual(t, false, err == nil)
go func() {
time.Sleep(1000 * time.Millisecond)
utils.AssertEqual(t, nil, app.Shutdown())
@ -28,9 +29,7 @@ func Test_App_Prefork_Child_Process(t *testing.T) {
func Test_App_Prefork_Main_Process(t *testing.T) {
testPreforkMaster = true
app := New(&Settings{
DisableStartupMessage: true,
})
app := New()
app.init()
go func() {
@ -39,4 +38,9 @@ func Test_App_Prefork_Main_Process(t *testing.T) {
}()
utils.AssertEqual(t, nil, app.prefork("127.0.0.1:"))
dummyChildCmd = "invalid"
err := app.prefork("127.0.0.1:")
utils.AssertEqual(t, false, err == nil)
}

View File

@ -4,7 +4,6 @@ package fiber
import (
"net"
"strings"
tcplisten "github.com/valyala/tcplisten"
)
@ -38,9 +37,5 @@ func reuseport(network, addr string) (net.Listener, error) {
DeferAccept: true,
FastOpen: true,
}
ln, err := cfg.NewListener(network, addr)
if err != nil && strings.Contains(err.Error(), "SO_REUSEPORT") {
return nil, err
}
return ln, err
return cfg.NewListener(network, addr)
}