MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestSwitchReconnectsToInboundPersistentPeer

Function TestSwitchReconnectsToInboundPersistentPeer

p2p/switch_test.go:540–567  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

538}
539
540func TestSwitchReconnectsToInboundPersistentPeer(t *testing.T) {
541 sw := MakeSwitch(cfg, 1, "testing", "123.123.123", initSwitchFunc)
542 err := sw.Start()
543 require.NoError(t, err)
544 t.Cleanup(func() {
545 if err := sw.Stop(); err != nil {
546 t.Error(err)
547 }
548 })
549
550 // 1. simulate failure by closing the connection
551 rp := &remotePeer{PrivKey: ed25519.GenPrivKey(), Config: cfg}
552 rp.Start()
553 defer rp.Stop()
554
555 err = sw.AddPersistentPeers([]string{rp.Addr().String()})
556 require.NoError(t, err)
557
558 conn, err := rp.Dial(sw.NetAddress())
559 require.NoError(t, err)
560 time.Sleep(50 * time.Millisecond)
561 require.NotNil(t, sw.Peers().Get(rp.ID()))
562
563 conn.Close()
564
565 waitUntilSwitchHasAtLeastNPeers(sw, 1)
566 assert.Equal(t, 1, sw.Peers().Size())
567}
568
569func TestSwitchDialPeersAsync(t *testing.T) {
570 if testing.Short() {

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
AddrMethod · 0.95
DialMethod · 0.95
IDMethod · 0.95
GenPrivKeyFunction · 0.92
MakeSwitchFunction · 0.85
StartMethod · 0.65
CleanupMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected