test(nodes): extend fleet quota classification regression coverage (#7387)

The SQL aggregation introduced in #7342 and the signed BIGINT overflow fix merged in #7323 are already in main. Consolidate and extend the shared SQLite/PostgreSQL regression without changing runtime behavior.

Cover 11 quota boundary cases, including depleted-before-disabled precedence, disabled clients below quota, mixed-sign exact-limit comparisons and negative quotas. Reset traffic counters and client enable state for each case and assert both remote-node and fleet counts.

Validation: all 12 CI jobs passed (run 47180136393), including PostgreSQL boundary regressions, race and node E2E. Independent Lenovo SQLite tests passed (6 top-level tests), and 101,000 SQL arithmetic comparisons matched the integer oracle. No schema, API or CI changes.

Refs #7319, #7323, #7342.
This commit is contained in:
Hamed
2026-12-03 22:48:11 +03:30
committed by GitHub
parent 3d6655ffb0
commit 86ccc92875
+24 -9
View File
@@ -223,30 +223,45 @@ func TestNodeFleetQuotaClassificationAtInt64Limits(t *testing.T) {
name string
up, down, total int64
depleted int
disabled bool
}{
{"above limit", math.MaxInt64, 1, math.MaxInt64, 1},
{"at limit", 1, math.MaxInt64 - 1, math.MaxInt64, 1},
{"below limit", math.MaxInt64 - 1, 0, math.MaxInt64, 0},
{"negative upload", -1, math.MaxInt64, math.MaxInt64, 0},
{"negative download", math.MaxInt64, -1, math.MaxInt64, 0},
{"negative underflow", math.MinInt64, -1, 1, 0},
{"unlimited", math.MaxInt64, 1, 0, 0},
{"above limit", math.MaxInt64, 1, math.MaxInt64, 1, false},
{"above limit while disabled", math.MaxInt64, 1, math.MaxInt64, 1, true},
{"at limit", 1, math.MaxInt64 - 1, math.MaxInt64, 1, false},
{"below limit", math.MaxInt64 - 1, 0, math.MaxInt64, 0, false},
{"below limit while disabled", math.MaxInt64 - 1, 0, math.MaxInt64, 0, true},
{"negative upload below limit", -1, math.MaxInt64, math.MaxInt64, 0, false},
{"negative upload at limit", -1, math.MaxInt64, math.MaxInt64 - 1, 1, false},
{"negative download", math.MaxInt64, -1, math.MaxInt64, 0, false},
{"negative underflow", math.MinInt64, -1, 1, 0, false},
{"unlimited", math.MaxInt64, 1, 0, 0, false},
{"negative quota", math.MaxInt64, math.MaxInt64, math.MinInt64, 0, false},
} {
t.Run(tc.name, func(t *testing.T) {
if err := db.Model(&traffic).Updates(map[string]any{"up": tc.up, "down": tc.down, "total": tc.total}).Error; err != nil {
t.Fatal(err)
}
if err := db.Model(&client).UpdateColumn("enable", !tc.disabled).Error; err != nil {
t.Fatal(err)
}
overview, err := (&NodeService{}).GetNodeOverview(nil)
if err != nil {
t.Fatal(err)
}
want := NodeFleetCounts{InboundCount: 1, ClientCount: 1, ActiveCount: 1 - tc.depleted, DepletedCount: tc.depleted}
disabledCount := 0
if tc.disabled && tc.depleted == 0 {
disabledCount = 1
}
want := NodeFleetCounts{
InboundCount: 1, ClientCount: 1, ActiveCount: 1 - tc.depleted - disabledCount,
DisabledCount: disabledCount, DepletedCount: tc.depleted,
}
if overview.Fleet != want || len(overview.Nodes) != 1 {
t.Fatalf("fleet counts = %+v, nodes = %d, want %+v and one node", overview.Fleet, len(overview.Nodes), want)
}
got := overview.Nodes[0]
if got.ClientCount != want.ClientCount || got.ActiveCount != want.ActiveCount ||
got.DisabledCount != 0 || got.DepletedCount != want.DepletedCount {
got.DisabledCount != want.DisabledCount || got.DepletedCount != want.DepletedCount {
t.Fatalf("unexpected remote client counts: %+v", got)
}
})