From 570bafcfecf2ec9e87eaf280599b9e239bd5c2d4 Mon Sep 17 00:00:00 2001 From: John Firebaugh 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 +#include #include #include #include +#include #include #include #include @@ -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(); + + 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