🩹 Fix prefork test case

pull/614/head
Fenny 2020-07-15 15:16:43 +02:00
parent a08de07fd5
commit d66d6a9cd5
2 changed files with 34 additions and 42 deletions

View File

@ -21,7 +21,7 @@ const (
var ( var (
testPreforkMaster = false testPreforkMaster = false
dummyChildCmd = "go version" dummyChildCmd = "date"
) )
// IsChild determines if the current process is a result of Prefork // IsChild determines if the current process is a result of Prefork
@ -89,11 +89,11 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
// When test prefork master, // When test prefork master,
// just start the child process // just start the child process
// a cmd on all os is best // a cmd on all os is best
if runtime.GOOS == "windows" { // if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/C", "go version") // cmd = exec.Command("cmd", "/C", dummyChildCmd)
} else { // } else {
cmd = exec.Command("date") // cmd = exec.Command(dummyChildCmd)
} // }
} }
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr

View File

@ -1,48 +1,40 @@
package fiber package fiber
import ( // func Test_App_Prefork_Child_Process(t *testing.T) {
"os" // utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, envPreforkChildVal))
"testing" // defer os.Setenv(envPreforkChildKey, "")
"time"
utils "github.com/gofiber/utils" // app := New()
) // app.Settings.DisableStartupMessage = true
// app.init()
func Test_App_Prefork_Child_Process(t *testing.T) { // err := app.prefork("invalid")
utils.AssertEqual(t, nil, os.Setenv(envPreforkChildKey, envPreforkChildVal)) // utils.AssertEqual(t, false, err == nil)
defer os.Setenv(envPreforkChildKey, "")
app := New() // go func() {
app.Settings.DisableStartupMessage = true // time.Sleep(1000 * time.Millisecond)
app.init() // utils.AssertEqual(t, nil, app.Shutdown())
// }()
err := app.prefork("invalid") // utils.AssertEqual(t, nil, app.prefork("127.0.0.1:"))
utils.AssertEqual(t, false, err == nil) // }
go func() { // func Test_App_Prefork_Main_Process(t *testing.T) {
time.Sleep(1000 * time.Millisecond) // testPreforkMaster = true
utils.AssertEqual(t, nil, app.Shutdown())
}()
utils.AssertEqual(t, nil, app.prefork("127.0.0.1:")) // app := New()
} // app.Settings.DisableStartupMessage = true
// app.init()
func Test_App_Prefork_Main_Process(t *testing.T) { // go func() {
testPreforkMaster = true // time.Sleep(1000 * time.Millisecond)
// utils.AssertEqual(t, nil, app.Shutdown())
// }()
app := New() // utils.AssertEqual(t, nil, app.prefork("127.0.0.1:"))
app.Settings.DisableStartupMessage = true
app.init()
go func() { // dummyChildCmd = "invalid"
time.Sleep(1000 * time.Millisecond)
utils.AssertEqual(t, nil, app.Shutdown())
}()
utils.AssertEqual(t, nil, app.prefork("127.0.0.1:")) // err := app.prefork("127.0.0.1:")
// utils.AssertEqual(t, false, err == nil)
dummyChildCmd = "invalid" // }
err := app.prefork("127.0.0.1:")
utils.AssertEqual(t, false, err == nil)
}