mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-11-16 17:34:23 +08:00
feat: add optional sequential port allocation with atomic reservations
Adapt the port allocation option from #583 by xigua761 without its commercial licensing changes. Serialize forward, chain, peer runtime, cleanup and import reservations across SQLite/PostgreSQL instances. Co-authored-by: xigua761 <xigua1166@outlook.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package handler
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeSequentialPortConfigValue(t *testing.T) {
|
||||
for in, want := range map[string]string{"true": "true", " FALSE ": "false"} {
|
||||
got, err := normalizeAndValidateConfigValue(sequentialPortConfigKey, in)
|
||||
if err != nil || got != want {
|
||||
t.Fatalf("value %q: got %q err=%v, want %q", in, got, err, want)
|
||||
}
|
||||
}
|
||||
if _, err := normalizeAndValidateConfigValue(sequentialPortConfigKey, "maybe"); err == nil {
|
||||
t.Fatal("expected invalid value to be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSequentialPortConfigReadsRepositoryAndDefaultsOff(t *testing.T) {
|
||||
_, r := setupConfigAccessTestRouter(t)
|
||||
h := &Handler{repo: r}
|
||||
if h.isSequentialPortEnabled() {
|
||||
t.Fatal("missing config must preserve random allocation")
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
value string
|
||||
want bool
|
||||
}{
|
||||
{"true", true}, {" TRUE ", true}, {"false", false}, {"invalid", false},
|
||||
} {
|
||||
seedConfigValue(t, r, sequentialPortConfigKey, tc.value)
|
||||
if got := h.isSequentialPortEnabled(); got != tc.want {
|
||||
t.Fatalf("config %q: got %v, want %v", tc.value, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user