Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

fix int to string conversion in tests, update Go version on CI #69

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ os:
language: go

go:
- 1.13.x
- 1.14.x
- 1.15.x

env:
global:
Expand Down
31 changes: 16 additions & 15 deletions listener_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stream_test

import (
"fmt"
"io"
"sync"
"testing"
Expand Down Expand Up @@ -41,7 +42,7 @@ func TestAcceptSingleConn(t *testing.T) {
ln := createListener(t, defaultUpgrader)
defer ln.Close()

cconn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(1))
cconn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("1"))
require.NoError(err)

sconn, err := ln.Accept()
Expand All @@ -64,7 +65,7 @@ func TestAcceptMultipleConns(t *testing.T) {
}()

for i := 0; i < 10; i++ {
cconn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(1))
cconn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("1"))
require.NoError(err)
toClose = append(toClose, cconn)

Expand All @@ -86,7 +87,7 @@ func TestConnectionsClosedIfNotAccepted(t *testing.T) {
ln := createListener(t, defaultUpgrader)
defer ln.Close()

conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(2))
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("2"))
require.NoError(err)

errCh := make(chan error)
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestFailedUpgradeOnListen(t *testing.T) {
require := require.New(t)

upgrader := &st.Upgrader{
Secure: insecure.New(peer.ID(1)),
Secure: insecure.New(peer.ID("1")),
Muxer: &errorMuxer{},
}

Expand All @@ -130,7 +131,7 @@ func TestFailedUpgradeOnListen(t *testing.T) {
errCh <- err
}()

_, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(2))
_, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("2"))
require.Error(err)

// close the listener.
Expand Down Expand Up @@ -164,7 +165,7 @@ func TestListenerClose(t *testing.T) {
require.Contains(err.Error(), "use of closed network connection")

// doesn't accept new connections when it is closed
_, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(1))
_, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("1"))
require.Error(err)
}

Expand All @@ -175,7 +176,7 @@ func TestListenerCloseClosesQueued(t *testing.T) {

var conns []transport.CapableConn
for i := 0; i < 10; i++ {
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(i))
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(fmt.Sprintf("%d", i)))
require.NoError(err)
conns = append(conns, conn)
}
Expand Down Expand Up @@ -213,7 +214,7 @@ func TestConcurrentAccept(t *testing.T) {
num = 3 * st.AcceptQueueLength
blockingMuxer = newBlockingMuxer()
upgrader = &st.Upgrader{
Secure: insecure.New(peer.ID(1)),
Secure: insecure.New(peer.ID("1")),
Muxer: blockingMuxer,
}
)
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestConcurrentAccept(t *testing.T) {
go func() {
defer wg.Done()

conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(2))
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("2"))
if err != nil {
errCh <- err
return
Expand Down Expand Up @@ -270,7 +271,7 @@ func TestAcceptQueueBacklogged(t *testing.T) {
// setup AcceptQueueLength connections, but don't accept any of them
errCh := make(chan error, st.AcceptQueueLength+1)
doDial := func() {
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(2))
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("2"))
errCh <- err
if conn != nil {
_ = conn.Close()
Expand Down Expand Up @@ -308,36 +309,36 @@ func TestListenerConnectionGater(t *testing.T) {
defer ln.Close()

// no gating.
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(0))
conn, err := dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("0"))
require.NoError(err)
require.False(conn.IsClosed())
_ = conn.Close()

// rejecting after handshake.
testGater.BlockSecured(true)
testGater.BlockAccept(false)
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(0))
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("0"))
require.Error(err)
require.Nil(conn)

// rejecting on accept will trigger first.
testGater.BlockSecured(true)
testGater.BlockAccept(true)
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(0))
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("0"))
require.Error(err)
require.Nil(conn)

// rejecting only on acceptance.
testGater.BlockSecured(false)
testGater.BlockAccept(true)
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(0))
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("0"))
require.Error(err)
require.Nil(conn)

// back to normal
testGater.BlockSecured(false)
testGater.BlockAccept(false)
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID(0))
conn, err = dial(t, defaultUpgrader, ln.Multiaddr(), peer.ID("0"))
require.NoError(err)
require.False(conn.IsClosed())
_ = conn.Close()
Expand Down
8 changes: 4 additions & 4 deletions upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

var (
defaultUpgrader = &st.Upgrader{
Secure: insecure.New(peer.ID(1)),
Secure: insecure.New(peer.ID("1")),
Muxer: &negotiatingMuxer{},
}
)
Expand Down Expand Up @@ -113,21 +113,21 @@ func TestOutboundConnectionGating(t *testing.T) {
upgrader := *defaultUpgrader
upgrader.ConnGater = testGater

conn, err := dial(t, &upgrader, ln.Multiaddr(), peer.ID(2))
conn, err := dial(t, &upgrader, ln.Multiaddr(), peer.ID("2"))
require.NoError(err)
require.NotNil(conn)
_ = conn.Close()

// blocking accepts doesn't affect the dialling side, only the listener.
testGater.BlockAccept(true)
conn, err = dial(t, &upgrader, ln.Multiaddr(), peer.ID(2))
conn, err = dial(t, &upgrader, ln.Multiaddr(), peer.ID("2"))
require.NoError(err)
require.NotNil(conn)
_ = conn.Close()

// now let's block all connections after being secured.
testGater.BlockSecured(true)
conn, err = dial(t, &upgrader, ln.Multiaddr(), peer.ID(2))
conn, err = dial(t, &upgrader, ln.Multiaddr(), peer.ID("2"))
require.Error(err)
require.Contains(err.Error(), "gater rejected connection")
require.Nil(conn)
Expand Down