-
Notifications
You must be signed in to change notification settings - Fork 33
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
Remove activity definition cache #118
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3012,6 +3012,62 @@ await ExecuteWorkerAsync<TaskEventsWorkflow>( | |
workerOptions); | ||
} | ||
|
||
public class DuplicateActivities | ||
{ | ||
private readonly string returnValue; | ||
|
||
public DuplicateActivities(string returnValue) => this.returnValue = returnValue; | ||
|
||
[Activity] | ||
public string DoThing() => returnValue; | ||
} | ||
|
||
[Workflow] | ||
public class DuplicateActivityWorkflow | ||
{ | ||
[WorkflowRun] | ||
public async Task<string[]> RunAsync(string taskQueue1, string taskQueue2) | ||
{ | ||
return new[] | ||
{ | ||
await Workflow.ExecuteActivityAsync( | ||
(DuplicateActivities act) => act.DoThing(), | ||
new() | ||
{ | ||
TaskQueue = taskQueue1, | ||
ScheduleToCloseTimeout = TimeSpan.FromHours(1), | ||
}), | ||
await Workflow.ExecuteActivityAsync( | ||
(DuplicateActivities act) => act.DoThing(), | ||
new() | ||
{ | ||
TaskQueue = taskQueue2, | ||
ScheduleToCloseTimeout = TimeSpan.FromHours(1), | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ExecuteWorkflowAsync_DuplicateActivity_DoesNotCacheInstance() | ||
{ | ||
await ExecuteWorkerAsync<DuplicateActivityWorkflow>( | ||
async worker1 => | ||
{ | ||
await ExecuteWorkerAsync<DuplicateActivityWorkflow>( | ||
async worker2 => | ||
{ | ||
var ret = await Env.Client.ExecuteWorkflowAsync( | ||
(DuplicateActivityWorkflow wf) => | ||
wf.RunAsync(worker1.Options.TaskQueue!, worker2.Options.TaskQueue!), | ||
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker1.Options.TaskQueue!)); | ||
Assert.Equal(new[] { "instance1", "instance2" }, ret); | ||
}, | ||
new TemporalWorkerOptions().AddAllActivities(new DuplicateActivities("instance2"))); | ||
}, | ||
new TemporalWorkerOptions().AddAllActivities(new DuplicateActivities("instance1"))); | ||
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. The way this test is written in a point-free style makes it a bit hard to read because the test assertion makes reference to 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. That's the consequence of lambdas. Parameters to methods accepting lambdas are invoked and often used before the lambda is invoked. We make the parameters after the lambda because they are optional and many don't use them. This is test code so it is an acceptable tradeoff IMO. |
||
} | ||
|
||
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. Explaining this test to myself:
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. So we're using the lambda passed to 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. Bingo. Before I removed the cache, this test would fail because the result of the workflow would be 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.
Yes
Mostly. It's just so I can get it to create that random task queue which I can use
Basically you have a worker that can run for some amount of time. In non-test code we support a worker running forever, until cancellation token is triggered, and/or until the completion of an async function. In test code, I made |
||
private async Task ExecuteWorkerAsync<TWf>( | ||
Func<TemporalWorker, Task> action, | ||
TemporalWorkerOptions? options = null, | ||
|
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.
Why does this test use two workers with different task queues?
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.
It only needs the activities on different workers not really the workflow (but I just reuse the execute worker helper). We use two workers to confirm that the same activity definition but with different instances for different workers returns different values.
So basically this workflow calls the same activity on different task queues and the test confirms that the activity called was the different instances on different task queues.
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.
It feels to me that the assertion being made is about what happens when we have distinct activity method instances and so it's not obvious that testing it requires multiple workers and task queues.
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 test is specifically "what happens when a workflow calls the same activity method but on different task queues where the different activity instances may have different state". This requires multiple task queues (task queues are 1:1 with workers, so it requires multiple workers).