From 570bafcfecf2ec9e87eaf280599b9e239bd5c2d4 Mon Sep 17 00:00:00 2001
From: John Firebaugh <john.firebaugh@gmail.com>
Date: Fri, 23 Sep 2016 15:26:31 -0700
Subject: [core] Don't allow OfflineDownload to flood the request queue

---
 test/storage/offline_download.cpp | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

(limited to 'test/storage')

diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp
index 76a772dd1b..27e57771c8 100644
--- a/test/storage/offline_download.cpp
+++ b/test/storage/offline_download.cpp
@@ -1,8 +1,10 @@
 #include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/fake_file_source.hpp>
 
 #include <mbgl/storage/offline.hpp>
 #include <mbgl/storage/offline_database.hpp>
 #include <mbgl/storage/offline_download.hpp>
+#include <mbgl/storage/http_file_source.hpp>
 #include <mbgl/util/run_loop.hpp>
 #include <mbgl/util/io.hpp>
 #include <mbgl/util/compression.hpp>
@@ -240,6 +242,29 @@ TEST(OfflineDownload, Activate) {
     test.loop.run();
 }
 
+TEST(OfflineDownload, DoesNotFloodTheFileSourceWithRequests) {
+    FakeFileSource fileSource;
+    OfflineTest test;
+    OfflineRegion region = test.createRegion();
+    OfflineDownload download(
+        region.getID(),
+        OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
+        test.db, fileSource);
+
+    auto observer = std::make_unique<MockObserver>();
+
+    download.setObserver(std::move(observer));
+    download.setState(OfflineRegionDownloadState::Active);
+    test.loop.runOnce();
+
+    EXPECT_EQ(1u, fileSource.requests.size());
+
+    fileSource.respond(Resource::Kind::Style, test.response("style.json"));
+    test.loop.runOnce();
+
+    EXPECT_EQ(HTTPFileSource::maximumConcurrentRequests(), fileSource.requests.size());
+}
+
 TEST(OfflineDownload, GetStatusNoResources) {
     OfflineTest test;
     OfflineRegion region = test.createRegion();
-- 
cgit v1.2.1