Files
MapLibreParticleLab/test/storage/http_load.cpp
Konstantin Käfer 94a5ac857f [core] all requests have to be canceled explicitly now
By not automatically destroying Request objects after the result has been delivered, we are making sure that we can potentially fire the callback multiple times without adverse effects. This means that you have to hold on to the result of fs->request(), can explicitly cancel it if you don't want to be notified of data changes anymore. Not doing so will monitor the request indefinitely and will prevent the app from exiting.
2015-10-26 15:54:27 +01:00

49 lines
1.2 KiB
C++

#include "storage.hpp"
#include <uv.h>
#include <mbgl/storage/default_file_source.hpp>
TEST_F(Storage, HTTPLoad) {
SCOPED_TEST(HTTPLoad)
using namespace mbgl;
DefaultFileSource fs(nullptr);
const int concurrency = 50;
const int max = 10000;
int number = 1;
Request* reqs[concurrency];
std::function<void(int)> req = [&](int i) {
const auto current = number++;
reqs[i] = fs.request({ Resource::Unknown,
std::string("http://127.0.0.1:3000/load/") + std::to_string(current) },
uv_default_loop(), [&, i, current](const Response &res) {
fs.cancel(reqs[i]);
reqs[i] = nullptr;
EXPECT_EQ(Response::Successful, res.status);
EXPECT_EQ(std::string("Request ") + std::to_string(current), res.data);
EXPECT_EQ(0, res.expires);
EXPECT_EQ(0, res.modified);
EXPECT_EQ("", res.etag);
EXPECT_EQ("", res.message);
if (number <= max) {
req(i);
} else if (current == max) {
HTTPLoad.finish();
}
});
};
for (int i = 0; i < concurrency; i++) {
req(i);
}
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}