Files
3x-ui/internal/web/runtime/tls_client_invalidate_test.go
T
Sanaei bc49c1a68f fix(node): release a deleted node's metric series and HTTP client
Deleting a node must free what the master keeps per node in memory.

Delete dropped the node's cpu and mem series but not netUp and netDown,
which the heartbeat records too, so each deleted node leaked two tiered
histories. It now drops every NodeMetricKeys entry.

InvalidateNode, called on node edit, disable and delete, cleared only the
cached Remote. The pooled HTTP client and its transport stayed cached until
a later call for the same node pruned them, which a deleted node never
makes. InvalidateNode now drops those too, outside the manager lock; an
edited node pays one fresh handshake on its next call.
2026-09-15 20:39:32 +02:00

26 lines
819 B
Go

package runtime
import (
"testing"
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
)
// Only a later call for the same node pruned its pooled client, so a deleted
// node kept its client and transport cached for the life of the process.
func TestInvalidateNodeDropsItsCachedHTTPClient(t *testing.T) {
node := &model.Node{Id: 8801, Address: "node.example.test", Port: 443, Scheme: "https", TlsVerifyMode: "skip"}
if _, err := HTTPClientForNode(node, ""); err != nil {
t.Fatalf("HTTPClientForNode: %v", err)
}
if got := nodeClientEntries(node.Id); got != 1 {
t.Fatalf("cached clients before invalidation = %d, want 1", got)
}
NewManager(LocalDeps{}).InvalidateNode(node.Id)
if got := nodeClientEntries(node.Id); got != 0 {
t.Fatalf("cached clients after InvalidateNode = %d, want 0", got)
}
}