aboutsummaryrefslogtreecommitdiffstats
path: root/vbench/src/tests/http_connection/http_connection_test.cpp
blob: 43ca460d0df1915d8dad174eb60f2650e2c56828 (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/testapp.h>
#include <vbench/test/all.h>
#include <vespa/vespalib/net/crypto_engine.h>

using namespace vbench;

auto null_crypto = std::make_shared<vespalib::NullCryptoEngine>();

TEST("http connection") {
    ServerSocket serverSocket;
    HttpConnection client(*null_crypto, ServerSpec("localhost", serverSocket.port()));
    Stream::UP server = serverSocket.accept(*null_crypto);
    EXPECT_TRUE(client.fresh());
    EXPECT_EQUAL("localhost", client.server().host);
    EXPECT_FALSE(client.mayReuse(0.1)); // still fresh
    client.touch(5.0);
    EXPECT_FALSE(client.fresh());
    EXPECT_TRUE(client.mayReuse(5.1));
    server.reset();
    client.stream().obtain(); // trigger eof
    EXPECT_FALSE(client.mayReuse(5.1));
}

TEST_MAIN() { TEST_RUN_ALL(); }