mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00

I think it's time to move a lot of the peer-to-peer networking but-not-ipfs-specific things into its own package: p2p. This could in the future be split off into its own library. The first thing to go is the peer.
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package swarm
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
peer "github.com/jbenet/go-ipfs/p2p/peer"
|
|
|
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
|
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
|
)
|
|
|
|
func TestSimultOpen(t *testing.T) {
|
|
// t.Skip("skipping for another test")
|
|
|
|
ctx := context.Background()
|
|
swarms, peers := makeSwarms(ctx, t, 2)
|
|
|
|
// connect everyone
|
|
{
|
|
var wg sync.WaitGroup
|
|
connect := func(s *Swarm, dst peer.ID, addr ma.Multiaddr) {
|
|
// copy for other peer
|
|
s.peers.AddAddress(dst, addr)
|
|
if _, err := s.Dial(ctx, dst); err != nil {
|
|
t.Fatal("error swarm dialing to peer", err)
|
|
}
|
|
wg.Done()
|
|
}
|
|
|
|
log.Info("Connecting swarms simultaneously.")
|
|
wg.Add(2)
|
|
go connect(swarms[0], swarms[1].local, peers[1].Addr)
|
|
go connect(swarms[1], swarms[0].local, peers[0].Addr)
|
|
wg.Wait()
|
|
}
|
|
|
|
for _, s := range swarms {
|
|
s.Close()
|
|
}
|
|
}
|
|
|
|
func TestSimultOpenMany(t *testing.T) {
|
|
// t.Skip("very very slow")
|
|
|
|
addrs := 20
|
|
SubtestSwarm(t, addrs, 10)
|
|
}
|
|
|
|
func TestSimultOpenFewStress(t *testing.T) {
|
|
if testing.Short() {
|
|
t.SkipNow()
|
|
}
|
|
// t.Skip("skipping for another test")
|
|
|
|
msgs := 40
|
|
swarms := 2
|
|
rounds := 10
|
|
// rounds := 100
|
|
|
|
for i := 0; i < rounds; i++ {
|
|
SubtestSwarm(t, swarms, msgs)
|
|
<-time.After(10 * time.Millisecond)
|
|
}
|
|
}
|