fix(multiplayer): bound adapter HTTP calls

This commit is contained in:
Josh Creek
2026-09-02 19:12:40 +01:00
parent cbefa86c5c
commit 1bce603c33
5 changed files with 36 additions and 11 deletions
+5 -2
View File
@@ -106,7 +106,10 @@ type Supervisor struct {
lastGameServer GameServer
}
const DefaultDrainGrace = 285 * time.Second
const (
DefaultDrainGrace = 285 * time.Second
DefaultHTTPTimeout = 10 * time.Second
)
func New(config Config) (*Supervisor, error) {
if len(config.Command) == 0 || config.Command[0] == "" {
@@ -131,7 +134,7 @@ func New(config Config) (*Supervisor, error) {
return nil, fmt.Errorf("unsupported transport %q", config.Transport)
}
if config.HTTPClient == nil {
config.HTTPClient = http.DefaultClient
config.HTTPClient = &http.Client{Timeout: DefaultHTTPTimeout}
}
if (config.DrainURL == "") != (config.DrainToken == "") {
return nil, fmt.Errorf("drain URL and token must be configured together")
+10
View File
@@ -13,6 +13,16 @@ import (
"time"
)
func TestSupervisorDefaultHTTPClientHasRequestDeadline(t *testing.T) {
supervisor, err := New(Config{Command: []string{"game-server"}})
if err != nil {
t.Fatal(err)
}
if supervisor.client == http.DefaultClient || supervisor.client.Timeout != DefaultHTTPTimeout || supervisor.client.Timeout <= 0 {
t.Fatalf("default HTTP client timeout = %s", supervisor.client.Timeout)
}
}
func TestWithAllocatedConfigOverridesAuthoritativeChildFlags(t *testing.T) {
command := []string{
"game-server", "--", "--allocated-mode", "--match-id=stale-match",