mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-02 07:24:48 +03:00
5d2d068484
The external traffic webhook was sent from inside the 5-second accounting job: its cadence could not be changed, and a slow receiver held up accounting. Add an interval setting (5 to 3600 seconds, default 5). The accounting poll only sums each tick's deltas per client email and per inbound or outbound tag; once the interval has passed, the batch is posted from its own goroutine. Accounting, quota enforcement and online updates keep their 5-second cadence. Delivery semantics are unchanged: each batch is posted once. A failure drops it, warns once with the reason (never the URI) and reports when deliveries resume. Destinations are checked at dial time and redirects are refused. A settings client that omits the interval keeps the stored value. Fixes #7028
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/dbtest"
|
|
)
|
|
|
|
func TestExternalTrafficInformIntervalSurvivesLegacySave(t *testing.T) {
|
|
dbtest.InitDB(t, filepath.Join(t.TempDir(), "x-ui.db"))
|
|
service := new(SettingService)
|
|
all, err := service.GetAllSetting()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if all.TrafficInformInterval != 5 {
|
|
t.Fatalf("default interval = %d, want 5s", all.TrafficInformInterval)
|
|
}
|
|
all.ExternalTrafficInformEnable = true
|
|
all.ExternalTrafficInformURI = "https://example.test/traffic"
|
|
all.TrafficInformInterval = 60
|
|
if err := service.UpdateAllSetting(all, SecretClears{}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
all.TrafficInformInterval = 0
|
|
if err := service.UpdateAllSetting(all, SecretClears{}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
all.TrafficInformInterval = 3601
|
|
if err := service.UpdateAllSetting(all, SecretClears{}); err == nil || err.Error() != "external traffic inform interval must be between 5 and 3600 seconds" {
|
|
t.Fatalf("invalid interval save = %v", err)
|
|
}
|
|
cfg, err := service.GetExternalTrafficInformConfig()
|
|
if err != nil || cfg.Interval != time.Minute || cfg.URI != "https://example.test/traffic" {
|
|
t.Fatalf("effective configuration = %+v, error = %v", cfg, err)
|
|
}
|
|
}
|