diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-23 16:11:34 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-26 03:52:02 +0200 |
commit | c8b7066d2e83d3a6f9f72b7db6681b437fa0dc9d (patch) | |
tree | 3733354b01c11d5d1d63e4f2c0f267ab822150ee /test | |
parent | 59a45b8400c1c07b3163c2274b0b59115cc23351 (diff) | |
download | qtlocation-mapboxgl-c8b7066d2e83d3a6f9f72b7db6681b437fa0dc9d.tar.gz |
[tests] Unit tests for clock skew retry timeout
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/http_expires.cpp | 35 | ||||
-rwxr-xr-x | test/storage/server.js | 5 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/storage/http_expires.cpp b/test/storage/http_expires.cpp index 0a37df8e37..676e15da4f 100644 --- a/test/storage/http_expires.cpp +++ b/test/storage/http_expires.cpp @@ -1,5 +1,6 @@ #include "storage.hpp" +#include <mbgl/storage/default_file_source.hpp> #include <mbgl/storage/online_file_source.hpp> #include <mbgl/util/chrono.hpp> #include <mbgl/util/run_loop.hpp> @@ -33,3 +34,37 @@ TEST_F(Storage, HTTPRetryDelayOnExpiredTile) { HTTPRetryDelayOnExpiredTile.finish(); } + +TEST_F(Storage, HTTPRetryOnClockSkew) { + SCOPED_TEST(HTTPRetryOnClockSkew) + + using namespace mbgl; + + util::RunLoop loop; + DefaultFileSource fs(":memory:", "."); + + int counter = 0; + + const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/clockskew" }; + std::unique_ptr<FileRequest> req1 = fs.request(resource, [&](Response res) { + switch (counter++) { + case 0: { + EXPECT_EQ(nullptr, res.error); + EXPECT_GT(SystemClock::now(), res.expires); + } break; + case 1: { + EXPECT_EQ(nullptr, res.error); + + auto now = SystemClock::now(); + EXPECT_LT(now + Seconds(40), res.expires) << "Expiration not interpolated to 60s"; + EXPECT_GT(now + Seconds(80), res.expires) << "Expiration not interpolated to 60s"; + + loop.stop(); + } break; + } + }); + + loop.run(); + + HTTPRetryOnClockSkew.finish(); +} diff --git a/test/storage/server.js b/test/storage/server.js index d15544a0fd..c2f30abc49 100755 --- a/test/storage/server.js +++ b/test/storage/server.js @@ -55,6 +55,11 @@ app.get('/revalidate-same', function(req, res) { } }); +var expiresCounter = 0; +app.get('/clockskew', function (req, res) { + res.setHeader('Expires', (new Date(2010, 1, 1, 10, ++expiresCounter, 0)).toUTCString()); + res.status(200).send('Response'); +}); app.get('/revalidate-modified', function(req, res) { var jan1 = new Date('jan 1 2015 utc'); |