Skip to content

Commit

Permalink
test: make functional test less flaky, and get a platform-specific tm…
Browse files Browse the repository at this point in the history
…p directory for tor contexts
  • Loading branch information
Richard Pospesel committed Jul 8, 2023
1 parent 20d036c commit 7cdd2d0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions source/test/functional/precomp.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// C++
#include <filesystem>
#include <iostream>
#include <string>

Expand Down
51 changes: 40 additions & 11 deletions source/test/functional/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,18 @@ TEST_CASE("gosling_cpp_demo") {

cout << "pat service id: " << pat_identity.get() << endl;

std::filesystem::path tmp;
try {
tmp = std::filesystem::temp_directory_path();
} catch (std::filesystem::filesystem_error err) {
REQUIRE_NOTHROW(throw err);
}

// init contexts
unique_ptr<gosling_context> alice_context;
string_view alice_working_dir = "/tmp/gosling_context_test_alice";
const auto alice_working_dir = (tmp / "gosling_context_test_alice").string();
cout << "alice working dir: " << alice_working_dir;

REQUIRE_NOTHROW(::gosling_context_init(
out(alice_context), // out_context
nullptr, // tor bin path
Expand All @@ -212,7 +221,9 @@ TEST_CASE("gosling_cpp_demo") {
create_server_handshake(alice_context); // server callbacks

unique_ptr<gosling_context> pat_context;
string_view pat_working_dir = "/tmp/gosling_context_test_pat";
const auto pat_working_dir = (tmp / "gosling_context_test_pat").string();
cout << "pat working dir: " << pat_working_dir;

REQUIRE_NOTHROW(::gosling_context_init(
out(pat_context), // out_context
nullptr, // tor bin path
Expand Down Expand Up @@ -364,10 +375,19 @@ TEST_CASE("gosling_cpp_demo") {
},
throw_on_error()));

cout << "--- pat begin identity handshake";
REQUIRE_NOTHROW(::gosling_context_begin_identity_handshake(
pat_context.get(), alice_identity.get(), endpointName.data(),
endpointName.size(), throw_on_error()));
bool pat_begin_identity_handshake_succeeded = false;
for (auto k = 1; k <= 3; k++) {
cout << "--- pat begin identity handshake attempt " << k;
try {
::gosling_context_begin_identity_handshake(
pat_context.get(), alice_identity.get(), endpointName.data(),
endpointName.size(), throw_on_error());
pat_begin_identity_handshake_succeeded = true;
break;
} catch (...) {
}
}
REQUIRE(pat_begin_identity_handshake_succeeded);

while (!alice_endpoint_request_complete) {
REQUIRE_NOTHROW(
Expand Down Expand Up @@ -480,11 +500,20 @@ TEST_CASE("gosling_cpp_demo") {
throw_on_error()));

// pat opens chanel to alice's endpoint
cout << "--- pat begin endpoint channel request" << endl;
REQUIRE_NOTHROW(::gosling_context_begin_endpoint_handshake(
pat_context.get(), alice_endpoint_service_id.get(),
pat_onion_auth_private_key.get(), channelName.data(), channelName.size(),
throw_on_error()));
bool pat_begin_endpoint_handshake_succeeded = false;
for (auto k = 1; k <= 3; k++) {
cout << "--- pat begin endpoint channel request attempt " << k << endl;
try {
::gosling_context_begin_endpoint_handshake(
pat_context.get(), alice_endpoint_service_id.get(),
pat_onion_auth_private_key.get(), channelName.data(),
channelName.size(), throw_on_error());
pat_begin_endpoint_handshake_succeeded = true;
break;
} catch (...) {
}
}
REQUIRE(pat_begin_endpoint_handshake_succeeded);

// wait for both channels to be open
while (!pat_channel_request_complete || !alice_channel_request_complete) {
Expand Down

0 comments on commit 7cdd2d0

Please sign in to comment.