[
https://issues.apache.org/jira/browse/PROTON-2438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17613499#comment-17613499
]
ASF GitHub Bot commented on PROTON-2438:
----------------------------------------
astitcher commented on code in PR #379:
URL: https://github.com/apache/qpid-proton/pull/379#discussion_r988994668
##########
cpp/src/container_test.cpp:
##########
@@ -574,6 +574,45 @@ void test_container_mt_close_race() {
}
}
+class schedule_cancel : public proton::messaging_handler {
+ long long w1_handle;
+ long long w2_handle;
+
+ void change_w1_state(proton::container* c) {
+ w1_state = 1;
+ }
+
+ void change_w2_state(proton::container* c) {
+ w2_state = 1;
+ }
+
+ void on_container_start(proton::container& c) override {
+ ASSERT(w1_state==0);
+ ASSERT(w2_state==0);
+
+ // Schedule tasks to change the value of w1_state and w2_state to 1.
+ w1_handle = c.schedule(proton::duration(250),
proton::make_work(&schedule_cancel::change_w1_state, this, &c));
+ w2_handle = c.schedule(proton::duration(250),
proton::make_work(&schedule_cancel::change_w2_state, this, &c));
+
+ // Cancel the first scheduled task.
+ c.cancel(w1_handle);
+ }
+
+public:
+ schedule_cancel(): w1_state(0), w2_state(0) {}
+
+ int w1_state;
+ int w2_state;
+};
+
+int test_schedule_cancel() {
Review Comment:
to be consistent the name should be:
test_container_schedule_cancel
##########
cpp/src/container_test.cpp:
##########
@@ -574,6 +574,45 @@ void test_container_mt_close_race() {
}
}
+class schedule_cancel : public proton::messaging_handler {
+ long long w1_handle;
+ long long w2_handle;
+
+ void change_w1_state(proton::container* c) {
+ w1_state = 1;
+ }
+
+ void change_w2_state(proton::container* c) {
+ w2_state = 1;
+ }
+
+ void on_container_start(proton::container& c) override {
+ ASSERT(w1_state==0);
+ ASSERT(w2_state==0);
+
+ // Schedule tasks to change the value of w1_state and w2_state to 1.
+ w1_handle = c.schedule(proton::duration(250),
proton::make_work(&schedule_cancel::change_w1_state, this, &c));
+ w2_handle = c.schedule(proton::duration(250),
proton::make_work(&schedule_cancel::change_w2_state, this, &c));
+
+ // Cancel the first scheduled task.
+ c.cancel(w1_handle);
+ }
+
+public:
+ schedule_cancel(): w1_state(0), w2_state(0) {}
+
+ int w1_state;
+ int w2_state;
+};
+
+int test_schedule_cancel() {
Review Comment:
The tests could be improved:
* Add in some negative testing:
** test canceling invalid work handle
** test cancelling a cancelled work item
** test cancelling an work item that has already executed
* Cross thread cancelling
> [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]