Repository navigation
Expand file tree
/
Copy paththread_local_curl_test.cpp
More file actions
79 lines (69 loc) · 2.35 KB
/
Copy paththread_local_curl_test.cpp
File metadata and controls
79 lines (69 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <gtest/gtest.h>
#include <aws/lambda-runtime/runtime.h>
#include <thread>
#include <atomic>
#include <vector>
using namespace aws::lambda_runtime;
TEST(ThreadLocalCurl, runtime_construction_succeeds)
{
runtime rt("http://127.0.0.1:9001");
auto outcome = rt.get_next();
// We expect a connection failure since there's no server, but the runtime itself should construct fine
ASSERT_FALSE(outcome.is_success());
}
TEST(ThreadLocalCurl, multiple_runtimes_on_same_thread_do_not_crash)
{
{
runtime rt1("http://127.0.0.1:9001");
auto o1 = rt1.get_next();
ASSERT_FALSE(o1.is_success());
}
{
runtime rt2("http://127.0.0.1:9001");
auto o2 = rt2.get_next();
ASSERT_FALSE(o2.is_success());
}
}
TEST(ThreadLocalCurl, concurrent_runtimes_on_different_threads)
{
constexpr int num_threads = 4;
std::vector<std::thread> threads;
std::atomic<int> successes{0};
for (int i = 0; i < num_threads; ++i) {
threads.emplace_back([&successes]() {
runtime rt("http://127.0.0.1:9001");
auto outcome = rt.get_next();
// Connection will fail but runtime should not crash or corrupt state
if (!outcome.is_success()) {
successes.fetch_add(1);
}
});
}
for (auto& t : threads) {
t.join();
}
ASSERT_EQ(successes.load(), num_threads);
}
TEST(ThreadLocalCurl, sequential_requests_on_same_runtime)
{
runtime rt("http://127.0.0.1:9001");
for (int i = 0; i < 5; ++i) {
auto outcome = rt.get_next();
ASSERT_FALSE(outcome.is_success());
}
}
TEST(ThreadLocalCurl, post_success_with_invocation_id_does_not_crash)
{
runtime rt("http://127.0.0.1:9001");
auto response = invocation_response::success("test payload", "application/json");
auto outcome = rt.post_success("test-request-id", response, "test-invocation-uuid-1234");
// Connection will fail but the invocation_id header path should not crash
ASSERT_FALSE(outcome.is_success());
}
TEST(ThreadLocalCurl, post_failure_with_invocation_id_does_not_crash)
{
runtime rt("http://127.0.0.1:9001");
auto response = invocation_response::failure("error msg", "TestError", "");
auto outcome = rt.post_failure("test-request-id", response, "test-invocation-uuid-5678");
ASSERT_FALSE(outcome.is_success());
}