Skip to content
Merged
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions interop/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"

testgrpc "google.golang.org/grpc/interop/grpc_testing"
Expand Down Expand Up @@ -676,7 +677,7 @@ func DoPickFirstUnary(tc testgrpc.TestServiceClient) {
}
}

func doOneSoakIteration(ctx context.Context, tc testgrpc.TestServiceClient, resetChannel bool, serverAddr string, dopts []grpc.DialOption) (latency time.Duration, err error) {
func doOneSoakIteration(ctx context.Context, tc testgrpc.TestServiceClient, resetChannel bool, serverAddr string, dopts []grpc.DialOption) (latency time.Duration, peer peer.Peer, err error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit this is existing art, but naked returns are not ideal for anything other than really small functions.
See: go/go-style/decisions#named-result-parameters

Not asking you change that in this PR, but if we can avoid adding more named result parameters to this function, that would be nice.

One option is to pass call options to this function. So, something like this:

func doOneSoakIteration(ctx context.Context, tc testgrpc.TestServiceClient, resetChannel bool, serverAddr string, dopts []grpc.DialOption, copts []grpc.CallOption) (latency time.Duration, err error) {
  ...
  reply, err = client.UnaryCall(ctx, req, copts...)
  ...
}

And then, the caller can create the peer.Peer, pass it as a CallOption to this function, and inspect the former after the RPC. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - done

start := time.Now()
client := tc
if resetChannel {
Expand All @@ -698,7 +699,7 @@ func doOneSoakIteration(ctx context.Context, tc testgrpc.TestServiceClient, rese
Payload: pl,
}
var reply *testpb.SimpleResponse
reply, err = client.UnaryCall(ctx, req)
reply, err = client.UnaryCall(ctx, req, grpc.Peer(&peer))
if err != nil {
err = fmt.Errorf("/TestService/UnaryCall RPC failed: %s", err)
return
Expand Down Expand Up @@ -733,20 +734,20 @@ func DoSoakTest(tc testgrpc.TestServiceClient, serverAddr string, dopts []grpc.D
break
}
iterationsDone++
latency, err := doOneSoakIteration(ctx, tc, resetChannel, serverAddr, dopts)
latency, peer, err := doOneSoakIteration(ctx, tc, resetChannel, serverAddr, dopts)
latencyMs := int64(latency / time.Millisecond)
h.Add(latencyMs)
if err != nil {
totalFailures++
fmt.Fprintf(os.Stderr, "soak iteration: %d elapsed_ms: %d failed: %s\n", i, latencyMs, err)
fmt.Fprintf(os.Stderr, "soak iteration: %d elapsed_ms: %d peer: %s failed: %s\n", i, latencyMs, peer.Addr.String(), err)
continue
}
if latency > perIterationMaxAcceptableLatency {
totalFailures++
fmt.Fprintf(os.Stderr, "soak iteration: %d elapsed_ms: %d exceeds max acceptable latency: %d\n", i, latencyMs, perIterationMaxAcceptableLatency.Milliseconds())
fmt.Fprintf(os.Stderr, "soak iteration: %d elapsed_ms: %d peer: %s exceeds max acceptable latency: %d\n", i, latencyMs, peer.Addr.String(), perIterationMaxAcceptableLatency.Milliseconds())
continue
}
fmt.Fprintf(os.Stderr, "soak iteration: %d elapsed_ms: %d succeeded\n", i, latencyMs)
fmt.Fprintf(os.Stderr, "soak iteration: %d elapsed_ms: %d peer: %s succeeded\n", i, latencyMs, peer.Addr.String())
}
var b bytes.Buffer
h.Print(&b)
Expand Down