MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / TestManager_ConcurrentApply

Function TestManager_ConcurrentApply

internal/sniproxy/manager_test.go:302–340  ·  view source on GitHub ↗

TestManager_ConcurrentApply 用几个 goroutine 同时 Apply,确保内部锁没问题。

(t *testing.T)

Source from the content-addressed store, hash-verified

300
301// TestManager_ConcurrentApply 用几个 goroutine 同时 Apply,确保内部锁没问题。
302func TestManager_ConcurrentApply(t *testing.T) {
303 backend := startEchoTLS(t, "x.example.com")
304 ln, _ := net.Listen("tcp", "127.0.0.1:0")
305 addr := ln.Addr().String()
306 _ = ln.Close()
307
308 m := NewManager(filepath.Join(t.TempDir(), "state.json"))
309 defer m.Close()
310
311 var wg sync.WaitGroup
312 for i := 0; i < 10; i++ {
313 wg.Add(1)
314 go func() {
315 defer wg.Done()
316 _ = m.Apply(ManagerConfig{
317 Listen: addr,
318 Routes: []Route{{SNI: "x.example.com", Backend: backend, Mode: ModeTransparent}},
319 })
320 }()
321 }
322 wg.Wait()
323
324 // 收尾:Listen 应可用
325 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
326 defer cancel()
327 for {
328 select {
329 case <-ctx.Done():
330 t.Fatal("proxy never came up")
331 default:
332 }
333 c, err := net.Dial("tcp", addr)
334 if err == nil {
335 _ = c.Close()
336 return
337 }
338 time.Sleep(20 * time.Millisecond)
339 }
340}

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
ApplyMethod · 0.95
startEchoTLSFunction · 0.85
AddrMethod · 0.80
AddMethod · 0.80
DialMethod · 0.80
NewManagerFunction · 0.70
CloseMethod · 0.65
DoneMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected