summaryrefslogtreecommitdiff
path: root/test/storage
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-08-31 16:43:33 +0200
committerIvo van Dongen <info@ivovandongen.nl>2016-09-13 14:21:37 +0200
commit290bd07a92d7103c67f606c1423785069fc9b776 (patch)
tree00fa0a654830f3cf239932f266e311cab6ebeb59 /test/storage
parentfdaf26b2c02afa6042876962f92b1eaf0ada19bb (diff)
downloadqtlocation-mapboxgl-290bd07a92d7103c67f606c1423785069fc9b776.tar.gz
[core] OnlineFileSource - rate limit
Diffstat (limited to 'test/storage')
-rw-r--r--test/storage/online_file_source.cpp44
-rwxr-xr-xtest/storage/server.js11
2 files changed, 55 insertions, 0 deletions
diff --git a/test/storage/online_file_source.cpp b/test/storage/online_file_source.cpp
index 18179c8448..f67d96f257 100644
--- a/test/storage/online_file_source.cpp
+++ b/test/storage/online_file_source.cpp
@@ -359,3 +359,47 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(NetworkStatusOnlineOffline)) {
loop.run();
}
+
+TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RateLimitStandard)) {
+ util::RunLoop loop;
+ OnlineFileSource fs;
+
+ auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/rate-limit?std=true" }, [&](Response res) {
+ ASSERT_NE(nullptr, res.error);
+ EXPECT_EQ(Response::Error::Reason::RateLimit, res.error->reason);
+ ASSERT_EQ(true, bool(res.error->retryAfter));
+ ASSERT_LT(util::now(), res.error->retryAfter);
+ loop.stop();
+ });
+
+ loop.run();
+}
+
+TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RateLimitMBX)) {
+ util::RunLoop loop;
+ OnlineFileSource fs;
+
+ auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/rate-limit?mbx=true" }, [&](Response res) {
+ ASSERT_NE(nullptr, res.error);
+ EXPECT_EQ(Response::Error::Reason::RateLimit, res.error->reason);
+ ASSERT_EQ(true, bool(res.error->retryAfter));
+ ASSERT_LT(util::now(), res.error->retryAfter);
+ loop.stop();
+ });
+
+ loop.run();
+}
+
+TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RateLimitDefault)) {
+ util::RunLoop loop;
+ OnlineFileSource fs;
+
+ auto req = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/rate-limit" }, [&](Response res) {
+ ASSERT_NE(nullptr, res.error);
+ EXPECT_EQ(Response::Error::Reason::RateLimit, res.error->reason);
+ ASSERT_EQ(false, bool(res.error->retryAfter));
+ loop.stop();
+ });
+
+ loop.run();
+}
diff --git a/test/storage/server.js b/test/storage/server.js
index c2f30abc49..a7538b55f1 100755
--- a/test/storage/server.js
+++ b/test/storage/server.js
@@ -116,6 +116,17 @@ app.get('/temporary-error', function(req, res) {
temporaryErrorCounter++;
});
+app.get('/rate-limit', function(req, res) {
+
+ if (req.query.std) {
+ res.setHeader('Retry-After', 1);
+ } else if (req.query.mbx) {
+ res.setHeader('x-rate-limit-reset', Math.round(Date.now() / 1000) + 1);
+ }
+
+ res.status(429).end();
+});
+
app.get('/delayed', function(req, res) {
setTimeout(function() {
res.status(200).send('Response');