Skip to content

Commit

Permalink
remove mock net test case TestStreamsStress
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 22, 2022
1 parent 013c661 commit 2a45095
Showing 1 changed file with 0 additions and 75 deletions.
75 changes: 0 additions & 75 deletions p2p/net/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"io"
"math"
"math/rand"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -331,80 +330,6 @@ func performPing(t *testing.T, st string, n int, s network.Stream) error {
return nil
}

func TestStreamsStress(t *testing.T) {
ctx := context.Background()
nnodes := 100
if race.WithRace() {
nnodes = 30
}

mn, err := FullMeshConnected(nnodes)
if err != nil {
t.Fatal(err)
}
defer mn.Close()

errs := make(chan error)

hosts := mn.Hosts()
var wg sync.WaitGroup
for _, h := range hosts {
h.SetStreamHandler(protocol.TestingID, func(s network.Stream) {
const st = "pingpong"
defer wg.Done()
defer s.Close()

for {
b := make([]byte, 4+len(st))
if _, err := io.ReadFull(s, b); err != nil {
if err == io.EOF {
return
}
errs <- err
}
if !bytes.Equal(b, []byte("ping"+st)) {
errs <- errors.New("bytes mismatch")
}
if _, err := s.Write([]byte("pong" + st)); err != nil {
errs <- err
}
}
})
}

for i := 0; i < 1000; i++ {
wg.Add(2)
go func(i int) {
defer wg.Done()
var from, to int
for from == to {
from = rand.Intn(len(hosts))
to = rand.Intn(len(hosts))
}
s, err := hosts[from].NewStream(ctx, hosts[to].ID(), protocol.TestingID)
if err != nil {
log.Debugf("%d (%s) %d (%s)", from, hosts[from], to, hosts[to])
panic(err)
}

log.Infof("%d start pinging", i)
errs <- performPing(t, "pingpong", rand.Intn(100), s)
log.Infof("%d done pinging", i)
}(i)
}

go func() {
wg.Wait()
close(errs)
}()

for err := range errs {
if err != nil {
t.Fatal(err)
}
}
}

func TestAdding(t *testing.T) {
mn := New()
defer mn.Close()
Expand Down

0 comments on commit 2a45095

Please sign in to comment.