[
https://issues.apache.org/jira/browse/PROTON-2438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17618840#comment-17618840
]
ASF GitHub Bot commented on PROTON-2438:
----------------------------------------
DreamPearl commented on code in PR #379:
URL: https://github.com/apache/qpid-proton/pull/379#discussion_r996953467
##########
cpp/src/container_test.cpp:
##########
@@ -574,6 +575,119 @@ void test_container_mt_close_race() {
}
}
+class schedule_cancel : public proton::messaging_handler {
+ proton::listener listener;
+ test_listen_handler listen_handler;
+ long long w1_handle;
+ long long w2_handle;
+ long long w3_handle;
+ long long w4_handle;
+ long long w5_handle;
+
+ void change_w1_state(proton::container* c) {
+ w1_state = 1;
+ }
+
+ void change_w2_state(proton::container* c) {
+ w2_state = 1;
+ }
+
+ void change_w3_state(proton::container* c) {
+ w3_state = 1;
+ }
+
+ void change_w4_state(proton::container* c) {
+ w4_state = 1;
+ }
+
+ void change_w5_state(proton::container* c) {
+ w5_state = 1;
+ }
+
+ void on_container_start(proton::container& c) override {
+ ASSERT(w1_state==0);
+ ASSERT(w2_state==0);
+ ASSERT(w3_state==0);
+ ASSERT(w4_state==0);
+ ASSERT(w5_state==0);
+
+ listener = c.listen("//:0", listen_handler);
+
+ // We will cancel this scheduled task before its execution.
+ w1_handle = c.schedule(proton::duration(250),
proton::make_work(&schedule_cancel::change_w1_state, this, &c));
+
+ // We will cancel this scheduled task before its execution and will
try to cancel it again.
+ w2_handle = c.schedule(proton::duration(260),
proton::make_work(&schedule_cancel::change_w2_state, this, &c));
+
+ // We will not cancel this scheduled task.
+ w3_handle = c.schedule(proton::duration(55),
proton::make_work(&schedule_cancel::change_w3_state, this, &c));
+
+ // We will try to cancel this task before its execution from different
thread i.e connection thread.
+ w4_handle = c.schedule(proton::duration(270),
proton::make_work(&schedule_cancel::change_w4_state, this, &c));
+
+ // We will try to cancel this task after its execution from different
thread i.e. connection thread.
+ w5_handle = c.schedule(proton::duration(50),
proton::make_work(&schedule_cancel::change_w5_state, this, &c));
+
+ // Cancel the first scheduled task.
+ c.cancel(w1_handle);
+
+ // Try cancelling the second scheduled task two times.
+ c.cancel(w2_handle);
+ c.cancel(w2_handle);
+
+ // Try cancelling invalid work handle.
+ c.cancel(-1);
+ c.auto_stop(false);
+ }
+
+ // Get here twice - once for listener, once for connector
+ void on_connection_open(proton::connection &c) override {
+ c.close();
+ }
+
+ void on_connection_close(proton::connection &c) override {
+ // Cross-thread cancelling
+
+ ASSERT(w4_state==0);
+ // Cancel the fourth task before its execution.
+ c.container().cancel(w4_handle);
+
+ // To make sure fifth task has been executed by now.
+ std::this_thread::sleep_for(std::chrono::milliseconds(60));
+
+ ASSERT(w5_state==1);
+ // Cancel the already executed fifth task.
+ c.container().cancel(w5_handle);
+
+ c.container().stop();
+ }
Review Comment:
@astitcher
> [cpp] Cancellable tasks
> -----------------------
>
> Key: PROTON-2438
> URL: https://issues.apache.org/jira/browse/PROTON-2438
> Project: Qpid Proton
> Issue Type: Improvement
> Components: cpp-binding
> Reporter: Božo Dragojevič
> Assignee: Justin Ross
> Priority: Major
>
> Allow scheduled tasks to be cancelled.
> A cancelled task does not keep reactor from stoping running
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]