Files
3x-ui/internal/web/service/client_bulk_reset_reenable_test.go
T
Jay Hemnani 1dbb37432c fix(traffic): re-enable quota-disabled clients on inbound and reset-all resets (#6833)
Running out of quota switches a client off in client_traffics, in its client
record and in the inbound settings JSON. The inbound's periodic reset and the
Reset All Client Traffic button only set client_traffics.enable back, so the
client showed zero usage but stayed out of the running core every period.

Both paths now read the disabled, depleted emails inside the transaction that
zeroes the counters, on the traffic writer, and re-enable them through
BulkSetEnable after the commit, like every other reset path. Reading them inside
that transaction keeps a traffic tick from disabling a client between the read
and the reset.
2026-10-24 04:21:11 +02:00

51 lines
1.8 KiB
Go

package service
import "testing"
// TestBulkResetTraffic_ReenablesDisabledClient covers the re-enable branch of
// BulkResetTraffic: a disabled client whose traffic is bulk-reset must come back
// enabled with its counters zeroed, in all three enable locations. This is the
// path whose s.Update failure was previously swallowed silently.
func TestBulkResetTraffic_ReenablesDisabledClient(t *testing.T) {
setupBulkDB(t)
svc := &ClientService{}
inboundSvc := &InboundService{}
email := "reset-reenable@x"
ib := seedLocalDisabledClient(t, svc, 52010, "", email, 1000, 0, 600, 500)
affected, err := svc.BulkResetTraffic(inboundSvc, []string{email})
if err != nil {
t.Fatalf("BulkResetTraffic: %v", err)
}
if affected < 1 {
t.Fatalf("affected = %d, want >= 1", affected)
}
assertEnableEverywhere(t, svc, inboundSvc, ib.Id, email, true)
if tr := trafficOf(t, email); tr.Up != 0 || tr.Down != 0 {
t.Fatalf("%s: traffic after reset up=%d down=%d, want 0/0", email, tr.Up, tr.Down)
}
}
func TestResetAllTraffics_ReenablesDepletedClientEverywhere(t *testing.T) {
setupBulkDB(t)
svc := &ClientService{}
inboundSvc := &InboundService{}
depleted := seedLocalDisabledClient(t, svc, 52011, "", "spent-all@x", 1000, 0, 600, 500)
banned := seedLocalDisabledClient(t, svc, 52012, "", "banned-all@x", 100000, 0, 600, 500)
if _, err := svc.ResetAllTraffics(); err != nil {
t.Fatalf("ResetAllTraffics: %v", err)
}
assertEnableEverywhere(t, svc, inboundSvc, depleted.Id, "spent-all@x", true)
if recordEnableOf(t, svc, "banned-all@x") {
t.Fatal("banned-all@x: an operator-disabled client was switched back on by Reset All Client Traffic")
}
if jsonClientEnable(t, inboundSvc, banned.Id, "banned-all@x") {
t.Fatal("banned-all@x: an operator-disabled client was enabled in the inbound JSON")
}
}