[core] set a timer and auto-refresh requests when they expire
When we get a request with an explicit expiration time, we're now starting a timer, and will trigger a refresh once the data expires. This gives requesters a chance to update their data.
This commit is contained in:
37
test/storage/http_timeout.cpp
Normal file
37
test/storage/http_timeout.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "storage.hpp"
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
|
||||
|
||||
TEST_F(Storage, HTTPTimeout) {
|
||||
SCOPED_TEST(HTTPTimeout)
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
DefaultFileSource fs(nullptr);
|
||||
|
||||
int counter = 0;
|
||||
|
||||
const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=1" };
|
||||
Request* req = fs.request(resource, uv_default_loop(), [&](const Response &res) {
|
||||
counter++;
|
||||
EXPECT_EQ(Response::Successful, res.status);
|
||||
EXPECT_EQ(false, res.stale);
|
||||
EXPECT_EQ("Hello World!", res.data);
|
||||
EXPECT_LT(0, res.expires);
|
||||
EXPECT_EQ(0, res.modified);
|
||||
EXPECT_EQ("", res.etag);
|
||||
EXPECT_EQ("", res.message);
|
||||
if (counter == 4) {
|
||||
fs.cancel(req);
|
||||
HTTPTimeout.finish();
|
||||
}
|
||||
});
|
||||
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
||||
EXPECT_EQ(4, counter);
|
||||
}
|
||||
Reference in New Issue
Block a user