server: ensure onClose() called if channel create fails
Setting onClose() alone is no longer enough to claim a channel Surprise. std::function(function&& o) does not fully specify the post-condition of 'o'. move() from std::function members of client Builders is ok to leave in "valid but unspecified" state.
This commit is contained in:
1 parent
956d3c2961
commit
f90f3a5106
8 files changed
+71
-29
No files matched your search
+47
-10
@@ -468,11 +468,19 @@ struct Tester {
|
||||
|
||||
struct ErrorSource : public server::Source
|
||||
{
|
||||
const bool phase = false;
|
||||
const enum phase_t {
|
||||
phaseCreate,
|
||||
phaseOp,
|
||||
phaseGet,
|
||||
} phase;
|
||||
const Value type;
|
||||
explicit ErrorSource(bool phase)
|
||||
:phase(phase)
|
||||
epicsEvent& closedChan;
|
||||
epicsEvent& closedOp;
|
||||
explicit ErrorSource(phase_t pha, epicsEvent& clCh, epicsEvent& clOp)
|
||||
:phase(pha)
|
||||
,type(nt::NTScalar{TypeCode::Int32}.create())
|
||||
,closedChan(clCh)
|
||||
,closedOp(clOp)
|
||||
{}
|
||||
|
||||
virtual void onSearch(Search &op) override final
|
||||
@@ -485,8 +493,20 @@ struct ErrorSource : public server::Source
|
||||
{
|
||||
auto chan = std::move(op);
|
||||
|
||||
auto& clo(closedChan);
|
||||
chan->onClose([&clo](const std::string&) {
|
||||
clo.signal();
|
||||
});
|
||||
|
||||
if(phase==phaseCreate)
|
||||
throw std::runtime_error("Refuse create");
|
||||
|
||||
chan->onOp([this](std::unique_ptr<server::ConnectOp>&& op) {
|
||||
if(!phase) {
|
||||
auto& clo(closedOp);
|
||||
op->onClose([&clo](const std::string&) {
|
||||
clo.signal();
|
||||
});
|
||||
if(phase==phaseOp) {
|
||||
op->error("haha");
|
||||
return;
|
||||
}
|
||||
@@ -498,13 +518,14 @@ struct ErrorSource : public server::Source
|
||||
}
|
||||
};
|
||||
|
||||
void testError(bool phase)
|
||||
void testError(ErrorSource::phase_t phase)
|
||||
{
|
||||
testShow()<<__func__<<" phase="<<phase;
|
||||
|
||||
epicsEvent closedChan, closedOp;
|
||||
auto serv = server::Config::isolated()
|
||||
.build()
|
||||
.addSource("err", std::make_shared<ErrorSource>(phase))
|
||||
.addSource("err", std::make_shared<ErrorSource>(phase, closedChan, closedOp))
|
||||
.start();
|
||||
|
||||
auto cli = serv.clientConfig().build();
|
||||
@@ -521,7 +542,11 @@ void testError(bool phase)
|
||||
|
||||
cli.hurryUp();
|
||||
|
||||
if(testOk1(done.wait(5.0))) {
|
||||
if(phase==ErrorSource::phaseCreate) {
|
||||
// client will silently re-try until cancelled
|
||||
testSkip(2, "client will silently re-try create until cancelled");
|
||||
|
||||
} else if(testOk1(done.wait(5.0))) {
|
||||
testThrows<client::RemoteError>([&actual]() {
|
||||
auto val = actual();
|
||||
testShow()<<"unexpected result\n"<<val;
|
||||
@@ -530,6 +555,17 @@ void testError(bool phase)
|
||||
} else {
|
||||
testSkip(1, "timeout");
|
||||
}
|
||||
if(phase==ErrorSource::phaseCreate) {
|
||||
// early failure during channel creation
|
||||
testSkip(2, "Op not yet created");
|
||||
} else {
|
||||
// later failure during op creation or execution
|
||||
testOk(closedOp.wait(2.0), "wait for operation onClose phase=%d", phase);
|
||||
testOk(!closedChan.tryWait(), "channel not failed");
|
||||
op->cancel();
|
||||
cli.cacheClear("", client::Context::Disconnect); // force close channel
|
||||
}
|
||||
testOk(closedChan.wait(2.0), "wait for channel onClose phase=%d", phase);
|
||||
}
|
||||
|
||||
struct DisconnSource : public server::Source
|
||||
@@ -602,7 +638,7 @@ void testServerClose()
|
||||
|
||||
MAIN(testget)
|
||||
{
|
||||
testPlan(68);
|
||||
testPlan(79);
|
||||
testSetup();
|
||||
logger_config_env();
|
||||
const bool canIPv6 = pvxs::impl::evsocket::canIPv6;
|
||||
@@ -625,8 +661,9 @@ MAIN(testget)
|
||||
Tester().badRequest();
|
||||
Tester().delayExec();
|
||||
Tester().ordering();
|
||||
testError(false);
|
||||
testError(true);
|
||||
testError(ErrorSource::phaseCreate);
|
||||
testError(ErrorSource::phaseOp);
|
||||
testError(ErrorSource::phaseGet);
|
||||
testServerClose();
|
||||
cleanup_for_valgrind();
|
||||
return testDone();
|
||||
|
||||
Reference in new issue
Block a user