Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.15k stars 93 forks source link

Fixes to Issues Reported by clang-tidy #53

Closed ahmedyarub closed 3 years ago

ahmedyarub commented 5 years ago

This should provide better code quality and may be even better performance. I've made some small adjustments to unit tests.

ahmedyarub commented 5 years ago

The test passes but it used to wait for 60 seconds before ending. Now it wait for 3 seconds only to speedup unit tests. How can we end the unit test after the response is sent?

eao197 commented 5 years ago

The test passes but it used to wait for 60 seconds before ending. Now it wait for 3 seconds only to speedup unit tests.

create_response should not be called after a call to upgrade.

ahmedyarub commented 5 years ago

Without a response the unit test would fail So what do you suggest to do in this case?

eao197 commented 5 years ago

Without a response the unit test would fail

Which unit-test?

ahmedyarub commented 5 years ago

TEST_CASE( "connection state for WS" , "[connection_state][ws]" )

This one

eao197 commented 5 years ago

This test passes successfully: https://travis-ci.com/Stiffstream/restinio/jobs/229166913#L1917

ahmedyarub commented 5 years ago

This test passes successfully: https://travis-ci.com/Stiffstream/restinio/jobs/229166913#L1917

On Windows it fails with the following log if I don't add the req->create_response() part: `D:\cpp\restinio\dev\test\handle_requests\connection_state\main.cpp:338: Failure: REQUIRE_NOTHROW(response = do_request( request_str )) with expansion: response = do_request( request_str )

D:\cpp\restinio\dev\test\handle_requests\connection_state\main.cpp:338: Failure: unexpected exception [2019-09-06 12:23:56.999] TRACE: starting server on 127.0.0.1:8085 [2019-09-06 12:23:57.001] INFO: init accept #0 [2019-09-06 12:23:57.001] INFO: server started on 127.0.0.1:8085 [2019-09-06 12:23:57.002] TRACE: accept connection from 127.0.0.1:52130 on socket #0 [2019-09-06 12:23:57.003] TRACE: [connection:1] start connection with 127.0.0.1:52130 [2019-09-06 12:23:57.003] TRACE: [connection:1] start waiting for request [2019-09-06 12:23:57.003] TRACE: [connection:1] continue reading request [2019-09-06 12:23:57.003] TRACE: [connection:1] received 204 bytes [2019-09-06 12:23:57.003] TRACE: [connection:1] upgrade request received: GET /chat; Upgrade: 'websocket'; [2019-09-06 12:23:57.003] INFO: [connection:1] handle upgrade request (#0): GET /chat [2019-09-06 12:23:57.003] TRACE: [connection:1] move socket to [ws_connection:1] [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] start connection with 127.0.0.1:52130 [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] start next write group, size: 1 [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] sending data with buf count: 1, total size: 129 [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] start reading header [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] continue reading message [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] kill [2019-09-06 12:23:57.004] TRACE: [ws_connection:1] close socket [2019-09-06 12:23:57.004] TRACE: [connection:1] destructor called [2019-09-06 12:23:57.005] ERROR: [ws_connection:1] reading message header error: The I/O operation has been aborted because of either a thread exit or an application request. [2019-09-06 12:23:57.005] ERROR: [ws_connection:1] unable to write: The I/O operation has been aborted because of either a thread exit or an application request. [2019-09-06 12:23:57.005] TRACE: [ws_connection:1] destructor called [2019-09-06 12:23:57.005] TRACE: closing server on 127.0.0.1:8085 [2019-09-06 12:23:57.005] INFO: server closed on 127.0.0.1:8085 Process finished with exit code 1 `

I built it with the following CMake flags: -DCMAKE_INSTALL_PREFIX="c:/Program Files/Restinio" -DRESTINIO_FIND_DEPS=ON -DCMAKE_TOOLCHAIN_FILE="D:/cpp/vcpkg/scripts/buildsystems/vcpkg.cmake" -DCMAKE_CXX_FLAGS_DEBUG="/MDd /Zi /Ob0 /Od /RTC1 /bigobj /D_WIN32_WINDOWS /D_WINSOCK_DEPRECATED_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS"

ahmedyarub commented 5 years ago

Looks like there are some errors with clang compilation. I'll be making more tests within the next few days.

eao197 commented 5 years ago

On Windows it fails

I think the reason is elsewhere. create_response must not be called after passing a request to upgrade.

I regularly check builds under Windows, but in Release mode only. In Release builds this unit-test doesn't fail. I can suppose that there is some problem with timing in Debug builds where some actions can take much more time than in Release mode.

ahmedyarub commented 5 years ago

On Windows it fails

I think the reason is elsewhere. create_response must not be called after passing a request to upgrade.

I regularly check builds under Windows, but in Release mode only. In Release builds this unit-test doesn't fail. I can suppose that there is some problem with timing in Debug builds where some actions can take much more time than in Release mode.

AppVeyor has Windows builds. I'll create a script within the next few days to automate testing on Windows. I'm testing with Release builds but we might be having different configurations. Automating the builds would probably help in this regards.