mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix(multiplayer): bound adapter HTTP calls
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user