Skip to content
Merged
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
29 changes: 28 additions & 1 deletion test/xds/xds_server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import (
"net"
"strconv"
"testing"
"time"

"github.com/google/uuid"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
xdscreds "google.golang.org/grpc/credentials/xds"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/grpcsync"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/internal/testutils/xds/e2e"
"google.golang.org/grpc/internal/testutils/xds/e2e/setup"
Expand Down Expand Up @@ -78,6 +80,19 @@ func testModeChangeServerOption(t *testing.T) grpc.ServerOption {
})
}

// acceptNotifyingListener wraps a listener and notifies users when a server
// calls the Listener.Accept() method. This can be used to ensure that the
// server is ready before requests are sent to it.
type acceptNotifyingListener struct {
net.Listener
serverReady grpcsync.Event
}

func (l *acceptNotifyingListener) Accept() (net.Conn, error) {
l.serverReady.Fire()
return l.Listener.Accept()
}

// setupGRPCServer performs the following:
// - spin up an xDS-enabled gRPC server, configure it with xdsCredentials and
// register the test service on it
Expand Down Expand Up @@ -110,12 +125,24 @@ func setupGRPCServer(t *testing.T, bootstrapContents []byte) (net.Listener, func
t.Fatalf("testutils.LocalTCPListener() failed: %v", err)
}

readyLis := &acceptNotifyingListener{
Listener: lis,
serverReady: *grpcsync.NewEvent(),
}

go func() {
if err := server.Serve(lis); err != nil {
if err := server.Serve(readyLis); err != nil {
t.Errorf("Serve() failed: %v", err)
}
}()

// Wait for the server to start running.
select {
case <-readyLis.serverReady.Done():
case <-time.After(defaultTestTimeout):
t.Fatalf("Timed out while waiting for the backend server to start serving")
}

return lis, func() {
server.Stop()
}
Expand Down