summaryrefslogtreecommitdiff
path: root/test/storage/http_noloop.cpp
blob: cd4ebeb2c495b817af82ad5628f4b3c9efdd45ae (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "storage.hpp"

#include <uv.h>

#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/uv.hpp>

TEST_F(Storage, HTTPNoLoop) {
    SCOPED_TEST(HTTPNoLoop)

    using namespace mbgl;

    DefaultFileSource fs(nullptr);

    auto &env = *static_cast<const Environment *>(nullptr);

    const auto mainThread = uv_thread_self();

    // Async handle that keeps the main loop alive until the thread finished
    auto async = new uv_async_t;
    uv_async_init(uv_default_loop(), async, [] (uv_async_t *as, int) {
        uv::close(as);
    });

    fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, nullptr, env,
               [&](const Response &res) {
        EXPECT_NE(uv_thread_self(), mainThread) << "Response was called in the same thread";
        EXPECT_EQ(Response::Successful, res.status);
        EXPECT_EQ("Hello World!", res.data);
        EXPECT_EQ(0, res.expires);
        EXPECT_EQ(0, res.modified);
        EXPECT_EQ("", res.etag);
        EXPECT_EQ("", res.message);
        HTTPNoLoop.finish();

        uv_async_send(async);
    });

    uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}