Skip to content
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
4 changes: 2 additions & 2 deletions src/Temporalio/Worker/WorkflowInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ private async Task RunTopLevelAsync(Func<Task> func)
}
if (e.Input.Options?.TypedSearchAttributes is SearchAttributeCollection attrs)
{
cmd.SearchAttributes.IndexedFields.Add(attrs.ToProto().IndexedFields);
cmd.SearchAttributes = attrs.ToProto();
}
if (e.Input.Headers is IDictionary<string, Payload> headers)
{
Expand Down Expand Up @@ -2420,7 +2420,7 @@ public override Task<ChildWorkflowHandle<TWorkflow, TResult>> StartChildWorkflow
}
if (input.Options?.TypedSearchAttributes is SearchAttributeCollection attrs)
{
cmd.SearchAttributes.IndexedFields.Add(attrs.ToProto().IndexedFields);
cmd.SearchAttributes = attrs.ToProto();
}
if (input.Headers is IDictionary<string, Payload> headers)
{
Expand Down
85 changes: 85 additions & 0 deletions tests/Temporalio.Tests/Worker/WorkflowWorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,52 @@ await AssertMore.EventuallyAsync(async () =>
});
}

[Workflow]
public class ChildWorkflowSearchAttributesWorkflow
{
[Workflow]
public class ChildWorkflow
{
[WorkflowRun]
public Task RunAsync() => Workflow.DelayAsync(Timeout.Infinite);
}

[WorkflowRun]
public async Task<string> RunAsync()
{
var attrs = new SearchAttributeCollection.Builder()
.Set(AttrKeyword, "child-keyword")
.ToSearchAttributeCollection();

var childHandle = await Workflow.StartChildWorkflowAsync(
(ChildWorkflow wf) => wf.RunAsync(),
new() { TypedSearchAttributes = attrs });

return childHandle.Id;
}
}

[Fact]
public async Task ExecuteWorkflowAsync_ChildWorkflowSearchAttributes_SetProperly()
{
await EnsureSearchAttributesPresentAsync();
await ExecuteWorkerAsync<ChildWorkflowSearchAttributesWorkflow>(
async worker =>
{
var handle = await Env.Client.StartWorkflowAsync(
(ChildWorkflowSearchAttributesWorkflow wf) => wf.RunAsync(),
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!)
{
ExecutionTimeout = TimeSpan.FromSeconds(5),
});
var childId = await handle.GetResultAsync();
var childDesc = await Env.Client.GetWorkflowHandle(childId).DescribeAsync();
Assert.Equal("child-keyword", childDesc.TypedSearchAttributes.Get(AttrKeyword));
},
new TemporalWorkerOptions()
.AddWorkflow<ChildWorkflowSearchAttributesWorkflow.ChildWorkflow>());
}

[Workflow]
public class MemoWorkflow
{
Expand Down Expand Up @@ -1643,6 +1689,45 @@ await ExecuteWorkerAsync<ContinueAsNewWorkflow>(async worker =>
});
}

[Workflow]
public class ContinueAsNewSearchAttributesWorkflow
{
[WorkflowRun]
public async Task RunAsync(bool continued)
{
if (continued)
{
return;
}
throw Workflow.CreateContinueAsNewException(
(ContinueAsNewSearchAttributesWorkflow wf) => wf.RunAsync(true),
new()
{
TypedSearchAttributes = new SearchAttributeCollection.Builder()
.Set(AttrKeyword, "can-keyword")
.ToSearchAttributeCollection(),
});
}
}

[Fact]
public async Task ExecuteWorkflowAsync_ContinueAsNewSearchAttributes_SetProperly()
{
await EnsureSearchAttributesPresentAsync();
await ExecuteWorkerAsync<ContinueAsNewSearchAttributesWorkflow>(async worker =>
{
var handle = await Env.Client.StartWorkflowAsync(
(ContinueAsNewSearchAttributesWorkflow wf) => wf.RunAsync(false),
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!)
{
ExecutionTimeout = TimeSpan.FromSeconds(5),
});
await handle.GetResultAsync();
var desc = await handle.DescribeAsync();
Assert.Equal("can-keyword", desc.TypedSearchAttributes.Get(AttrKeyword));
});
}

[Workflow]
public class SimpleActivityWorkflow
{
Expand Down
Loading