Skip to content

Commit

Permalink
Use grpc context for GetSystemInfo. (temporalio#1528)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns committed Jun 24, 2024
1 parent 652b15d commit 5c6a928
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
45 changes: 45 additions & 0 deletions internal/grpc_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,33 @@ func TestEagerAndLazyClient(t *testing.T) {
srv.getSystemInfoResponseError = nil
err = c.SignalWorkflow(context.Background(), "workflow1", "", "my-signal", nil)
require.NoError(t, err)
// Verify version headers are set
require.Equal(
t,
[]string{SDKVersion},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientVersionHeaderName),
)
require.Equal(
t,
[]string{clientNameHeaderValue},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientNameHeaderName),
)

// Now that there's no sys info response error, eager should succeed
c, err = DialClient(context.Background(), ClientOptions{HostPort: srv.addr})
require.NoError(t, err)
defer c.Close()
// Verify version headers are set
require.Equal(
t,
[]string{SDKVersion},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientVersionHeaderName),
)
require.Equal(
t,
[]string{clientNameHeaderValue},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientNameHeaderName),
)

// And even if it starts erroring, the success was memoized so calls succeed
srv.getSystemInfoResponseError = fmt.Errorf("some server failure")
Expand Down Expand Up @@ -456,6 +478,17 @@ func TestCredentialsAPIKey(t *testing.T) {
[]string{"Bearer my-api-key"},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, "Authorization"),
)
// Verify version headers are set
require.Equal(
t,
[]string{SDKVersion},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientVersionHeaderName),
)
require.Equal(
t,
[]string{clientNameHeaderValue},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientNameHeaderName),
)

// Overwrite via context
_, err = client.WorkflowService().GetSystemInfo(
Expand Down Expand Up @@ -483,6 +516,18 @@ func TestCredentialsAPIKey(t *testing.T) {
[]string{"Bearer my-callback-api-key"},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, "Authorization"),
)

// Verify version headers are set
require.Equal(
t,
[]string{SDKVersion},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientVersionHeaderName),
)
require.Equal(
t,
[]string{clientNameHeaderValue},
metadata.ValueFromIncomingContext(srv.getSystemInfoRequestContext, clientNameHeaderName),
)
}

func TestCredentialsMTLS(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,9 +1229,9 @@ func (wc *WorkflowClient) loadCapabilities(ctx context.Context, getSystemInfoTim
if getSystemInfoTimeout == 0 {
getSystemInfoTimeout = defaultGetSystemInfoTimeout
}
ctx, cancel := context.WithTimeout(ctx, getSystemInfoTimeout)
grpcCtx, cancel := newGRPCContext(ctx, grpcTimeout(getSystemInfoTimeout))
defer cancel()
resp, err := wc.workflowService.GetSystemInfo(ctx, &workflowservice.GetSystemInfoRequest{})
resp, err := wc.workflowService.GetSystemInfo(grpcCtx, &workflowservice.GetSystemInfoRequest{})
// We ignore unimplemented
if _, isUnimplemented := err.(*serviceerror.Unimplemented); err != nil && !isUnimplemented {
return nil, fmt.Errorf("failed reaching server: %w", err)
Expand Down

0 comments on commit 5c6a928

Please sign in to comment.