feat: runtime bootstrap snapshot cache with backoff
This commit is contained in:
1 parent
08f60a14d1
commit
aa6bb23e24
19 files changed
+1400
-384
No files matched your search
@@ -6,22 +6,25 @@ import (
|
||||
)
|
||||
|
||||
func TestLoadDefaults(t *testing.T) {
|
||||
for _, key := range []string{"PORT", "DATA_DIR", "FASTAPI_URL", "CONTROL_USER", "CONTROL_PASS", "CONTROL_TOKEN", "SSE_HEARTBEAT", "ML_TIMEOUT"} {
|
||||
for _, key := range []string{
|
||||
"PORT", "FASTAPI_URL", "CONTROL_USER", "CONTROL_PASS", "CONTROL_TOKEN",
|
||||
"SSE_HEARTBEAT", "ML_TIMEOUT", "BOOTSTRAP_REFRESH", "BOOTSTRAP_TIMEOUT",
|
||||
} {
|
||||
t.Setenv(key, "")
|
||||
}
|
||||
cfg := Load()
|
||||
if cfg.Addr != ":8080" {
|
||||
t.Errorf("Addr=%q", cfg.Addr)
|
||||
}
|
||||
if cfg.DataDir != "testdata/data" {
|
||||
t.Errorf("DataDir=%q", cfg.DataDir)
|
||||
}
|
||||
if cfg.FastAPIURL != "http://localhost:8000" {
|
||||
t.Errorf("FastAPIURL=%q", cfg.FastAPIURL)
|
||||
}
|
||||
if cfg.Heartbeat != 15*time.Second || cfg.MLTimeout != 1500*time.Millisecond {
|
||||
t.Errorf("timeouts: heartbeat=%s ml=%s", cfg.Heartbeat, cfg.MLTimeout)
|
||||
}
|
||||
if cfg.RefreshInterval != 60*time.Second || cfg.BootstrapTimeout != 20*time.Second {
|
||||
t.Errorf("snapshot: refresh=%s timeout=%s", cfg.RefreshInterval, cfg.BootstrapTimeout)
|
||||
}
|
||||
if cfg.ControlAuthConfigured() {
|
||||
t.Error("control auth should be unconfigured by default")
|
||||
}
|
||||
@@ -32,16 +35,17 @@ func TestLoadDefaults(t *testing.T) {
|
||||
|
||||
func TestLoadFromEnv(t *testing.T) {
|
||||
t.Setenv("PORT", "9999")
|
||||
t.Setenv("DATA_DIR", "/data")
|
||||
t.Setenv("FASTAPI_URL", "http://ml:8000")
|
||||
t.Setenv("CONTROL_USER", "user")
|
||||
t.Setenv("CONTROL_PASS", "pass")
|
||||
t.Setenv("CONTROL_TOKEN", "token-123")
|
||||
t.Setenv("SSE_HEARTBEAT", "5s")
|
||||
t.Setenv("ML_TIMEOUT", "2s")
|
||||
t.Setenv("BOOTSTRAP_REFRESH", "30s")
|
||||
t.Setenv("BOOTSTRAP_TIMEOUT", "10s")
|
||||
|
||||
cfg := Load()
|
||||
if cfg.Addr != ":9999" || cfg.DataDir != "/data" || cfg.FastAPIURL != "http://ml:8000" {
|
||||
if cfg.Addr != ":9999" || cfg.FastAPIURL != "http://ml:8000" {
|
||||
t.Fatalf("cfg=%+v", cfg)
|
||||
}
|
||||
if cfg.ControlToken != "token-123" {
|
||||
@@ -50,6 +54,9 @@ func TestLoadFromEnv(t *testing.T) {
|
||||
if cfg.Heartbeat != 5*time.Second || cfg.MLTimeout != 2*time.Second {
|
||||
t.Fatalf("timeouts: heartbeat=%s ml=%s", cfg.Heartbeat, cfg.MLTimeout)
|
||||
}
|
||||
if cfg.RefreshInterval != 30*time.Second || cfg.BootstrapTimeout != 10*time.Second {
|
||||
t.Fatalf("snapshot: refresh=%s timeout=%s", cfg.RefreshInterval, cfg.BootstrapTimeout)
|
||||
}
|
||||
if !cfg.ControlAuthConfigured() {
|
||||
t.Fatal("control auth should be configured")
|
||||
}
|
||||
@@ -58,17 +65,27 @@ func TestLoadFromEnv(t *testing.T) {
|
||||
func TestDurationAcceptsPlainSeconds(t *testing.T) {
|
||||
t.Setenv("SSE_HEARTBEAT", "7")
|
||||
t.Setenv("ML_TIMEOUT", "3")
|
||||
t.Setenv("BOOTSTRAP_REFRESH", "45")
|
||||
t.Setenv("BOOTSTRAP_TIMEOUT", "12")
|
||||
cfg := Load()
|
||||
if cfg.Heartbeat != 7*time.Second || cfg.MLTimeout != 3*time.Second {
|
||||
t.Fatalf("timeouts: heartbeat=%s ml=%s", cfg.Heartbeat, cfg.MLTimeout)
|
||||
}
|
||||
if cfg.RefreshInterval != 45*time.Second || cfg.BootstrapTimeout != 12*time.Second {
|
||||
t.Fatalf("snapshot: refresh=%s timeout=%s", cfg.RefreshInterval, cfg.BootstrapTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDurationFallsBackOnInvalidValue(t *testing.T) {
|
||||
t.Setenv("SSE_HEARTBEAT", "soon")
|
||||
t.Setenv("ML_TIMEOUT", "-1s")
|
||||
t.Setenv("BOOTSTRAP_REFRESH", "later")
|
||||
t.Setenv("BOOTSTRAP_TIMEOUT", "-3s")
|
||||
cfg := Load()
|
||||
if cfg.Heartbeat != 15*time.Second || cfg.MLTimeout != 1500*time.Millisecond {
|
||||
t.Fatalf("timeouts: heartbeat=%s ml=%s", cfg.Heartbeat, cfg.MLTimeout)
|
||||
}
|
||||
if cfg.RefreshInterval != 60*time.Second || cfg.BootstrapTimeout != 20*time.Second {
|
||||
t.Fatalf("snapshot: refresh=%s timeout=%s", cfg.RefreshInterval, cfg.BootstrapTimeout)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user