2023-04-20 12:40:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-04-20 12:40:22 +00:00
|
|
|
|
2023-03-29 16:51:21 +00:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"fortio.org/fortio/fgrpc"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GRPCPing sends a fgrpc.PingMessage to a fortio server at addr, analogous to
|
|
|
|
// the CLI command `fortio grpcping`. It retries for up to 1m, with a 25ms gap.
|
|
|
|
func GRPCPing(t *testing.T, addr string) {
|
|
|
|
t.Helper()
|
|
|
|
pingConn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
|
|
require.NoError(t, err)
|
|
|
|
pingCl := fgrpc.NewPingServerClient(pingConn)
|
|
|
|
var msg *fgrpc.PingMessage
|
|
|
|
retries := 0
|
|
|
|
retry.RunWith(&retry.Timer{Timeout: time.Minute, Wait: 25 * time.Millisecond}, t, func(r *retry.R) {
|
2023-07-21 01:30:22 +00:00
|
|
|
t.Logf("making grpc call to %s", addr)
|
2023-03-29 16:51:21 +00:00
|
|
|
retries += 1
|
|
|
|
msg, err = pingCl.Ping(context.Background(), &fgrpc.PingMessage{
|
|
|
|
// use addr as payload so we have something variable to check against
|
|
|
|
Payload: addr,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
r.Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert.Equal(t, addr, msg.Payload)
|
|
|
|
}
|