refactor(mtr): 统一生产与测试的 atomic 哨兵初始化

This commit is contained in:
tsosunchia committed 2026-09-04 16:24:24 +08:00
1 parent fcd1336c43
commit 8d36dc7406
2 files changed
+11 -11

No files matched your search

+5 -1
View File
@@ -338,6 +338,10 @@ func newMTRICMPEngine(config Config) (*mtrICMPEngine, error) {
return nil, fmt.Errorf("cannot determine local IP for MTR ICMP")
}
return newMTRICMPEngineState(config, ipVer, srcIP), nil
}
func newMTRICMPEngineState(config Config, ipVer int, srcIP net.IP) *mtrICMPEngine {
engine := &mtrICMPEngine{
config: config,
ipVer: ipVer,
@@ -346,7 +350,7 @@ func newMTRICMPEngine(config Config) (*mtrICMPEngine, error) {
}
engine.knownFinalTTL.Store(-1)
engine.roundFinalTTL.Store(-1)
return engine, nil
return engine
}
func newMTREchoID() int {
+6 -10
View File
@@ -435,19 +435,15 @@ func newTestICMPEngine(timeout time.Duration) *mtrICMPEngine {
if timeout <= 0 {
timeout = 2 * time.Second
}
engine := &mtrICMPEngine{
config: Config{Timeout: timeout},
notifyCh: make(chan struct{}, 1),
sentAt: make(map[int]mtrProbeMeta),
replied: make(map[int]*mtrProbeReply),
}
engine.knownFinalTTL.Store(-1)
engine.roundFinalTTL.Store(-1)
engine := newMTRICMPEngineState(Config{Timeout: timeout}, 4, net.IPv4zero)
engine.notifyCh = make(chan struct{}, 1)
engine.sentAt = make(map[int]mtrProbeMeta)
engine.replied = make(map[int]*mtrProbeReply)
return engine
}
func TestNewTestICMPEngineInitialFinalTTL(t *testing.T) {
engine := newTestICMPEngine(time.Second)
func TestNewMTRICMPEngineStateInitialFinalTTL(t *testing.T) {
engine := newMTRICMPEngineState(Config{Timeout: time.Second}, 4, net.IPv4zero)
if got := engine.knownFinalTTL.Load(); got != -1 {
t.Fatalf("knownFinalTTL = %d, want -1", got)
}