mirror of
https://github.com/pgsty/minio.git
synced 2026-10-05 17:25:59 +03:00
fix(http): honor configured request header deadlines
Signed-off-by: Feng Ruohang <rh@vonng.com> (cherry picked from commit 0d48d32d7e038ae1ea5966f3d7e0cb86780a6311) Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/minio/cli"
|
||||
xhttp "github.com/minio/minio/internal/http"
|
||||
)
|
||||
|
||||
func TestServerReadHeaderTimeoutConfig(t *testing.T) {
|
||||
for _,tc:=range []struct{name,env string;args []string;want time.Duration}{
|
||||
{name:"default",want:xhttp.DefaultReadHeaderTimeout},
|
||||
{name:"flag",args:[]string{"--read-header-timeout=100ms"},want:100*time.Millisecond},
|
||||
{name:"environment",env:"170ms",want:170*time.Millisecond},
|
||||
{name:"flag-over-environment",env:"170ms",args:[]string{"--read-header-timeout=80ms"},want:80*time.Millisecond},
|
||||
{name:"yaml-retains-flag",args:[]string{"--config=testdata/config/1.yaml","--read-header-timeout=100ms"},want:100*time.Millisecond},
|
||||
{name:"zero-fallback",args:[]string{"--read-header-timeout=0s"}},
|
||||
{name:"negative-disabled",args:[]string{"--read-header-timeout=-1s"},want:-time.Second},
|
||||
}{
|
||||
t.Run(tc.name,func(t *testing.T){
|
||||
for _,key:=range []string{"MINIO_ARGS","MINIO_VOLUMES","MINIO_ENDPOINTS","MINIO_CONFIG","MINIO_ERASURE_SET_DRIVE_COUNT"}{t.Setenv(key,"")}
|
||||
t.Setenv("MINIO_READ_HEADER_TIMEOUT",tc.env)
|
||||
if tc.env==""{if err:=os.Unsetenv("MINIO_READ_HEADER_TIMEOUT");err!=nil{t.Fatal(err)}}
|
||||
t.Setenv("MINIO_IDLE_TIMEOUT","2s")
|
||||
var got serverCtxt
|
||||
called:=false
|
||||
app:=cli.NewApp()
|
||||
app.Commands=[]cli.Command{{Name:"server",Flags:serverCmd.Flags,Action:func(ctx *cli.Context)error{called=true;t.Logf("CLI read-header-timeout=%s, expected=%s",ctx.Duration("read-header-timeout"),tc.want);return buildServerCtxt(ctx,&got)}}}
|
||||
args:=append([]string{"silo","server"},tc.args...)
|
||||
args=append(args,t.TempDir())
|
||||
if err:=app.Run(args);err!=nil{t.Fatal(err)}
|
||||
if !called{t.Fatal("server action did not run")}
|
||||
if got.ReadHeaderTimeout!=tc.want{t.Errorf("parsed ReadHeaderTimeout = %s, want %s",got.ReadHeaderTimeout,tc.want)}
|
||||
if got.IdleTimeout!=2*time.Second{t.Errorf("parsed IdleTimeout = %s, want 2s",got.IdleTimeout)}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user