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 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org For additional commands, e-mail: dev-h...@qpid.apache.org