Skip to content

Commit

Permalink
Update torii_async_test
Browse files Browse the repository at this point in the history
  • Loading branch information
motxx committed Jul 14, 2017
1 parent 2983db2 commit f781c1a
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions test/module/irohad/torii/torii_async_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,53 @@ limitations under the License.
#include <endpoint.pb.h>
#include <thread>

const std::string Ip = "0.0.0.0";
const int Port = 50051;
constexpr const char* Ip = "0.0.0.0";
constexpr int Port = 50051;

TEST(ToriiAsyncTest, GetToriiResponseWhenSendingTx) {
ServerRunner runner(Ip, Port);
std::thread th([&runner]{
runner.run();
});
ServerRunner runner {Ip, Port};
std::thread th;

runner.waitForServersReady();
class ToriiAsyncTest : public testing::Test {
public:
virtual void SetUp() {
th = std::thread([]{
runner.run();
});

runner.waitForServersReady();
}

virtual void TearDown() {
runner.shutdown();
th.join();
}
};

TEST_F(ToriiAsyncTest, ToriiBlocking) {
EXPECT_GT(static_cast<int>(iroha::protocol::ResponseCode::OK), 0); // to guarantee ASSERT_EQ works TODO(motxx): More reasonable way.
for (int i = 0; i < 100; i++) {
std::cout << i << std::endl;
auto response = torii::sendTransactionBlocking(iroha::protocol::Transaction {}, Ip, Port);
auto response = torii::CommandClient(Ip, Port)
.ToriiBlocking(iroha::protocol::Transaction {});
ASSERT_EQ(response.code(), iroha::protocol::ResponseCode::OK);
// ASSERT_STREQ(response.message().c_str(), "Torii async response");
}
}

// TODO(motxx): Segmentation fault occurs because an event doesn't executed that causes completion queue to be shut down.
runner.shutdown();
th.join();
/*
* TODO(motxx): We can't use CommandClient::ToriiNonBlocking() for now. gRPC causes the error
* E0714 04:24:40.045388600 4346 sync_posix.c:60] assertion failed: pthread_mutex_lock(mu) == 0
*/
/*
TEST_F(ToriiAsyncTest, ToriiNonBlocking) {
EXPECT_GT(static_cast<int>(iroha::protocol::ResponseCode::OK), 0);
for (int i = 0; i < 100; i++) {
std::cout << i << std::endl;
torii::CommandClient(Ip, Port)
.ToriiNonBlocking(iroha::protocol::Transaction {},
[](iroha::protocol::ToriiResponse response){
ASSERT_EQ(response.code(), iroha::protocol::ResponseCode::OK);
std::cout << "Response validated\n"; // for checking really asynced.
});
}
}
*/

0 comments on commit f781c1a

Please sign in to comment.