aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-03-03 17:44:48 +0800
committerGitHub <noreply@github.com>2017-03-03 17:44:48 +0800
commit6bfd894f46d12f78e2ea49a58f96763a077bcf49 (patch)
treec509dedf491316af6105e050d6d64f28f856c5cb /test
parent11195360f6742ae49eba513917af8b0b0cd60d09 (diff)
parentea7f5f96408bbdd06417480ac570f2b289f25581 (diff)
downloaddexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.tar
dexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.tar.gz
dexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.tar.bz2
dexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.tar.lz
dexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.tar.xz
dexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.tar.zst
dexon-solidity-6bfd894f46d12f78e2ea49a58f96763a077bcf49.zip
Merge pull request #1725 from ethereum/ipcreadloop
Try reading multiple times from IPC.
Diffstat (limited to 'test')
-rw-r--r--test/RPCSession.cpp49
-rw-r--r--test/RPCSession.h10
2 files changed, 41 insertions, 18 deletions
diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp
index ff00d783..be8774bc 100644
--- a/test/RPCSession.cpp
+++ b/test/RPCSession.cpp
@@ -16,19 +16,20 @@
The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx
*/
-/** @file RPCSession.cpp
- * @author Dimtiry Khokhlov <dimitry@ethdev.com>
- * @author Alex Beregszaszi
- * @date 2016
- */
+/// @file RPCSession.cpp
+/// Low-level IPC communication between the test framework and the Ethereum node.
+
+#include "RPCSession.h"
-#include <string>
-#include <stdio.h>
-#include <thread>
#include <libdevcore/CommonData.h>
+
#include <json/reader.h>
#include <json/writer.h>
-#include "RPCSession.h"
+
+#include <string>
+#include <stdio.h>
+#include <thread>
+#include <chrono>
using namespace std;
using namespace dev;
@@ -107,13 +108,24 @@ string IPCSocket::sendRequest(string const& _req)
return string(m_readBuf, m_readBuf + cbRead);
#else
if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length())
- BOOST_FAIL("Writing on IPC failed");
+ BOOST_FAIL("Writing on IPC failed.");
- ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0);
+ auto start = chrono::steady_clock::now();
+ ssize_t ret;
+ do
+ {
+ ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0);
+ // Also consider closed socket an error.
+ if (ret < 0)
+ BOOST_FAIL("Reading on IPC failed.");
+ }
+ while (
+ ret == 0 &&
+ chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count() < m_readTimeOutMS
+ );
- // Also consider closed socket an error.
- if (ret <= 0)
- BOOST_FAIL("Reading on IPC failed");
+ if (ret == 0)
+ BOOST_FAIL("Timeout reading on IPC.");
return string(m_readBuf, m_readBuf + ret);
#endif
@@ -186,12 +198,17 @@ string RPCSession::eth_getStorageRoot(string const& _address, string const& _blo
void RPCSession::personal_unlockAccount(string const& _address, string const& _password, int _duration)
{
- BOOST_REQUIRE(rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }) == true);
+ BOOST_REQUIRE_MESSAGE(
+ rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }),
+ "Error unlocking account " + _address
+ );
}
string RPCSession::personal_newAccount(string const& _password)
{
- return rpcCall("personal_newAccount", { quote(_password) }).asString();
+ string addr = rpcCall("personal_newAccount", { quote(_password) }).asString();
+ BOOST_MESSAGE("Created account " + addr);
+ return addr;
}
void RPCSession::test_setChainParams(vector<string> const& _accounts)
diff --git a/test/RPCSession.h b/test/RPCSession.h
index 414db323..843036e1 100644
--- a/test/RPCSession.h
+++ b/test/RPCSession.h
@@ -28,11 +28,13 @@
#include <sys/un.h>
#endif
+#include <json/value.h>
+
+#include <boost/test/unit_test.hpp>
+
#include <string>
#include <stdio.h>
#include <map>
-#include <json/value.h>
-#include <boost/test/unit_test.hpp>
#if defined(_WIN32)
class IPCSocket : public boost::noncopyable
@@ -60,8 +62,12 @@ public:
std::string const& path() const { return m_path; }
private:
+
std::string m_path;
int m_socket;
+ /// Socket read timeout in milliseconds. Needs to be large because the key generation routine
+ /// might take long.
+ unsigned static constexpr m_readTimeOutMS = 15000;
char m_readBuf[512000];
};
#endif