summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-12-18 18:50:50 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-12-18 18:50:50 (GMT)
commit312a114c7e204cfe4cfe961509ab9b24ccde7860 (patch)
tree7649aba8b50de49f5259709ee3d34b035d83b33b /Swiften/QA/NetworkTest
parent790dd3e97c6634f6a256f2e072507b9d5f29348b (diff)
downloadswift-312a114c7e204cfe4cfe961509ab9b24ccde7860.zip
swift-312a114c7e204cfe4cfe961509ab9b24ccde7860.tar.bz2
Move all domain name resolve queries into one thread.
This avoids reentrancy problems on some platform DNS calls. Resolves: #443
Diffstat (limited to 'Swiften/QA/NetworkTest')
-rw-r--r--Swiften/QA/NetworkTest/DomainNameResolverTest.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
index 1bda585..d0e0a43 100644
--- a/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
+++ b/Swiften/QA/NetworkTest/DomainNameResolverTest.cpp
@@ -34,6 +34,7 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testResolveAddress_IPv4and6);
CPPUNIT_TEST(testResolveAddress_International);
CPPUNIT_TEST(testResolveAddress_Localhost);
+ CPPUNIT_TEST(testResolveAddress_Parallel);
CPPUNIT_TEST(testResolveService);
CPPUNIT_TEST(testResolveService_Error);
CPPUNIT_TEST_SUITE_END();
@@ -115,6 +116,31 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(std::find(addressQueryResult.begin(), addressQueryResult.end(), HostAddress("127.0.0.1")) != addressQueryResult.end());
}
+ void testResolveAddress_Parallel() {
+ std::vector<DomainNameAddressQuery::ref> queries;
+ static const size_t numQueries = 100;
+ for (size_t i = 0; i < numQueries; ++i) {
+ DomainNameAddressQuery::ref query(createAddressQuery("xmpp.test.swift.im"));
+ queries.push_back(query);
+ query->run();
+ }
+
+ eventLoop->processEvents();
+ int ticks = 0;
+ while (allAddressQueryResults.size() < numQueries) {
+ ticks++;
+ if (ticks > 1000) {
+ CPPUNIT_ASSERT(false);
+ }
+ Swift::sleep(10);
+ eventLoop->processEvents();
+ }
+
+ CPPUNIT_ASSERT_EQUAL(numQueries, allAddressQueryResults.size());
+ for (size_t i = 0; i < numQueries; ++i) {
+ CPPUNIT_ASSERT_EQUAL(std::string("10.0.0.0"), allAddressQueryResults[i].toString());
+ }
+ }
void testResolveService() {
boost::shared_ptr<DomainNameServiceQuery> query(createServiceQuery("_xmpp-client._tcp.xmpp-srv.test.swift.im"));
@@ -144,10 +170,6 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
void testResolveService_Error() {
}
-/*
- }
- */
-
private:
boost::shared_ptr<DomainNameAddressQuery> createAddressQuery(const String& domain) {
boost::shared_ptr<DomainNameAddressQuery> result = resolver->createAddressQuery(domain);
@@ -158,6 +180,7 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
void handleAddressQueryResult(const std::vector<HostAddress>& addresses, boost::optional<DomainNameResolveError> error) {
addressQueryResult = addresses;
std::sort(addressQueryResult.begin(), addressQueryResult.end(), CompareHostAddresses());
+ allAddressQueryResults.insert(allAddressQueryResults.begin(), addresses.begin(), addresses.end());
addressQueryError = error;
resultsAvailable = true;
}
@@ -190,6 +213,7 @@ class DomainNameResolverTest : public CppUnit::TestFixture {
DummyEventLoop* eventLoop;
bool resultsAvailable;
std::vector<HostAddress> addressQueryResult;
+ std::vector<HostAddress> allAddressQueryResults;
boost::optional<DomainNameResolveError> addressQueryError;
std::vector<DomainNameServiceQuery::Result> serviceQueryResult;
PlatformDomainNameResolver* resolver;