Skip to content

Commit

Permalink
[coro_http][ut]add tests (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Nov 4, 2024
1 parent 8ae2183 commit 3b533d9
Show file tree
Hide file tree
Showing 14 changed files with 4,405 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/linux_llvm_cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ jobs:
./metric_test
./struct_pb_test
./reflection_test
./coro_http_test
llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata
llvm-cov show -object coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -instr-profile=test_ylt.profdata -format=html -output-dir=../../.coverage_llvm_cov -ignore-filename-regex="thirdparty|src|template_switch" -show-instantiations=false
llvm-cov show -object coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -object coro_http_test -instr-profile=test_ylt.profdata -format=html -output-dir=../../.coverage_llvm_cov -ignore-filename-regex="thirdparty|src|template_switch" -show-instantiations=false
echo "Done!"
- name: Upload Coverage Results
Expand All @@ -63,7 +64,7 @@ jobs:
echo "Code Coverage Report" > tmp.log
echo "for detail, [goto summary](https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{github.run_id}}) download Artifacts `llvm-cov`" >> tmp.log
echo "\`\`\`" >> tmp.log
llvm-cov report -object coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -instr-profile=test_ylt.profdata -ignore-filename-regex="thirdparty|src|template_switch" -show-region-summary=false >> tmp.log
llvm-cov report -object coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -object coro_http_test -instr-profile=test_ylt.profdata -ignore-filename-regex="thirdparty|src|template_switch" -show-region-summary=false >> tmp.log
echo "\`\`\`" >> tmp.log
- name: Create Comment
Expand Down
12 changes: 12 additions & 0 deletions include/ylt/coro_http/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
*/
#pragma once
#ifdef YLT_ENABLE_SSL
#ifndef CINATRA_ENABLE_SSL
#define CINATRA_ENABLE_SSL
#endif
#endif
#include <ylt/easylog.hpp>
#ifndef CINATRA_LOG_ERROR
#define CINATRA_LOG_ERROR ELOG_ERROR
#endif
#ifndef CINATRA_LOG_WARNING
#define CINATRA_LOG_WARNING ELOG_WARN
#endif
#ifndef CINATRA_LOG_INFO
#define CINATRA_LOG_INFO ELOG_INFO
#endif
#ifndef CINATRA_LOG_DEBUG
#define CINATRA_LOG_DEBUG ELOG_DEBUG
#endif
#ifndef CINATRA_LOG_TRACE
#define CINATRA_LOG_TRACE ELOG_TRACE
#endif

#include <cinatra/coro_http_client.hpp>

Expand Down
12 changes: 12 additions & 0 deletions include/ylt/coro_http/coro_http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
*/
#pragma once
#ifdef YLT_ENABLE_SSL
#ifndef CINATRA_ENABLE_SSL
#define CINATRA_ENABLE_SSL
#endif
#endif
#include <ylt/easylog.hpp>
#ifndef CINATRA_LOG_ERROR
#define CINATRA_LOG_ERROR ELOG_ERROR
#endif
#ifndef CINATRA_LOG_WARNING
#define CINATRA_LOG_WARNING ELOG_WARN
#endif
#ifndef CINATRA_LOG_INFO
#define CINATRA_LOG_INFO ELOG_INFO
#endif
#ifndef CINATRA_LOG_DEBUG
#define CINATRA_LOG_DEBUG ELOG_DEBUG
#endif
#ifndef CINATRA_LOG_TRACE
#define CINATRA_LOG_TRACE ELOG_TRACE
#endif

#include <cinatra/coro_http_server.hpp>

Expand Down
2 changes: 1 addition & 1 deletion include/ylt/coro_io/coro_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ struct channel : public asio::experimental::channel<void(std::error_code, R)> {
};

template <typename R>
inline channel<R> create_load_blancer(
inline channel<R> create_channel(
size_t capacity,
coro_io::ExecutorWrapper<> *executor = coro_io::get_global_executor()) {
return channel<R>(executor, capacity);
Expand Down
6 changes: 3 additions & 3 deletions src/coro_http/examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ void http_proxy() {
assert(!resp_random.resp_body.empty());
}

void coro_load_blancer() {
auto ch = coro_io::create_load_blancer<int>(10000);
void coro_channel() {
auto ch = coro_io::create_channel<int>(10000);
auto ec = async_simple::coro::syncAwait(coro_io::async_send(ch, 41));
assert(!ec);
ec = async_simple::coro::syncAwait(coro_io::async_send(ch, 42));
Expand Down Expand Up @@ -661,6 +661,6 @@ int main() {
test_gzip();
#endif
http_proxy();
coro_load_blancer();
coro_channel();
return 0;
}
46 changes: 46 additions & 0 deletions src/coro_http/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/tests)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Threads REQUIRED)
link_libraries(Threads::Threads)

include_directories(include)
include_directories(include/ylt/thirdparty)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
#-ftree-slp-vectorize with coroutine cause link error. disable it util gcc fix.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-tree-slp-vectorize")
endif()

add_executable(coro_http_test
test_coro_http_server.cpp
test_cinatra.cpp
test_cinatra_websocket.cpp
test_http_parse.cpp
main.cpp
)

add_custom_command(
TARGET coro_http_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/openssl_files
${CMAKE_BINARY_DIR}/src/coro_http/openssl_files)
add_custom_command(
TARGET coro_http_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/openssl_files
${CMAKE_BINARY_DIR}/output/openssl_files)

add_test(NAME coro_http_test COMMAND coro_http_test)
# target_compile_definitions(easylog_test PRIVATE STRUCT_PACK_ENABLE_UNPORTABLE_TYPE)
if (YLT_ENABLE_SSL)
message(STATUS "Use SSL")
find_package(OpenSSL REQUIRED)
add_definitions(-DCINATRA_ENABLE_SSL)
target_link_libraries(coro_http_test OpenSSL::SSL OpenSSL::Crypto)
endif ()
7 changes: 7 additions & 0 deletions src/coro_http/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define DOCTEST_CONFIG_IMPLEMENT

#include "doctest.h"

DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007)
int main(int argc, char** argv) { return doctest::Context(argc, argv).run(); }
DOCTEST_MSVC_SUPPRESS_WARNING_POP
19 changes: 19 additions & 0 deletions src/coro_http/tests/openssl_files/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDKDCCAhACCQDHu0UVVUEr4DANBgkqhkiG9w0BAQsFADBWMQswCQYDVQQGEwJD
TjEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBh
bnkgTHRkMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMjIxMDI1MDM1NzMwWhcNMzIx
MDIyMDM1NzMwWjBWMQswCQYDVQQGEwJDTjEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5
MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMRIwEAYDVQQDDAlsb2NhbGhv
c3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCr6iWgRRYJ9QfKSUPT
nbw2rKZRlSBqnLeLdPam+s8RUA1p+YPoH2HJqIdxcfYmToz5t6G5OX8TFhAssShw
PalRlQm5QHp4pL7nqPV79auB3PYKv6TgOumwDUpoBxcu0l9di9fjYbC2LmpVJeVz
WQxCo+XO/g5YjXN1nPPeBgmZVkRvXLIYCTKshLlUa0nW7hj7Sl8CAV8OBNMBFkf1
2vgcTqhs3yW9gnIwIoCFZvsdAsSbwR6zF1z96MeAYDIZWeyzUXkoZa4OCWwAhqzo
+0JWukuNuHhsQhIJDvIZWHEblT0GlentP8HPXjFnJHYGUAjx3Fj1mH8mFG0fEXXN
06qlAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGbKTy1mfSlJF012jKuIue2valI2
CKz8X619jmxxIzk0k7wcmAlUUrUSFIzdIddZj92wYbBC1YNOWQ4AG5zpFo3NAQaZ
kYGnlt+d2pNHLaT4IV9JM4iwTqPyi+FsOwTjUGHgaOr+tfK8fZmPbDmAE46OlC/a
VVqNPmjaJiM2c/pJOs+HV9PvEOFmV9p5Yjjz4eV3jwqHdOcxZuLJl28/oqz65uCu
LQiivkdVCuwc1IlpRFejkrbkrk28XCCJwokLt03EQj4xs0sjoTKgd92fpjls/tt+
rw+7ILsAsuoWPIdiuCArCU1LXJDz3FDHafX/dxzdVBzpfVgP0rNpS050Mls=
-----END CERTIFICATE-----
30 changes: 30 additions & 0 deletions src/coro_http/tests/openssl_files/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,D920B8941C56ADDC

I2lW3QsAG/xubjtXpXh3wQ5Ru3VZiMkPNjc+G6/2JjjVr1sD+fzCWvvwdqdxGuNJ
gKdpPBHLuQfTTzGETE4NKDkYzmiPTVbZPJ77DyfL2cK1dcZtAY46RsHf+VMI5N8l
Be1jQSB5xvUa88dSIeowPTc2XSnTIoSFWCa38XuqYF7i0a3lv96eAyXpqB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Qj7i9MWCFwTMwNzdUoZI3PWDhXbXDO
lQJS6v3iAPw+KvLJywODe+C4shUqYdrRdUSKE0FfuB8Ajzh86+FmjJcZM+BSxM4J
hC2yjv114jDlsgjFSxQE2K1iotLUY9mfmW8QWVMO3L4LlNpr4ypNLYX0Ph2wgqzQ
kszXTFN11RFKFLUhF0Mi5m4ffMLPD5YyoqO9grpyC1Nt7vxaPPvcvPD86jK3ksqJ
MwucZGgm9HtUuAjGOSljUr0d+d+4pySJbcpH2YDIBHGVsCScYPVg8XZ1CYko3mq/
d6jDUgydraEmQvIPiKMpTE18rW+jierv2FlB8AGcwxm2VWxuM25wQ40J2YuZLY7k
-----END RSA PRIVATE KEY-----
Loading

0 comments on commit 3b533d9

Please sign in to comment.