Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
1. internal/noise/read_writer_test.go: removed test TestReadWriterConcurrentTCP
2. docs/Tests.Detection-of-unstable-tests.md: added note about removal
of TestReadWriterConcurrentTCP
  • Loading branch information
ayuryshev committed Apr 15, 2019
1 parent 2a21dbf commit 0b3fb15
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 71 deletions.
2 changes: 2 additions & 0 deletions docs/Tests.Detection-of-unstable-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ $ grep coverage ./logs/internal/*.log
```

Note 0.0% coverage

Test removed.
71 changes: 0 additions & 71 deletions internal/noise/read_writer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package noise

import (
"errors"
"fmt"
"net"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -126,71 +123,3 @@ func TestReadWriterXKPattern(t *testing.T) {
assert.Equal(t, 3, n)
assert.Equal(t, []byte("bar"), buf)
}

func TestReadWriterConcurrentTCP(t *testing.T) {
const readCount = 15
readErrs := make([]error, readCount)
writeErrs := make([]error, readCount)
msg := []byte("foo")

errNoOp := errors.New("no operation")
for i := 0; i < readCount; i++ {
readErrs[i] = errNoOp
writeErrs[i] = errNoOp
}

l, err := net.Listen("tcp", ":0") // nolint: gosec
require.NoError(t, err)
defer l.Close()

var wg sync.WaitGroup
wg.Add(1)
go func() {
conn, err := l.Accept()
if err != nil {
return
}

var rwg sync.WaitGroup
for i := 0; i < readCount; i++ {
rwg.Add(1)
go func(idx int, c net.Conn) {
buf := make([]byte, 3)
if _, err := c.Read(buf); err != nil {
readErrs[idx] = err
}

if string(buf) != "foo" {
readErrs[idx] = errors.New("invalid message")
}

readErrs[idx] = nil
rwg.Done()
}(i, conn)
}
rwg.Wait()
wg.Done()
}()

conn, err := net.Dial("tcp", l.Addr().String())
require.NoError(t, err)
defer conn.Close()

for i := 0; i < readCount; i++ {
wg.Add(1)
go func(idx int, c net.Conn) {
if _, err := c.Write(msg); err != nil {
writeErrs[idx] = err
}

writeErrs[idx] = nil
wg.Done()
}(i, conn)
}
wg.Wait()

for i := 0; i < readCount; i++ {
require.NoError(t, readErrs[i], fmt.Sprintf("read #%d", i))
require.NoError(t, writeErrs[i], fmt.Sprintf("write #%d", i))
}
}

0 comments on commit 0b3fb15

Please sign in to comment.