Skip to content

Commit

Permalink
Enforce nexus request timeout in workflow test suite (#1653)
Browse files Browse the repository at this point in the history
* Enforce nexus request timeout in workflow test suite

* Use GreaterOrEqual to compare timeout
  • Loading branch information
bergundy authored Oct 3, 2024
1 parent cdd3070 commit d7a2128
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/internal_nexus_task_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (h *nexusTaskHandler) goContextForTask(nctx *NexusOperationContext, header
if err != nil {
return nil, nil, nexusHandlerError(nexus.HandlerErrorTypeBadRequest, "cannot parse request timeout")
}

ctx, cancel := context.WithTimeout(ctx, timeout)
return ctx, cancel, nil
}
Expand Down
11 changes: 11 additions & 0 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,17 @@ func (env *testWorkflowEnvironmentImpl) ExecuteNexusOperation(
) int64 {
seq := env.nextID()
taskHandler := env.newTestNexusTaskHandler()
// Use lower case header values to simulate how the Nexus SDK (used internally by the "real" server) would transmit
// these headers over the wire.
nexusHeader := make(map[string]string, len(params.nexusHeader))
for k, v := range params.nexusHeader {
nexusHeader[strings.ToLower(k)] = v
}
params.nexusHeader = nexusHeader
// The real server allows requests to take up to 10 seconds, mimic that behavior here.
// Note that if a user sets the Request-Timeout header, it gets overridden.
params.nexusHeader[strings.ToLower(nexus.HeaderRequestTimeout)] = "10s"

handle := &testNexusOperationHandle{
env: env,
seq: seq,
Expand Down
4 changes: 4 additions & 0 deletions test/nexus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@ func TestReplay(t *testing.T) {

func TestWorkflowTestSuite_NexusSyncOperation(t *testing.T) {
op := nexus.NewSyncOperation("op", func(ctx context.Context, outcome string, opts nexus.StartOperationOptions) (string, error) {
dealine, ok := ctx.Deadline()
require.True(t, ok)
timeout := time.Until(dealine)
require.GreaterOrEqual(t, 10*time.Second, timeout)
require.NotPanicsf(t, func() {
temporalnexus.GetMetricsHandler(ctx)
temporalnexus.GetLogger(ctx)
Expand Down

0 comments on commit d7a2128

Please sign in to comment.