summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2019-05-01 09:00:49 -0500
committerMichael Brasser <michael.brasser@live.com>2019-05-01 17:11:22 +0000
commit1076f342e0e2fd57ba11d1ba513cd079b053dd4e (patch)
tree188d5dce6946b6b07329e2c8ef2b7a7e683d8d47
parent539a087eb099181630b5f5bd20d41a7b4bd45b66 (diff)
Ensure proxied objects are correctly unproxied
If the server goes away, we must unproxy the objects. Otherwise if the server returns we will end up attempting to reproxy the same objects. As a side effect the proxy_multprocess autotest becomes more stable. Change-Id: I9f3f0c9e4aa40790da7a999273badb141beacd62 Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
-rw-r--r--src/remoteobjects/qremoteobjectnode.cpp32
-rw-r--r--src/remoteobjects/qremoteobjectnode_p.h3
-rw-r--r--tests/auto/proxy_multiprocess/proxy/main.cpp6
3 files changed, 32 insertions, 9 deletions
diff --git a/src/remoteobjects/qremoteobjectnode.cpp b/src/remoteobjects/qremoteobjectnode.cpp
index 0e9de09..8e7b2c9 100644
--- a/src/remoteobjects/qremoteobjectnode.cpp
+++ b/src/remoteobjects/qremoteobjectnode.cpp
@@ -2207,6 +2207,16 @@ ProxyInfo::ProxyInfo(QRemoteObjectNode *node, QRemoteObjectHostBase *parent,
++i;
}
});
+
+ connect(registry, &QRemoteObjectRegistry::stateChanged, this,
+ [this](QRemoteObjectRegistry::State state, QRemoteObjectRegistry::State /*oldState*/) {
+ if (state != QRemoteObjectRegistry::Suspect)
+ return;
+ // unproxy all objects
+ for (ProxyReplicaInfo* info : proxiedReplicas)
+ disableAndDeleteObject(info);
+ proxiedReplicas.clear();
+ });
}
ProxyInfo::~ProxyInfo() {
@@ -2299,17 +2309,23 @@ void ProxyInfo::unproxyObject(const QRemoteObjectSourceLocation &entry)
if (proxiedReplicas.contains(name)) {
qCDebug(QT_REMOTEOBJECT) << "Stopping proxy for" << name;
auto const info = proxiedReplicas.take(name);
- if (info->direction == ProxyDirection::Forward)
- this->parentNode->disableRemoting(info->replica);
- else {
- QRemoteObjectHostBase *host = qobject_cast<QRemoteObjectHostBase *>(this->proxyNode);
- Q_ASSERT(host);
- host->disableRemoting(info->replica);
- }
- delete info;
+ disableAndDeleteObject(info);
}
}
+void ProxyInfo::disableAndDeleteObject(ProxyReplicaInfo* info)
+{
+ if (info->direction == ProxyDirection::Forward)
+ this->parentNode->disableRemoting(info->replica);
+ else {
+ QRemoteObjectHostBase *host = qobject_cast<QRemoteObjectHostBase *>(this->proxyNode);
+ Q_ASSERT(host);
+ host->disableRemoting(info->replica);
+ }
+ delete info;
+}
+
+
QT_END_NAMESPACE
#include "moc_qremoteobjectnode.cpp"
diff --git a/src/remoteobjects/qremoteobjectnode_p.h b/src/remoteobjects/qremoteobjectnode_p.h
index bf6a0bd..7fe70ba 100644
--- a/src/remoteobjects/qremoteobjectnode_p.h
+++ b/src/remoteobjects/qremoteobjectnode_p.h
@@ -116,6 +116,9 @@ public:
QRemoteObjectHostBase::RemoteObjectNameFilter proxyFilter;
QRemoteObjectHostBase::RemoteObjectNameFilter reverseFilter;
QHash<QString, ProxyReplicaInfo*> proxiedReplicas;
+
+private:
+ void disableAndDeleteObject(ProxyReplicaInfo* info);
};
struct ProxyReplicaInfo
diff --git a/tests/auto/proxy_multiprocess/proxy/main.cpp b/tests/auto/proxy_multiprocess/proxy/main.cpp
index 46a73a8..6e0932a 100644
--- a/tests/auto/proxy_multiprocess/proxy/main.cpp
+++ b/tests/auto/proxy_multiprocess/proxy/main.cpp
@@ -41,7 +41,11 @@ private Q_SLOTS:
m_hostNode->setHostUrl(QUrl(QStringLiteral("tcp://127.0.0.1:65213")));
m_hostNode->proxy(QUrl("local:testRegistry"));
- QTest::qWait(500);
+ // our proxied object should be added, and then later removed when the server shuts down
+ QSignalSpy addSpy(m_hostNode.data(), &QRemoteObjectNode::remoteObjectAdded);
+ QSignalSpy removeSpy(m_hostNode.data(), &QRemoteObjectNode::remoteObjectRemoved);
+ QVERIFY(addSpy.wait());
+ QVERIFY(removeSpy.wait());
}
private: