From 9bbd9aba3a8cebf7191ae5b28c8cf16acf39987e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 15 Oct 2015 23:02:11 +0200 Subject: [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. --- test/storage/http_timeout.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/storage/http_timeout.cpp (limited to 'test/storage/http_timeout.cpp') diff --git a/test/storage/http_timeout.cpp b/test/storage/http_timeout.cpp new file mode 100644 index 0000000000..71553677bd --- /dev/null +++ b/test/storage/http_timeout.cpp @@ -0,0 +1,37 @@ +#include "storage.hpp" + +#include + +#include +#include + + +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); +} -- cgit v1.2.1