diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3a2bc683..99def0a71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,6 +204,16 @@ jobs: exit 1 fi + - name: PostgreSQL node counter reset regressions + run: | + set -o pipefail + go test -p 1 ./internal/web/service ./internal/database -run '^(TestNodeFrozenDip_|TestMigrateNodeClientTrafficDippedWhileFrozenColumn$)' -count=1 -v | tee /tmp/postgres-node-counter-reset.log + passed=$(grep -c -- '^--- PASS' /tmp/postgres-node-counter-reset.log || true) + if [ "$passed" -ne 4 ]; then + echo "expected 3 node counter regressions and 1 migration test to pass, got $passed" >&2 + exit 1 + fi + - name: PostgreSQL schema and migration tests run: | set -o pipefail diff --git a/internal/database/node_client_traffic_dip_migration_test.go b/internal/database/node_client_traffic_dip_migration_test.go index fb88b3802..24228d654 100644 --- a/internal/database/node_client_traffic_dip_migration_test.go +++ b/internal/database/node_client_traffic_dip_migration_test.go @@ -4,9 +4,15 @@ import ( "testing" "github.com/mhsanaei/3x-ui/v3/internal/database/model" + "github.com/mhsanaei/3x-ui/v3/internal/testpg" ) func TestMigrateNodeClientTrafficDippedWhileFrozenColumn(t *testing.T) { + cleanup, err := testpg.IsolatePackage("node_frozen_dip_migration") + if err != nil { + t.Fatal(err) + } + t.Cleanup(cleanup) initMigrateDB(t) tx := GetDB().Begin() if tx.Error != nil { diff --git a/internal/web/service/node_frozen_dip_test.go b/internal/web/service/node_frozen_dip_test.go index 107933b1e..e884cac5d 100644 --- a/internal/web/service/node_frozen_dip_test.go +++ b/internal/web/service/node_frozen_dip_test.go @@ -3,11 +3,24 @@ package service import ( "testing" + "gorm.io/gorm" + "github.com/mhsanaei/3x-ui/v3/internal/database/model" + "github.com/mhsanaei/3x-ui/v3/internal/testpg" "github.com/mhsanaei/3x-ui/v3/internal/web/runtime" "github.com/mhsanaei/3x-ui/v3/internal/xray" ) +func initFrozenDipTestDB(t *testing.T) *gorm.DB { + t.Helper() + cleanup, err := testpg.IsolatePackage("node_frozen_dip") + if err != nil { + t.Fatal(err) + } + t.Cleanup(cleanup) + return initTrafficTestDB(t) +} + func syncDirtyNode(t *testing.T, svc *InboundService, nodeID int, tag, settings string, stats ...xray.ClientTraffic) { t.Helper() snap := &runtime.TrafficSnapshot{ @@ -21,7 +34,7 @@ func syncDirtyNode(t *testing.T, svc *InboundService, nodeID int, tag, settings // A node counter that restarted below the baseline while the node is dirty must // add the other field's growth once, not again on every tick. func TestNodeFrozenDip_IdleClientCountedOnce(t *testing.T) { - db := initTrafficTestDB(t) + db := initFrozenDipTestDB(t) svc := &InboundService{} const email = "idle@x" @@ -43,7 +56,7 @@ func TestNodeFrozenDip_IdleClientCountedOnce(t *testing.T) { // Usage a client makes below the pre-restart baseline while the node is dirty // must still be counted. func TestNodeFrozenDip_UsageBelowOldBaselineCounted(t *testing.T) { - db := initTrafficTestDB(t) + db := initFrozenDipTestDB(t) svc := &InboundService{} const email = "active@x" @@ -65,7 +78,7 @@ func TestNodeFrozenDip_UsageBelowOldBaselineCounted(t *testing.T) { // A node-side renewal seen while dirty must still be adopted on the first clean // tick, even after the client's usage outgrew the pre-renewal baseline. func TestNodeFrozenDip_RenewalSurvivesUsagePastOldBaseline(t *testing.T) { - db := initTrafficTestDB(t) + db := initFrozenDipTestDB(t) createNodeInbound(t, db, 1, "n1-in", 41001) svc := &InboundService{}