Skip to content
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

Some response tests failing because of unthrown exceptions #23

Open
JadeMatrix opened this issue Mar 21, 2018 · 0 comments
Open

Some response tests failing because of unthrown exceptions #23

JadeMatrix opened this issue Mar 21, 2018 · 0 comments
Assignees

Comments

@JadeMatrix
Copy link
Owner

For some reason the way I tried implementing several does-throw tests for show::response doesn't work (see end of issue for code example). It appears writes to the socket succeed and don't block, even if the socket has been closed from the client side or the client isn't reading. This is possibly due to both sockets being in the same process, as I've been able to trigger the desired behavior with two processes, one running a SHOW server and another being a Netcat instance. This needs further investigation; I've leaving these tests artificially failing for now.

The tests are located in tests/response_tests.cpp and are:

  • GracefulClientDisconnectWhileCreating
  • GracefulClientDisconnectWhileSending
  • GracefulClientDisconnectWhileDestroying
  • GracefulConnectionTimeoutWhileCreating
  • GracefulConnectionTimeoutWhileSending
  • GracefulConnectionTimeoutWhileDestroying

An example of how I tried to implement the tests:

TEST( ... )
{
    std::string address = "::";
    int port = 9090;
    show::server test_server( address, port, 1 );
    
    auto request_thread = send_request_async(
        address,
        port,
        []( show::socket_fd request_socket ){
            std::cout << "writing...\n";
            
            write_to_socket(
                request_socket,
                "GET / HTTP/1.0\r\n"
                "Content-Length: 0\r\n"
                "\r\n"
            );
        }
    );
    
    try
    {
        show::connection test_connection = test_server.serve();
        show::request test_request( test_connection );
        test_request.flush();
        std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
        CHECK_THROW(
            ( show::response(
                test_connection,
                show::HTTP_1_0,
                { 200, "OK" },
                {}
            ) ).flush(),
            show::client_disconnected
        );
    }
    catch( ... )
    {
        request_thread.join();
        throw;
    }
    
    request_thread.join();
}
@JadeMatrix JadeMatrix self-assigned this Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant