-
Notifications
You must be signed in to change notification settings - Fork 97
feat: use thread-local curl handle for multi-concurrency support #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
726641b
2c9df5c
e09e6bf
6a9536e
12eff27
3a73104
f2ad905
9f31e9d
14d6f70
1415a02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,12 @@ | |
| */ | ||
|
|
||
| #include <cstdarg> | ||
| #include <cstdint> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see in the commit history that there was some fighting with clang tidy, with options added at one point and later reverted. Are the changes in |
||
|
|
||
| namespace aws { | ||
| namespace logging { | ||
|
|
||
| enum class verbosity { | ||
| enum class verbosity : std::uint8_t { | ||
| error, | ||
| info, | ||
| debug, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,8 @@ if(DEFINED ENV{GITHUB_ACTIONS}) | |
| FetchContent_MakeAvailable(gtest) | ||
|
|
||
| add_executable(unit_tests | ||
| unit/no_op_test.cpp) | ||
| unit/thread_local_curl_test.cpp | ||
| unit/unit_tests.cpp) | ||
| target_link_libraries(unit_tests PRIVATE gtest_main aws-lambda-runtime) | ||
|
|
||
| # Register unit tests | ||
|
|
@@ -25,7 +26,22 @@ if(DEFINED ENV{GITHUB_ACTIONS}) | |
| LABELS "unit" | ||
| DISCOVERY_TIMEOUT 10) | ||
| else() | ||
| message(STATUS "Unit tests skipped: Not in GitHub Actions environment") | ||
| # Build unit tests using the bundled gtest | ||
|
Comment on lines
28
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why bother with the above actions specific branch if the bundled one works? |
||
| add_executable(unit_tests | ||
| unit/thread_local_curl_test.cpp | ||
| unit/unit_tests.cpp | ||
| gtest/gtest-all.cc) | ||
| target_include_directories(unit_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| target_link_libraries(unit_tests PRIVATE aws-lambda-runtime pthread) | ||
|
|
||
| # Provide a main() for gtest | ||
| target_sources(unit_tests PRIVATE unit/main.cpp) | ||
|
|
||
| include(GoogleTest) | ||
| gtest_discover_tests(unit_tests | ||
| PROPERTIES | ||
| LABELS "unit" | ||
| DISCOVERY_TIMEOUT 10) | ||
| endif() | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #include "gtest/gtest.h" | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| ::testing::InitGoogleTest(&argc, argv); | ||
| return RUN_ALL_TESTS(); | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #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()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this change made?Figure it was from a clang-tidy during development, but didn't audit all the runsah