Skip to content

Commit

Permalink
Make localhost default device (#283)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #283

"localhost" serves as a floating string constant throughout the gloo test codebase. Consolidating this into the `kDefaultDevice` constant. In the future, we could add this to a more generic utils header that all the tests import?

Reviewed By: mingzhe09088

Differential Revision: D26091783

fbshipit-source-id: e9fa34805d93940215811008e9ad728fa778e553
  • Loading branch information
osalpekar authored and facebook-github-bot committed Feb 3, 2021
1 parent 5f867b2 commit bb6aa6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions gloo/test/base_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
namespace gloo {
namespace test {

const char *kDefaultDevice = "localhost";

std::shared_ptr<::gloo::transport::Device> createDevice(Transport transport) {
#if GLOO_HAVE_TRANSPORT_TCP
if (transport == Transport::TCP) {
return ::gloo::transport::tcp::CreateDevice("localhost");
return ::gloo::transport::tcp::CreateDevice(kDefaultDevice);
}
#endif
#if GLOO_HAVE_TRANSPORT_TCP_TLS
if (transport == Transport::TCP_TLS) {
return ::gloo::transport::tcp::tls::CreateDevice(
"localhost", pkey_file, cert_file, ca_cert_file, "");
kDefaultDevice, pkey_file, cert_file, ca_cert_file, "");
}
#endif
#if GLOO_HAVE_TRANSPORT_UV
Expand All @@ -31,7 +33,7 @@ std::shared_ptr<::gloo::transport::Device> createDevice(Transport transport) {
attr.ai_family = AF_UNSPEC;
return ::gloo::transport::uv::CreateDevice(attr);
#else
return ::gloo::transport::uv::CreateDevice("localhost");
return ::gloo::transport::uv::CreateDevice(kDefaultDevice);
#endif
}
#endif
Expand Down
8 changes: 5 additions & 3 deletions gloo/test/tls_tcp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ namespace gloo {
namespace test {
namespace {

const char *kDefaultDevice = "localhost";

class TlsTcpTest : public BaseTest {};

TEST_F(TlsTcpTest, CreateDeviceWithAllEmptyFilePaths) {
bool exception_thrown = false;
try {
::gloo::rendezvous::HashStore store;
auto device =
::gloo::transport::tcp::tls::CreateDevice("localhost", "", "", "", "");
::gloo::transport::tcp::tls::CreateDevice(kDefaultDevice, "", "", "", "");
auto context = device->createContext(0, 1);
} catch (::gloo::EnforceNotMet e) {
exception_thrown = true;
Expand All @@ -41,7 +43,7 @@ TEST_F(TlsTcpTest, CreateDeviceWithCAEmptyFilePaths) {
try {
::gloo::rendezvous::HashStore store;
auto device = ::gloo::transport::tcp::tls::CreateDevice(
"localhost", pkey_file, cert_file, "", "");
kDefaultDevice, pkey_file, cert_file, "", "");
auto context = device->createContext(0, 1);
} catch (::gloo::EnforceNotMet e) {
exception_thrown = true;
Expand All @@ -53,7 +55,7 @@ TEST_F(TlsTcpTest, CreateDeviceWithCAEmptyFilePaths) {

TEST_F(TlsTcpTest, CreateDeviceWithUnknownCA) {
auto device = ::gloo::transport::tcp::tls::CreateDevice(
"localhost", pkey_file, cert_file, cert_file, "");
kDefaultDevice, pkey_file, cert_file, cert_file, "");
auto context = device->createContext(0, 2);
auto &pair0 = context->createPair(0);
auto addrBytes0 = pair0->address().bytes();
Expand Down

0 comments on commit bb6aa6e

Please sign in to comment.