mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-06 22:51:58 +00:00
* Fixes for some of the failing tests * Add readiness check to serverStart() * Use net/http client for tests listen test * Use different key for this test * Run Proxy Middleware tests in parallel. Add nil checks for potential issues pointed by nilaway * Enable parallel client tests * Do not run timing sensitive tests in parallel * Remove TODO * Revert Test_Proxy_DoTimeout_Timeout, and remove t.Parallel() for it * Do not calculate favicon len on each handler call * Revert logic change * Increase timeout of SaveFile tests * Do not run time sensitive tests in parallel * The Agent can't be run in parallel * Do not run time sensitive tests in parallel * Fixes based on uber/nilaway * Revert change to Client test * Run parallel * Update client_test.go * Update client_test.go * Update cache_test.go * Update cookiejar_test.go * Remove parallel for test using timeouts * Remove t.Parallel() from logger middleware tests * Do not use testify.require in a goroutine * Fix import, and update golangci-lint * Remove changes to template_chain.go * Run more tests in parallel * Add more parallel tests * Add more parallel tests * SetLogger can't run in parallel * Run more tests in parallel, fix issue with goroutine in limiter middleware * Update internal/storage/memory, add more benchmarks * Increase sleep for csrf test by 100 milliseconds. Implement asserted and parallel benchmarks for Session middleware * Add 100 milliseconds to sleep during test * Revert name change * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests * fix: Inconsistent and flaky unit-tests --------- Co-authored-by: M. Efe Çetin <efectn@protonmail.com> Co-authored-by: René <rene@gofiber.io>
106 lines
2.3 KiB
Go
106 lines
2.3 KiB
Go
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
|
|
// 📄 Github Repository: https://github.com/gofiber/fiber
|
|
// 📌 API Documentation: https://docs.gofiber.io
|
|
// 💖 Maintained and modified for Fiber by @renewerner87
|
|
package fiber
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_App_Prefork_Child_Process(t *testing.T) {
|
|
// Reset test var
|
|
testPreforkMaster = true
|
|
|
|
setupIsChild(t)
|
|
defer teardownIsChild(t)
|
|
|
|
app := New()
|
|
|
|
err := app.prefork("invalid", nil, listenConfigDefault())
|
|
require.Error(t, err)
|
|
|
|
go func() {
|
|
time.Sleep(1000 * time.Millisecond)
|
|
assert.NoError(t, app.Shutdown())
|
|
}()
|
|
|
|
require.NoError(t, app.prefork("[::1]:", nil, ListenConfig{ListenerNetwork: NetworkTCP6}))
|
|
|
|
// Create tls certificate
|
|
cer, err := tls.LoadX509KeyPair("./.github/testdata/ssl.pem", "./.github/testdata/ssl.key")
|
|
if err != nil {
|
|
require.NoError(t, err)
|
|
}
|
|
//nolint:gosec // We're in a test so using old ciphers is fine
|
|
config := &tls.Config{Certificates: []tls.Certificate{cer}}
|
|
|
|
go func() {
|
|
time.Sleep(1000 * time.Millisecond)
|
|
assert.NoError(t, app.Shutdown())
|
|
}()
|
|
|
|
require.NoError(t, app.prefork("127.0.0.1:", config, listenConfigDefault()))
|
|
}
|
|
|
|
func Test_App_Prefork_Master_Process(t *testing.T) {
|
|
// Reset test var
|
|
testPreforkMaster = true
|
|
|
|
app := New()
|
|
|
|
go func() {
|
|
time.Sleep(1000 * time.Millisecond)
|
|
assert.NoError(t, app.Shutdown())
|
|
}()
|
|
|
|
require.NoError(t, app.prefork(":3000", nil, listenConfigDefault()))
|
|
|
|
dummyChildCmd.Store("invalid")
|
|
|
|
err := app.prefork("127.0.0.1:", nil, listenConfigDefault())
|
|
require.Error(t, err)
|
|
|
|
dummyChildCmd.Store("go")
|
|
}
|
|
|
|
func Test_App_Prefork_Child_Process_Never_Show_Startup_Message(t *testing.T) {
|
|
setupIsChild(t)
|
|
defer teardownIsChild(t)
|
|
|
|
rescueStdout := os.Stdout
|
|
defer func() { os.Stdout = rescueStdout }()
|
|
|
|
r, w, err := os.Pipe()
|
|
require.NoError(t, err)
|
|
|
|
os.Stdout = w
|
|
|
|
New().startupProcess().startupMessage(":3000", false, "", listenConfigDefault())
|
|
|
|
require.NoError(t, w.Close())
|
|
|
|
out, err := io.ReadAll(r)
|
|
require.NoError(t, err)
|
|
require.Empty(t, out)
|
|
}
|
|
|
|
func setupIsChild(t *testing.T) {
|
|
t.Helper()
|
|
|
|
require.NoError(t, os.Setenv(envPreforkChildKey, envPreforkChildVal))
|
|
}
|
|
|
|
func teardownIsChild(t *testing.T) {
|
|
t.Helper()
|
|
|
|
require.NoError(t, os.Setenv(envPreforkChildKey, ""))
|
|
}
|