local_tuic_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package runtime
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  6. )
  7. func TestUpdateTuicInboundResyncsBridgeOnTagRename(t *testing.T) {
  8. resyncs := 0
  9. local := NewLocal(LocalDeps{SetNeedRestart: func() { resyncs++ }})
  10. oldInbound := &model.Inbound{Id: 940001, Tag: "old-tuic-tag", Protocol: model.TUIC, Enable: true, Settings: `{"clients":[]}`}
  11. newInbound := *oldInbound
  12. newInbound.Tag = "new-tuic-tag"
  13. if err := local.updateTuicInbound(context.Background(), oldInbound, &newInbound); err != nil {
  14. t.Fatalf("updateTuicInbound: %v", err)
  15. }
  16. if resyncs != 1 {
  17. t.Fatalf("Xray bridge resync count = %d, want 1", resyncs)
  18. }
  19. }
  20. func TestUpdateTuicInboundDoesNotResyncForProfileOnlyChange(t *testing.T) {
  21. resyncs := 0
  22. local := NewLocal(LocalDeps{SetNeedRestart: func() { resyncs++ }})
  23. oldInbound := &model.Inbound{Id: 940002, Tag: "tuic-tag", Protocol: model.TUIC, Enable: true, Settings: `{"clients":[],"congestion_control":"bbr"}`}
  24. newInbound := *oldInbound
  25. newInbound.Settings = `{"clients":[],"congestion_control":"cubic","log_level":"debug"}`
  26. if err := local.updateTuicInbound(context.Background(), oldInbound, &newInbound); err != nil {
  27. t.Fatalf("updateTuicInbound: %v", err)
  28. }
  29. if resyncs != 0 {
  30. t.Fatalf("profile-only update triggered %d Xray restarts, want 0", resyncs)
  31. }
  32. }