-
Notifications
You must be signed in to change notification settings - Fork 44
Handle errors with update result serialization #468
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3081,7 +3081,7 @@ public class DynamicHandlersWorkflow | |
| [WorkflowRun] | ||
| public Task RunAsync() => Workflow.WaitConditionAsync(() => false); | ||
|
|
||
| [WorkflowSignal] | ||
| [WorkflowUpdate] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to fix a mostly-unrelated flake where slow GH runners were not guaranteeing signal order as the test expected |
||
| public async Task SetHandlersAsync() | ||
| { | ||
| Workflow.DynamicSignal = WorkflowSignalDefinition.CreateWithoutAttribute( | ||
|
|
@@ -3106,7 +3106,7 @@ public async Task SetHandlersAsync() | |
| }); | ||
| } | ||
|
|
||
| [WorkflowSignal] | ||
| [WorkflowUpdate] | ||
| public async Task UnsetHandlersAsync() | ||
| { | ||
| Workflow.DynamicSignal = null; | ||
|
|
@@ -3138,7 +3138,7 @@ await ExecuteWorkerAsync<DynamicHandlersWorkflow>( | |
|
|
||
| // Add handlers, and confirm all signals are drained to it and it handles | ||
| // queries/updates | ||
| await handle.SignalAsync(wf => wf.SetHandlersAsync()); | ||
| await handle.ExecuteUpdateAsync(wf => wf.SetHandlersAsync()); | ||
| await handle.SignalAsync("SomeSignal2", new[] { "signal arg 2" }); | ||
| Assert.Equal( | ||
| "done", await handle.QueryAsync<string>("SomeQuery2", new[] { "query arg 2" })); | ||
|
|
@@ -3156,7 +3156,7 @@ await ExecuteWorkerAsync<DynamicHandlersWorkflow>( | |
| (await handle.QueryAsync(wf => wf.Events)).OrderBy(v => v).ToList()); | ||
|
|
||
| // Remove handlers and confirm things go back to unhandled | ||
| await handle.SignalAsync(wf => wf.UnsetHandlersAsync()); | ||
| await handle.ExecuteUpdateAsync(wf => wf.UnsetHandlersAsync()); | ||
| await handle.SignalAsync("SomeSignal3", new[] { "signal arg 3" }); | ||
| queryExc = await Assert.ThrowsAsync<WorkflowQueryFailedException>( | ||
| () => handle.QueryAsync<string>("SomeQuery3", new[] { "query arg 3" })); | ||
|
|
@@ -4168,6 +4168,79 @@ await ExecuteWorkerAsync<ImmediatelyCompleteUpdateAndWorkflow>( | |
| new(taskQueue) { MaxCachedWorkflows = 0 }); | ||
| } | ||
|
|
||
| [Workflow] | ||
| public class UpdateBadResultSerializationWorkflow | ||
| { | ||
| public record MyUpdateResult(string Value); | ||
|
|
||
| [WorkflowRun] | ||
| public Task RunAsync() => Workflow.WaitConditionAsync(() => false); | ||
|
|
||
| [WorkflowUpdate] | ||
| public async Task<MyUpdateResult> DoUpdateAsync(string value) => new(value); | ||
| } | ||
|
|
||
| public class UpdateBadResultSerializationPayloadConverter : IPayloadConverter | ||
| { | ||
| public bool FailTask { get; set; } | ||
|
|
||
| public Payload ToPayload(object? value) | ||
| { | ||
| if (value is UpdateBadResultSerializationWorkflow.MyUpdateResult) | ||
| { | ||
| if (FailTask) | ||
| { | ||
| throw new InvalidOperationException("Intentionally failing task"); | ||
| } | ||
| throw new ApplicationFailureException("Intentionally failing update"); | ||
| } | ||
| return DataConverter.Default.PayloadConverter.ToPayload(value); | ||
| } | ||
|
|
||
| public object? ToValue(Payload payload, Type type) => | ||
| DataConverter.Default.PayloadConverter.ToValue(payload, type); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteWorkflowAsync_Updates_BadResultSerialization() | ||
| { | ||
| // Client with failure payload converter | ||
| var converter = new UpdateBadResultSerializationPayloadConverter(); | ||
| var newOptions = (TemporalClientOptions)Client.Options.Clone(); | ||
| newOptions.DataConverter = DataConverter.Default with { PayloadConverter = converter }; | ||
| var client = new TemporalClient(Client.Connection, newOptions); | ||
|
|
||
| // Update failure | ||
| await ExecuteWorkerAsync<UpdateBadResultSerializationWorkflow>( | ||
| async worker => | ||
| { | ||
| var handle = await client.StartWorkflowAsync( | ||
| (UpdateBadResultSerializationWorkflow wf) => wf.RunAsync(), | ||
| new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!)); | ||
| var exc = await Assert.ThrowsAsync<WorkflowUpdateFailedException>(() => | ||
| handle.ExecuteUpdateAsync(wf => wf.DoUpdateAsync("some value"))); | ||
| Assert.Equal( | ||
| "Intentionally failing update", | ||
| Assert.IsType<ApplicationFailureException>(exc.InnerException).Message); | ||
| }, | ||
| client: client); | ||
|
|
||
| // Task failure | ||
| converter.FailTask = true; | ||
| await ExecuteWorkerAsync<UpdateBadResultSerializationWorkflow>( | ||
| async worker => | ||
| { | ||
| var handle = await client.StartWorkflowAsync( | ||
| (UpdateBadResultSerializationWorkflow wf) => wf.RunAsync(), | ||
| new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!)); | ||
| _ = Task.Run(() => handle.ExecuteUpdateAsync(wf => wf.DoUpdateAsync("some value"))); | ||
| await AssertMore.HasEventEventuallyAsync( | ||
| handle, | ||
| e => e.WorkflowTaskFailedEventAttributes?.Failure?.Message == "Intentionally failing task"); | ||
| }, | ||
| client: client); | ||
| } | ||
|
|
||
| [Workflow] | ||
| public class CurrentBuildIdWorkflow | ||
| { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR makes this a bit ugly, I recommend "hide whitespace" in the this diff view (i.e. https://github.com/temporalio/sdk-dotnet/pull/468/files?diff=unified&w=1)