Skip to content

Commit d7a2128

Browse files
authoredOct 3, 2024··
Enforce nexus request timeout in workflow test suite (#1653)
* Enforce nexus request timeout in workflow test suite * Use GreaterOrEqual to compare timeout
1 parent cdd3070 commit d7a2128

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
 

‎internal/internal_nexus_task_handler.go

+1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ func (h *nexusTaskHandler) goContextForTask(nctx *NexusOperationContext, header
336336
if err != nil {
337337
return nil, nil, nexusHandlerError(nexus.HandlerErrorTypeBadRequest, "cannot parse request timeout")
338338
}
339+
339340
ctx, cancel := context.WithTimeout(ctx, timeout)
340341
return ctx, cancel, nil
341342
}

‎internal/internal_workflow_testsuite.go

+11
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,17 @@ func (env *testWorkflowEnvironmentImpl) ExecuteNexusOperation(
23582358
) int64 {
23592359
seq := env.nextID()
23602360
taskHandler := env.newTestNexusTaskHandler()
2361+
// Use lower case header values to simulate how the Nexus SDK (used internally by the "real" server) would transmit
2362+
// these headers over the wire.
2363+
nexusHeader := make(map[string]string, len(params.nexusHeader))
2364+
for k, v := range params.nexusHeader {
2365+
nexusHeader[strings.ToLower(k)] = v
2366+
}
2367+
params.nexusHeader = nexusHeader
2368+
// The real server allows requests to take up to 10 seconds, mimic that behavior here.
2369+
// Note that if a user sets the Request-Timeout header, it gets overridden.
2370+
params.nexusHeader[strings.ToLower(nexus.HeaderRequestTimeout)] = "10s"
2371+
23612372
handle := &testNexusOperationHandle{
23622373
env: env,
23632374
seq: seq,

‎test/nexus_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,10 @@ func TestReplay(t *testing.T) {
735735

736736
func TestWorkflowTestSuite_NexusSyncOperation(t *testing.T) {
737737
op := nexus.NewSyncOperation("op", func(ctx context.Context, outcome string, opts nexus.StartOperationOptions) (string, error) {
738+
dealine, ok := ctx.Deadline()
739+
require.True(t, ok)
740+
timeout := time.Until(dealine)
741+
require.GreaterOrEqual(t, 10*time.Second, timeout)
738742
require.NotPanicsf(t, func() {
739743
temporalnexus.GetMetricsHandler(ctx)
740744
temporalnexus.GetLogger(ctx)

0 commit comments

Comments
 (0)
Please sign in to comment.