diff options
Diffstat (limited to 'test/storage/http_coalescing.cpp')
-rw-r--r-- | test/storage/http_coalescing.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/storage/http_coalescing.cpp b/test/storage/http_coalescing.cpp new file mode 100644 index 0000000000..2a82abba2e --- /dev/null +++ b/test/storage/http_coalescing.cpp @@ -0,0 +1,48 @@ +#include "../util.hpp" + +#include <uv.h> + +#include <mbgl/storage/default/default_file_source.hpp> + +TEST(Storage, HTTPCoalescing) { + SCOPED_TEST(HTTPCoalescing) + + static int counter = 0; + const static int total = 4; + + using namespace mbgl; + + DefaultFileSource fs(nullptr, uv_default_loop()); + + static const Response *reference = nullptr; + + const auto complete = [&](const Response &res) { + counter++; + + // Make sure all of the Response objects are the same. + if (!reference) { + reference = &res; + } else { + EXPECT_EQ(reference, &res); + } + + EXPECT_EQ(res.status, Response::Successful); + EXPECT_EQ(res.data, "Hello World!"); + EXPECT_EQ(res.expires, 0); + EXPECT_EQ(res.modified, 0); + EXPECT_EQ(res.etag, ""); + EXPECT_EQ(res.message, ""); + + if (counter >= total) { + HTTPCoalescing.finish(); + } + }; + + const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; + + for (int i = 0; i < total; i++) { + fs.request(resource, uv_default_loop(), complete); + } + + uv_run(uv_default_loop(), UV_RUN_DEFAULT); +} |