private/server: avoid relying on timing

The previous test relied on timing, but instead let's try dialing
the server and see whether we can do something with the connection.

We probably should test all the supported protocols instead of just tcp.

Change-Id: I9217494859faea0a7b93515aad706da4fdd8a140
This commit is contained in:
Egon Elbre 2023-02-01 12:29:43 +02:00
parent 3976a2fd1d
commit 9a6be7f1e7

View File

@ -5,13 +5,14 @@ package server_test
import ( import (
"context" "context"
"net"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"time"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/zeebo/errs"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
"storj.io/common/errs2" "storj.io/common/errs2"
@ -20,6 +21,7 @@ import (
"storj.io/common/rpc" "storj.io/common/rpc"
_ "storj.io/common/rpc/quic" _ "storj.io/common/rpc/quic"
"storj.io/common/storj" "storj.io/common/storj"
"storj.io/common/sync2"
"storj.io/common/testcontext" "storj.io/common/testcontext"
"storj.io/storj/private/server" "storj.io/storj/private/server"
"storj.io/storj/private/testplanet" "storj.io/storj/private/testplanet"
@ -51,12 +53,28 @@ func TestServer(t *testing.T) {
require.NoError(t, instance.Close()) require.NoError(t, instance.Close())
}() }()
serverCtx, serverCancel := context.WithTimeout(ctx, time.Second) serverCtx, serverCancel := context.WithCancel(ctx)
defer serverCancel() defer serverCancel()
err = instance.Run(serverCtx) require.Empty(t, sync2.Concurrently(
err = errs2.IgnoreCanceled(err) func() error {
require.NoError(t, err) err = instance.Run(serverCtx)
return errs2.IgnoreCanceled(err)
},
func() (err error) {
defer serverCancel()
dialer := net.Dialer{}
conn, err := dialer.DialContext(ctx, "tcp", instance.PrivateAddr().String())
if err != nil {
return errs.Wrap(err)
}
defer func() { err = errs.Combine(err, conn.Close()) }()
_, err = conn.Write([]byte{1})
return errs.Wrap(err)
},
))
} }
func TestHybridConnector_Basic(t *testing.T) { func TestHybridConnector_Basic(t *testing.T) {