Skip to content

Commit

Permalink
Fix consensus sunny day test (hyperledger-iroha#1310)
Browse files Browse the repository at this point in the history
* Fix wakeup in consensus sunny day test

* Fix file descriptors not being closed in iroha-ed25519 randombytes

Signed-off-by: Andrei Lebedev <[email protected]>
  • Loading branch information
lebdron authored May 8, 2018
1 parent e662fc4 commit e4cb149
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmake/Modules/Finded25519.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ set(VERSION e7188b8393dbe5ac54378610d53630bd4a180038)
set_target_description(ed25519 "Digital signature algorithm" ${URL} ${VERSION})

if (NOT ed25519_FOUND)
if (NOT WIN32)
find_package(Git REQUIRED)
set(PATCH_RANDOM ${GIT_EXECUTABLE} apply ${PROJECT_SOURCE_DIR}/patch/close.patch || true)
endif ()

externalproject_add(hyperledger_ed25519
GIT_REPOSITORY ${URL}
GIT_TAG ${VERSION}
CMAKE_ARGS -DTESTING=OFF -DBUILD=STATIC
PATCH_COMMAND ${PATCH_RANDOM}
BUILD_BYPRODUCTS ${EP_PREFIX}/src/hyperledger_ed25519-build/libed25519.a
INSTALL_COMMAND "" # remove install step
TEST_COMMAND "" # remove test step
Expand Down
29 changes: 29 additions & 0 deletions patch/close.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/lib/randombytes/random/random.c b/lib/randombytes/random/random.c
index e5eca79..e6e862e 100644
--- a/lib/randombytes/random/random.c
+++ b/lib/randombytes/random/random.c
@@ -13,6 +13,7 @@ int randombytes(unsigned char *p, int len) {
while (completed < len) {
ssize_t result = read(source, p + completed, len - completed);
if (result < 0) {
+ close(source);
return ED25519_ERROR;
}
completed += result;
diff --git a/lib/randombytes/urandom/urandom.c b/lib/randombytes/urandom/urandom.c
index ecad2cf..5b4ec0d 100644
--- a/lib/randombytes/urandom/urandom.c
+++ b/lib/randombytes/urandom/urandom.c
@@ -9,9 +9,12 @@ int randombytes(unsigned char *p, int len) {
} else {
ssize_t result = read(source, p, len);
if (result < 0) {
+ close(source);
return ED25519_ERROR; /* something went wrong */
}
}

+ close(source);
+
return ED25519_SUCCESS;
}
15 changes: 12 additions & 3 deletions test/integration/consensus/consensus_sunny_day.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "module/shared_model/builders/protobuf/test_signature_builder.hpp"

using ::testing::An;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;

using namespace iroha::consensus::yac;
Expand Down Expand Up @@ -114,7 +115,7 @@ class ConsensusSunnyDayTest : public ::testing::Test {
}
if (num_peers == 1) {
delay_before = 0;
delay_after = 50;
delay_after = 5 * 1000;
} else {
delay_before = 10 * 1000;
delay_after = 3 * default_peers.size() + 10 * 1000;
Expand All @@ -130,13 +131,19 @@ std::vector<std::shared_ptr<shared_model::interface::Peer>>
ConsensusSunnyDayTest::default_peers;

TEST_F(ConsensusSunnyDayTest, SunnyDayTest) {
std::condition_variable cv;
auto wrapper = make_test_subscriber<CallExact>(yac->on_commit(), 1);
wrapper.subscribe(
[](auto hash) { std::cout << "^_^ COMMITTED!!!" << std::endl; });

EXPECT_CALL(*crypto, verify(An<CommitMessage>()))
.Times(1)
.WillRepeatedly(Return(true));
.WillRepeatedly(DoAll(InvokeWithoutArgs([&cv] {
// wake up after commit is received from the
// network so that it is safe to shutdown
cv.notify_one();
}),
Return(true)));
EXPECT_CALL(*crypto, verify(An<VoteMessage>())).WillRepeatedly(Return(true));

// Wait for other peers to start
Expand All @@ -148,7 +155,9 @@ TEST_F(ConsensusSunnyDayTest, SunnyDayTest) {
ASSERT_TRUE(order);

yac->vote(my_hash, *order);
std::this_thread::sleep_for(std::chrono::milliseconds(delay_after));
std::mutex m;
std::unique_lock<std::mutex> lk(m);
cv.wait_for(lk, std::chrono::milliseconds(delay_after));

ASSERT_TRUE(wrapper.validate());
}
Expand Down

0 comments on commit e4cb149

Please sign in to comment.