Jiri Daněk created PROTON-1676:
----------------------------------
Summary: Check that scheduled tasks are executed, despite closed
connection or stopped container
Key: PROTON-1676
URL: https://issues.apache.org/jira/browse/PROTON-1676
Project: Qpid Proton
Issue Type: Test
Components: cpp-binding
Reporter: Jiri Daněk
Assignee: Cliff Jansen
Priority: Minor
{code}
/// Checks that scheduled tasks are executed, despite closed connection or
stopped container
struct end_with_scheduled_tasks_tester : public proton::messaging_handler {
enum end_t {STOP, CLOSE};
proton::listener listener;
test_port port;
enum end_t end;
bool done;
int scheduled_work;
end_with_scheduled_tasks_tester(enum end_t end) : end(end), done(false),
scheduled_work(0) {}
void on_container_start(proton::container& c) PN_CPP_OVERRIDE {
c.schedule(proton::duration(250), [this]() { this->scheduled_work++; });
if (end == STOP) {
c.stop();
} else {
listener = c.listen(port.url());
c.connect(port.url("localhost"));
}
}
void on_connection_open(proton::connection& c) PN_CPP_OVERRIDE {
std::cout << "on connection open" << std::endl;
c.container().schedule(proton::duration(250), [this]() {
this->scheduled_work++; });
if (end == CLOSE) {
c.close();
}
}
void on_connection_close(proton::connection& c) PN_CPP_OVERRIDE {
c.container().schedule(proton::duration(250), [this]() {
this->scheduled_work++; });
if (!done) {
done = true;
listener.stop();
}
}
};
int test_close_with_scheduled_tasks_in_queue() {
end_with_scheduled_tasks_tester t(end_with_scheduled_tasks_tester::CLOSE);
proton::container(t).run();
// this reactor connects to itself, so on_connection_open and
on_connection_close is called twice, for both ends
ASSERT_EQUAL(t.scheduled_work, 5);
ASSERT(t.done);
return 0;
}
int test_stop_with_scheduled_tasks_in_queue() {
end_with_scheduled_tasks_tester t(end_with_scheduled_tasks_tester::STOP);;
proton::container(t).run();
// this currently fails with failed ASSERT_EQUAL(t.scheduled_work, 1) 0 != 1
// not sure what is the correct number to assert, depends where exactly we
call c.stop()
ASSERT_EQUAL(t.scheduled_work, 1);
ASSERT(t.done);
return 0;
}
{code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]