Skip to content

Commit

Permalink
testrpc: fix race in cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed May 22, 2020
1 parent 1409baf commit 92ea351
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions test/testrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ using namespace pvxs;

struct Tester {
client::Result actual;
epicsEvent done;
epicsEvent start, done;
Value initial;
server::SharedPV mbox;
server::Server serv;
client::Context cli;
bool fail = false;
bool wait = false;

Tester()
:initial(nt::NTScalar{TypeCode::Int32}.create())
Expand All @@ -46,10 +47,13 @@ struct Tester {
initial["value"] = 1;

mbox.onRPC([this](server::SharedPV& pv, std::unique_ptr<server::ExecOp>&& op, Value&& arg) {
if(fail)
if(fail) {
op->error("oops");
else
} else {
if(wait)
start.wait(10.0);
op->reply(arg); // echo
}
});
}

Expand Down Expand Up @@ -142,11 +146,21 @@ struct Tester {
{
mbox.open(initial);
serv.start();
wait = true;

auto arg = initial.cloneEmpty();
arg["value"] = 42;
(void)doCall(std::move(arg));
testOk1(!done.wait(2.1));
// implicit cancel
start.signal();
if(!testOk1(!done.wait(2.1))) {
try {
auto R = actual();
testTrue(false)<<" unexpected success "<<R;
}catch(std::exception& e){
testTrue(false)<<" unexpected error "<<e.what();
}
}

}

Expand Down

0 comments on commit 92ea351

Please sign in to comment.