Files
MapLibreParticleLab/test/storage/http_coalescing.cpp
Konstantin Käfer 9781785ab7 scope Requests to an Environment object for easier cancelation
we are now scoping all file requests to an environment object. The FileSource implementation treats
this as an opaque pointer, but allows canceling all Requests that are associated with that pointer.
This is necessary to abort all file requests that originated from a particular Map object. Aborting
a file request is different from canceling a file request: A canceled request doesn't have its
callback called, while an aborted request will have its callback called with an error, indicating
that the environment is going to be shut down.
2015-03-06 08:21:47 -08:00

51 lines
1.2 KiB
C++

#include "storage.hpp"
#include <uv.h>
#include <mbgl/storage/default_file_source.hpp>
TEST_F(Storage, HTTPCoalescing) {
SCOPED_TEST(HTTPCoalescing)
static int counter = 0;
const static int total = 4;
using namespace mbgl;
DefaultFileSource fs(nullptr, uv_default_loop());
auto &env = *static_cast<const Environment *>(nullptr);
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(&res, reference);
}
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);
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(), env, complete);
}
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}