Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 7 additions & 36 deletions test/server/auto_head_options_engines_421_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,41 +303,12 @@ func startServer421(t *testing.T, eng celeris.EngineType, setup func(*celeris.Se
// chosen here).
func startServerConfig421(t *testing.T, cfg celeris.Config, setup func(*celeris.Server)) string {
t.Helper()
retryUntil := time.Now().Add(30 * time.Second)
for tries := 1; ; tries++ {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
cfg.Addr = addr
s := celeris.New(cfg)
// setup comes first (it may call Server.Use); the listener is handed to the
// server, so the port cannot be taken between the pick and the bind
// (celeris#1104, startPicked1104).
_, addr := startPickedPing1104(t, cfg, func(s *celeris.Server) {
setup(s)
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
startDone := make(chan error, 1)
go func() { startDone <- s.Start() }()
err = waitReady761(addr, startDone)
if err == nil {
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = s.Shutdown(ctx)
select {
case <-startDone:
case <-time.After(15 * time.Second):
t.Errorf("Start did not return within 15s of Shutdown")
}
})
return addr
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_ = s.Shutdown(ctx)
cancel()
if isRingENOMEM(err) && time.Now().Before(retryUntil) {
time.Sleep(20 * time.Millisecond)
continue
}
t.Fatalf("server did not start (try %d): %v", tries, err)
}
ping1104(s)
})
return addr
}
41 changes: 6 additions & 35 deletions test/server/bodylimit_default_889_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,42 +69,13 @@ var bodyCfgs889 = []bodyCfg889{
// the number of body bytes the handler saw.
func bodyServer889(t *testing.T, eng celeris.EngineType, limit int64) string {
t.Helper()
retryUntil := time.Now().Add(30 * time.Second)
for tries := 1; ; tries++ {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
s := celeris.New(celeris.Config{Addr: addr, Engine: eng, Protocol: celeris.Auto, MaxRequestBodySize: limit})
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
// The listener is handed to the server, so the port cannot be taken between
// the pick and the bind (celeris#1104, startPicked1104).
_, addr := startPickedPing1104(t, celeris.Config{Engine: eng, Protocol: celeris.Auto, MaxRequestBodySize: limit}, func(s *celeris.Server) {
ping1104(s)
s.POST("/up", func(c *celeris.Context) error { return c.String(http.StatusOK, "n=%d", len(c.Body())) })
startDone := make(chan error, 1)
go func() { startDone <- s.Start() }()
err = waitReady761(addr, startDone)
if err == nil {
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = s.Shutdown(ctx)
select {
case <-startDone:
case <-time.After(15 * time.Second):
t.Errorf("Start did not return within 15s of Shutdown")
}
})
return addr
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_ = s.Shutdown(ctx)
cancel()
if isRingENOMEM(err) && time.Now().Before(retryUntil) {
time.Sleep(20 * time.Millisecond)
continue
}
t.Fatalf("server did not start (try %d): %v", tries, err)
}
})
return addr
}

const bodyUpgradeHead889 = "POST /up HTTP/1.1\r\nHost: a\r\nConnection: Upgrade, HTTP2-Settings\r\nUpgrade: h2c\r\n" +
Expand Down
42 changes: 6 additions & 36 deletions test/server/chunked_promotion_889_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,19 @@ var enginesNative889 = []struct {
// the body length, a sync GET /ping and an Async() GET /slow, on one engine.
func start889(t *testing.T, cfg celeris.Config, extra ...func(*celeris.Server)) (string, *celeris.Server) {
t.Helper()
retryUntil := time.Now().Add(30 * time.Second)
for tries := 1; ; tries++ {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
cfg.Addr = addr
s := celeris.New(cfg)
// The listener is handed to the server, so the port cannot be taken between
// the pick and the bind (celeris#1104, startPicked1104).
s, addr := startPickedPing1104(t, cfg, func(s *celeris.Server) {
up := func(c *celeris.Context) error { return c.String(http.StatusOK, "n=%d", len(c.Body())) }
s.POST("/up", up)
s.POST("/aup", up).Async()
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
ping1104(s)
s.GET("/slow", func(c *celeris.Context) error { return c.String(http.StatusOK, "slow") }).Async()
for _, f := range extra {
f(s)
}
startDone := make(chan error, 1)
go func() { startDone <- s.Start() }()
err = waitReady761(addr, startDone)
if err == nil {
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = s.Shutdown(ctx)
select {
case <-startDone:
case <-time.After(15 * time.Second):
t.Errorf("Start did not return within 15s of Shutdown")
}
})
return addr, s
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_ = s.Shutdown(ctx)
cancel()
if strings.Contains(err.Error(), "cannot allocate memory") && time.Now().Before(retryUntil) {
time.Sleep(20 * time.Millisecond)
continue
}
t.Fatalf("server did not start (try %d): %v", tries, err)
}
})
return addr, s
}

func get889(t *testing.T, c net.Conn, br *bufio.Reader, path string) string {
Expand Down
43 changes: 6 additions & 37 deletions test/server/detect_split_first_segment_870_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package celeris_test

import (
"bufio"
"context"
"encoding/binary"
"fmt"
"io"
Expand Down Expand Up @@ -74,16 +73,9 @@ func startServer870(t *testing.T, cfg celeris.Config) string {
// that reads its metrics.
func startServerSrv870(t *testing.T, cfg celeris.Config) (string, *celeris.Server) {
t.Helper()
retryUntil := time.Now().Add(30 * time.Second)
for tries := 1; ; tries++ {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
cfg.Addr = addr
s := celeris.New(cfg)
// The listener is handed to the server, so the port cannot be taken between
// the pick and the bind (celeris#1104, startPicked1104).
s, addr := startPickedPing1104(t, cfg, func(s *celeris.Server) {
// With AsyncHandlers on, a route that only answers runs inline and its conn
// is never promoted to a dispatch goroutine (AsyncPromotedConns stays 0), so
// the route is marked async: the conn is promoted at its first request and
Expand All @@ -92,35 +84,12 @@ func startServerSrv870(t *testing.T, cfg celeris.Config) (string, *celeris.Serve
if cfg.AsyncHandlers {
h.Async()
}
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
ping1104(s)
s.POST("/len", func(c *celeris.Context) error {
return c.String(http.StatusOK, "%d", len(c.Body()))
})
startDone := make(chan error, 1)
go func() { startDone <- s.Start() }()
err = waitReady761(addr, startDone)
if err == nil {
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = s.Shutdown(ctx)
select {
case <-startDone:
case <-time.After(15 * time.Second):
t.Errorf("Start did not return within 15s of Shutdown")
}
})
return addr, s
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_ = s.Shutdown(ctx)
cancel()
if isRingENOMEM(err) && time.Now().Before(retryUntil) {
time.Sleep(20 * time.Millisecond)
continue
}
t.Fatalf("server did not start (try %d): %v", tries, err)
}
})
return addr, s
}

// sendPieces870 dials addr and writes each piece as its own segment, pieceGap870
Expand Down
41 changes: 6 additions & 35 deletions test/server/h2_stream_context_836_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,40 +477,11 @@ func TestH2CUnmatchedThroughTimeoutSingleflight836(t *testing.T) {
// readiness probe /ping is registered after it.
func startGlobalChainServer836(t *testing.T, cfg celeris.Config, setup func(*celeris.Server)) string {
t.Helper()
retryUntil := time.Now().Add(30 * time.Second)
for {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
cfg.Addr = addr
s := celeris.New(cfg)
// The listener is handed to the server, so the port cannot be taken between
// the pick and the bind (celeris#1104, startPicked1104).
_, addr := startPickedPing1104(t, cfg, func(s *celeris.Server) {
setup(s)
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
startDone := make(chan error, 1)
go func() { startDone <- s.Start() }()
if err = waitReady761(addr, startDone); err == nil {
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = s.Shutdown(ctx)
select {
case <-startDone:
case <-time.After(15 * time.Second):
t.Errorf("Start did not return within 15s of Shutdown")
}
})
return addr
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_ = s.Shutdown(ctx)
cancel()
if isRingENOMEM(err) && time.Now().Before(retryUntil) {
time.Sleep(20 * time.Millisecond)
continue
}
t.Fatalf("server did not start: %v", err)
}
ping1104(s)
})
return addr
}
43 changes: 6 additions & 37 deletions test/server/h2upgrade_disabled_964_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package celeris_test

import (
"bufio"
"context"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -36,43 +35,13 @@ func bptr964(v bool) *bool { return &v }
// whatever cfg says (the zero value is Auto).
func startServer964(t *testing.T, cfg celeris.Config) string {
t.Helper()
retryUntil := time.Now().Add(30 * time.Second)
for tries := 1; ; tries++ {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close()
cfg.Addr = addr
s := celeris.New(cfg)
// The listener is handed to the server, so the port cannot be taken between
// the pick and the bind (celeris#1104, startPicked1104).
_, addr := startPickedPing1104(t, cfg, func(s *celeris.Server) {
s.GET("/h", func(c *celeris.Context) error { return c.String(http.StatusOK, "h1-answer") })
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
startDone := make(chan error, 1)
go func() { startDone <- s.Start() }()
err = waitReady761(addr, startDone)
if err == nil {
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = s.Shutdown(ctx)
select {
case <-startDone:
case <-time.After(15 * time.Second):
t.Errorf("Start did not return within 15s of Shutdown")
}
})
return addr
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_ = s.Shutdown(ctx)
cancel()
if isRingENOMEM(err) && time.Now().Before(retryUntil) {
time.Sleep(20 * time.Millisecond)
continue
}
t.Fatalf("server did not start (try %d): %v", tries, err)
}
ping1104(s)
})
return addr
}

// TestEnableH2UpgradeFalseDisablesUpgradeOnAuto964 drives celeris#964 on every
Expand Down
7 changes: 5 additions & 2 deletions test/server/iouring_async_cancel_refusal_886_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ func TestServerAdaptiveStartsOnEpollWhenIOUringRefused886(t *testing.T) {
if err != nil {
t.Fatalf("listen: %v", err)
}
// The listener is handed to the server, not closed and bound again: adaptive
// gives it to the epoll fallback when the io_uring start engine is refused
// before Listen, and the port is not free between the pick and the bind
// until that engine rebinds it (celeris#1104).
addr := ln.Addr().String()
_ = ln.Close()

var logs lockedBuf886
s := celeris.New(celeris.Config{
Expand All @@ -133,7 +136,7 @@ func TestServerAdaptiveStartsOnEpollWhenIOUringRefused886(t *testing.T) {
s.GET("/ping", func(c *celeris.Context) error { return c.String(http.StatusOK, "ok") })
ctx, cancel := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() { done <- s.StartWithContext(ctx) }()
go func() { done <- s.StartWithListenerAndContext(ctx, ln) }()
defer func() {
cancel()
sctx, scancel := context.WithTimeout(context.Background(), 10*time.Second)
Expand Down
Loading
Loading