-
Notifications
You must be signed in to change notification settings - Fork 64
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
Make pending activations interrupt long poll #89
Merged
vitarb
merged 6 commits into
temporalio:master
from
Sushisource:fix-pending-activtations-not-interrupt-poll
Apr 13, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1905c80
Make pending activations interrupt long poll (daft, needs polish)
Sushisource b9d4351
Add integ test to verify fix
Sushisource c785d0a
Better flexibility for shutdown code re-use
Sushisource f40d078
Disable Jaeger by default to prevent logspam
Sushisource acbafeb
Better clarify docstring
Sushisource c91a7f3
Better encapsulate PA notify
Sushisource File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use crate::integ_tests::{ | ||
create_workflow, get_integ_core, simple_wf_tests::schedule_activity_and_timer_cmds, | ||
}; | ||
use assert_matches::assert_matches; | ||
use rand::Rng; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use temporal_sdk_core::protos::coresdk::{ | ||
activity_task::activity_task as act_task, | ||
workflow_activation::{wf_activation_job, FireTimer, WfActivationJob}, | ||
workflow_commands::{ | ||
ActivityCancellationType, CompleteWorkflowExecution, RequestCancelActivity, | ||
}, | ||
workflow_completion::WfActivationCompletion, | ||
}; | ||
use temporal_sdk_core::Core; | ||
|
||
#[tokio::test] | ||
async fn long_poll_interrupted_by_new_pending_activation() { | ||
let mut rng = rand::thread_rng(); | ||
let task_q_salt: u32 = rng.gen(); | ||
let task_q = format!("activity_cancelled_workflow_{}", task_q_salt.to_string()); | ||
let core = Arc::new(get_integ_core().await); | ||
let workflow_id: u32 = rng.gen(); | ||
create_workflow(&*core, &task_q, &workflow_id.to_string(), None).await; | ||
let activity_id: String = rng.gen::<u32>().to_string(); | ||
let timer_id: String = rng.gen::<u32>().to_string(); | ||
let task = core.poll_workflow_task(&task_q).await.unwrap(); | ||
// Complete workflow task and schedule activity and a timer that fires immediately | ||
core.complete_workflow_task(schedule_activity_and_timer_cmds( | ||
&task_q, | ||
&activity_id, | ||
&timer_id, | ||
ActivityCancellationType::TryCancel, | ||
task, | ||
Duration::from_secs(60), | ||
Duration::from_millis(50), | ||
)) | ||
.await | ||
.unwrap(); | ||
// Poll activity and verify that it's been scheduled with correct parameters, we don't expect to | ||
// complete it in this test as activity is try-cancelled. | ||
let activity_task = core.poll_activity_task(&task_q).await.unwrap(); | ||
assert_matches!( | ||
activity_task.variant, | ||
Some(act_task::Variant::Start(start_activity)) => { | ||
assert_eq!(start_activity.activity_type, "test_activity".to_string()) | ||
} | ||
); | ||
// Poll workflow task and verify that activity has failed. | ||
let task = core.poll_workflow_task(&task_q).await.unwrap(); | ||
assert_matches!( | ||
task.jobs.as_slice(), | ||
[ | ||
WfActivationJob { | ||
variant: Some(wf_activation_job::Variant::FireTimer( | ||
FireTimer { timer_id: t_id } | ||
)), | ||
}, | ||
] => { | ||
assert_eq!(t_id, &timer_id); | ||
} | ||
); | ||
|
||
// Start polling again *before* we complete the WFT | ||
let cc = core.clone(); | ||
let jh = tokio::spawn(async move { | ||
let task = cc.poll_workflow_task(&task_q).await.unwrap(); | ||
assert_matches!( | ||
task.jobs.as_slice(), | ||
[WfActivationJob { | ||
variant: Some(wf_activation_job::Variant::ResolveActivity(_)), | ||
}] | ||
); | ||
cc.complete_workflow_task(WfActivationCompletion::ok_from_cmds( | ||
vec![CompleteWorkflowExecution { result: None }.into()], | ||
task.task_token, | ||
)) | ||
.await | ||
.unwrap(); | ||
}); | ||
|
||
tokio::time::sleep(Duration::from_millis(100)).await; | ||
// Then complete the (last) WFT with a request to cancel the AT, which should produce a | ||
// pending activation, unblocking the (already started) poll | ||
core.complete_workflow_task(WfActivationCompletion::ok_from_cmds( | ||
vec![RequestCancelActivity { | ||
activity_id, | ||
..Default::default() | ||
} | ||
.into()], | ||
task.task_token, | ||
)) | ||
.await | ||
.unwrap(); | ||
|
||
jh.await.unwrap(); | ||
} |
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.
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.
What happens to the poll request in this case?
Is it cancelled? Is it ignored?
We probably don't want to create a new request if we got interrputed.
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.
Yeah it's a good question, was thinking about it after I wrote this. I'll see if I can figure out a way to test that while I finish this. Ideally, it doesn't really matter, because we spit out the PA so fast that when we go back to requesting it'll kinda be like nothing ever happened... but perhaps we need to keep the polling future around in order to ensure that behavior. I'll play with it.
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.
I think this opens up too big of a can of worms to deal with in this PR. Ideally the request should actually be cancelled I think. Keeping it around raises too many questions like "what if the next poll is for a different task queue" or "how long should we buffer the response" and so on. I opened #91 so we can come back to this
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.
I agree, we should discard initial poll as from the lang's perspective it polled and got an activation, it shouldn't care if core made a request to the server or not in order to get it.