Created
August 12, 2020 21:34
-
-
Save pradovic/0ce78bbd0ce886963a51a7e1f3ecb52f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestConnectOnAllAddresses(t *testing.T) { | |
| s1, _ := newService(t, 1, libp2pServiceOpts{ | |
| libp2pOpts: libp2p.Options{ | |
| EnableQUIC: true, | |
| EnableWS: true, | |
| }, | |
| }) | |
| s2, overlay2 := newService(t, 1, libp2pServiceOpts{ | |
| libp2pOpts: libp2p.Options{ | |
| EnableQUIC: true, | |
| EnableWS: true, | |
| }, | |
| }) | |
| addrs1, err := s1.Addresses() | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| addrs2, err := s2.Addresses() | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| go func() { | |
| for _, addr := range addrs1 { | |
| fmt.Println(addr.String()) | |
| bzzAddrs, err := s2.Connect(context.Background(), addr) | |
| if err != nil && !errors.Is(err, p2p.ErrAlreadyConnected) { | |
| fmt.Println(err) | |
| } | |
| if bzzAddrs != nil { | |
| fmt.Println("connected") | |
| } | |
| } | |
| }() | |
| go func() { | |
| for _, addr := range addrs2 { | |
| fmt.Println(addr.String()) | |
| bzzAddrs, err := s1.Connect(context.Background(), addr) | |
| if err != nil && !errors.Is(err, p2p.ErrAlreadyConnected) { | |
| fmt.Println(err) | |
| } | |
| if bzzAddrs != nil { | |
| fmt.Println("connected") | |
| } | |
| } | |
| }() | |
| time.Sleep(10 * time.Second) | |
| err1 := s1.Disconnect(overlay2) | |
| err2 := s2.Close() | |
| fmt.Println(err1, err2) | |
| time.Sleep(2 * time.Second) | |
| } | |
| type mocknotifier struct{} | |
| func (m *mocknotifier) Connected(_ context.Context, s swarm.Address) error { | |
| fmt.Println("connected notifier", s) | |
| return nil | |
| } | |
| func (m *mocknotifier) Disconnected(s swarm.Address) { | |
| fmt.Println("disconnected notifier", s) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment