diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-10-15 23:02:11 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-10-26 15:54:27 +0100 |
commit | 9bbd9aba3a8cebf7191ae5b28c8cf16acf39987e (patch) | |
tree | 0acb1e4b9b027c0b54d87919f29d4962358a2826 /test | |
parent | 6a7334b882a47ca193209f2012843e42aa3ed4e2 (diff) | |
download | qtlocation-mapboxgl-9bbd9aba3a8cebf7191ae5b28c8cf16acf39987e.tar.gz |
[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.
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/http_timeout.cpp | 37 | ||||
-rw-r--r-- | test/test.gypi | 1 |
2 files changed, 38 insertions, 0 deletions
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 <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); +} diff --git a/test/test.gypi b/test/test.gypi index b581053d81..3631c14ef1 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -85,6 +85,7 @@ 'storage/http_load.cpp', 'storage/http_other_loop.cpp', 'storage/http_reading.cpp', + 'storage/http_timeout.cpp', 'style/glyph_store.cpp', 'style/pending_resources.cpp', |