Use better test ports (#311)

Other interface or ports may be blocked or require permissions when running tests.
This commit is contained in:
Egon Elbre 2018-09-07 12:42:04 +03:00 committed by GitHub
parent 79354bf0ab
commit 706a6ac26e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 14 deletions

View File

@ -6,7 +6,6 @@ package kademlia
import (
"context"
"crypto/rand"
"fmt"
"log"
"net"
"strconv"
@ -152,7 +151,7 @@ func (k *Kademlia) FindNode(ctx context.Context, ID dht.NodeID) (proto.Node, err
if string(v.ID) == ID.String() {
return proto.Node{Id: string(v.ID), Address: &proto.NodeAddress{
Transport: defaultTransport,
Address: fmt.Sprintf("%s:%d", v.IP.String(), v.Port),
Address: net.JoinHostPort(v.IP.String(), strconv.Itoa(v.Port)),
},
}, nil
}

View File

@ -5,7 +5,6 @@ package node
import (
"context"
"fmt"
"net"
"testing"
@ -28,16 +27,18 @@ func TestLookup(t *testing.T) {
}{
{
self: proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: ":7070"}},
to: proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: ":8080"}},
to: proto.Node{}, // filled after server has been started
find: proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: ":9090"}},
expectedErr: nil,
},
}
for _, v := range cases {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 8080))
lis, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err)
v.to = proto.Node{Id: test.NewNodeID(t), Address: &proto.NodeAddress{Address: lis.Addr().String()}}
srv, mock, err := newTestServer(ctx)
assert.NoError(t, err)
go srv.Serve(lis)

View File

@ -5,7 +5,6 @@ package overlay
import (
"context"
"fmt"
"net"
"testing"
@ -66,7 +65,7 @@ func TestChoose(t *testing.T) {
}
for _, v := range cases {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
lis, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err)
srv, mock, err := newTestServer(ctx)
@ -103,7 +102,7 @@ func TestLookup(t *testing.T) {
}
for _, v := range cases {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
lis, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err)
srv, mock, err := newTestServer(ctx)

View File

@ -5,7 +5,6 @@ package overlay
import (
"context"
"fmt"
"net"
"testing"
@ -18,7 +17,7 @@ import (
)
func TestFindStorageNodes(t *testing.T) {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
lis, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err)
id, err := kademlia.NewID()
@ -44,7 +43,7 @@ func TestFindStorageNodes(t *testing.T) {
}
func TestOverlayLookup(t *testing.T) {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
lis, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err)
id, err := kademlia.NewID()

View File

@ -5,7 +5,6 @@ package overlay
import (
"context"
"fmt"
"net"
"testing"
@ -16,7 +15,7 @@ import (
)
func TestNewServer(t *testing.T) {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
lis, err := net.Listen("tcp", "127.0.0.1:0")
assert.NoError(t, err)
srv := newMockServer()

View File

@ -526,7 +526,7 @@ func NewTestServer(t *testing.T) *TestServer {
}
func (TS *TestServer) start() (addr string) {
lis, err := net.Listen("tcp", ":0")
lis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}