Skip to content

Commit a8c8506

Browse files
c-p-i-ofacebook-github-bot
authored andcommitted
Back out "fbcode/gloo/test"
Summary: Put back tests that were erroneously removed by codemod. This is because these files were added in OSS and no-one bothered to update the `TARGETS` file. Reviewed By: fduwjj Differential Revision: D65238799 Privacy Context Container: L1267325 fbshipit-source-id: d196d141ab90df04a5673ceefdfdf2378399c08a
1 parent 7069642 commit a8c8506

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

gloo/test/memory_test.cc

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Copyright (c) 2019-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include "gloo/test/base_test.h"
10+
11+
#include <fstream>
12+
#include <sstream>
13+
14+
#ifdef _WIN32
15+
#include <Windows.h>
16+
#include <psapi.h>
17+
#endif
18+
19+
namespace gloo {
20+
namespace test {
21+
namespace {
22+
23+
#ifdef _WIN32
24+
size_t readResidentSetSize() {
25+
PROCESS_MEMORY_COUNTERS counters{};
26+
GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters));
27+
return counters.WorkingSetSize;
28+
}
29+
#else
30+
size_t readResidentSetSize() {
31+
std::stringstream path;
32+
path << "/proc/" << getpid() << "/statm";
33+
std::ifstream f(path.str());
34+
size_t size;
35+
size_t resident;
36+
f >> size >> resident;
37+
return (getpagesize() * resident);
38+
}
39+
#endif
40+
41+
const std::vector<Transport> kTransportsForMemoryTest{
42+
Transport::TCP,
43+
#if GLOO_HAVE_TRANSPORT_TCP_TLS
44+
Transport::TCP_TLS,
45+
#endif
46+
};
47+
48+
// Test parameterization.
49+
using Param = Transport;
50+
51+
// Test fixture.
52+
class MemoryTest : public BaseTest,
53+
public ::testing::WithParamInterface<Param> {};
54+
55+
TEST_P(MemoryTest, ManySlotsNoLeaks) {
56+
const auto transport = GetParam();
57+
spawn(transport, 2, [&](std::shared_ptr<Context> context) {
58+
size_t tmp0;
59+
size_t tmp1;
60+
auto buf0 = context->createUnboundBuffer(&tmp0, sizeof(tmp0));
61+
auto buf1 = context->createUnboundBuffer(&tmp1, sizeof(tmp1));
62+
auto step = [&](size_t slot) {
63+
const auto peer = 1 - context->rank;
64+
if (context->rank == 0) {
65+
buf0->send(peer, slot);
66+
buf1->recv(peer, slot);
67+
buf0->waitSend();
68+
buf1->waitRecv();
69+
} else {
70+
buf0->recv(peer, slot);
71+
buf1->send(peer, slot);
72+
buf0->waitRecv();
73+
buf1->waitSend();
74+
}
75+
};
76+
77+
// Prime processes with a few send/recv ping/pongs
78+
size_t slot = 0;
79+
for (auto i = 0; i < 10; i++) {
80+
step(slot++);
81+
}
82+
83+
// Read current memory usage and run for a while
84+
auto baselineResidentSetSize = readResidentSetSize();
85+
for (auto i = 0; i < 10000; i++) {
86+
step(slot++);
87+
}
88+
89+
// Ensure memory usage didn't increase
90+
auto newResidentSetSize = readResidentSetSize();
91+
ASSERT_EQ(baselineResidentSetSize, newResidentSetSize);
92+
});
93+
}
94+
95+
INSTANTIATE_TEST_CASE_P(
96+
MemoryTestDefault,
97+
MemoryTest,
98+
::testing::ValuesIn(kTransportsForMemoryTest));
99+
100+
} // namespace
101+
} // namespace test
102+
} // namespace gloo

gloo/test/tls_tcp_test.cc

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Copyright (c) 2019-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#include "gloo/config.h"
10+
#if GLOO_HAVE_TRANSPORT_TCP_TLS
11+
12+
#include <gmock/gmock.h>
13+
14+
#include "gloo/test/multiproc_test.h"
15+
#include "gloo/test/openssl_utils.h"
16+
17+
namespace gloo {
18+
namespace test {
19+
namespace {
20+
21+
const char* kDefaultDevice = "localhost";
22+
23+
class TlsTcpTest : public BaseTest {};
24+
25+
TEST_F(TlsTcpTest, CreateDeviceWithAllEmptyFilePaths) {
26+
bool exception_thrown = false;
27+
try {
28+
::gloo::rendezvous::HashStore store;
29+
auto device = ::gloo::transport::tcp::tls::CreateDevice(
30+
kDefaultDevice, "", "", "", "");
31+
auto context = device->createContext(0, 1);
32+
} catch (::gloo::EnforceNotMet e) {
33+
exception_thrown = true;
34+
ASSERT_THAT(
35+
e.what(),
36+
::testing::ContainsRegex(
37+
"Private key and certificate location must be specified"));
38+
}
39+
ASSERT_TRUE(exception_thrown);
40+
}
41+
42+
TEST_F(TlsTcpTest, CreateDeviceWithCAEmptyFilePaths) {
43+
bool exception_thrown = false;
44+
try {
45+
::gloo::rendezvous::HashStore store;
46+
auto device = ::gloo::transport::tcp::tls::CreateDevice(
47+
kDefaultDevice, pkey_file, cert_file, "", "");
48+
auto context = device->createContext(0, 1);
49+
} catch (::gloo::EnforceNotMet e) {
50+
exception_thrown = true;
51+
ASSERT_THAT(
52+
e.what(),
53+
::testing::ContainsRegex("CAfile or CApath must be specified"));
54+
}
55+
ASSERT_TRUE(exception_thrown);
56+
}
57+
58+
TEST_F(TlsTcpTest, CreateDeviceWithUnknownCA) {
59+
auto device = ::gloo::transport::tcp::tls::CreateDevice(
60+
kDefaultDevice, pkey_file, cert_file, cert_file, "");
61+
auto context = device->createContext(0, 2);
62+
auto& pair0 = context->createPair(0);
63+
auto addrBytes0 = pair0->address().bytes();
64+
auto& pair1 = context->createPair(1);
65+
auto addrBytes1 = pair1->address().bytes();
66+
67+
bool exception_thrown = false;
68+
spawnThreads(2, [&](int rank) {
69+
try {
70+
if (rank == 0) {
71+
pair0->connect(addrBytes1);
72+
} else {
73+
pair1->connect(addrBytes0);
74+
}
75+
} catch (::gloo::IoException e) {
76+
exception_thrown = true;
77+
ASSERT_THAT(e.what(), ::testing::ContainsRegex("unknown ca"));
78+
} catch (::gloo::EnforceNotMet e) {
79+
exception_thrown = true;
80+
ASSERT_THAT(
81+
e.what(), ::testing::ContainsRegex("handshake was not succeeded"));
82+
}
83+
});
84+
85+
ASSERT_TRUE(exception_thrown);
86+
}
87+
88+
} // namespace
89+
} // namespace test
90+
} // namespace gloo
91+
#endif

0 commit comments

Comments
 (0)