Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce nexus request timeout in workflow test suite #1653

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
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
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"
Comment on lines +2361 to +2370
Copy link
Contributor

Choose a reason for hiding this comment

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

We also set the request timeout for the cancel operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this will set that timeout for all "requests".

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the real server behaviour the minimum of 10s or the remaining schedule to close?

Copy link
Member Author

@bergundy bergundy Oct 3, 2024

Choose a reason for hiding this comment

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

Good point. Not at the moment, but we should enforce that eventually.


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
Loading