From a5c0f582f93ae9596c965691063e72ab056f5ada Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Wed, 22 Apr 2020 13:02:39 +0300 Subject: [PATCH] [core] Database file source does not return stored tiles for volatile resources The `DatabaseFileSource.VolatileResource` test is included. --- .../src/mbgl/storage/database_file_source.cpp | 2 +- test/storage/database_file_source.test.cpp | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/platform/default/src/mbgl/storage/database_file_source.cpp b/platform/default/src/mbgl/storage/database_file_source.cpp index 07a5291e050..da1ca45926f 100644 --- a/platform/default/src/mbgl/storage/database_file_source.cpp +++ b/platform/default/src/mbgl/storage/database_file_source.cpp @@ -27,7 +27,7 @@ class DatabaseFileSourceThread { offlineResponse->noContent = true; offlineResponse->error = std::make_unique(Response::Error::Reason::NotFound, "Not found in offline database"); - } else if (!offlineResponse->isUsable()) { + } else if (resource.storagePolicy == Resource::StoragePolicy::Volatile || !offlineResponse->isUsable()) { offlineResponse->error = std::make_unique(Response::Error::Reason::NotFound, "Cached resource is unusable"); } diff --git a/test/storage/database_file_source.test.cpp b/test/storage/database_file_source.test.cpp index 62e59546054..fa94c854b54 100644 --- a/test/storage/database_file_source.test.cpp +++ b/test/storage/database_file_source.test.cpp @@ -22,5 +22,34 @@ TEST(DatabaseFileSource, PauseResume) { util::Timer resumeTimer; resumeTimer.start(Milliseconds(5), Duration::zero(), [dbfs] { dbfs->resume(); }); + loop.run(); +} + +TEST(DatabaseFileSource, VolatileResource) { + util::RunLoop loop; + + std::shared_ptr dbfs = + FileSourceManager::get()->getFileSource(FileSourceType::Database, ResourceOptions{}); + + Resource resource{Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly}; + Response response{}; + response.data = std::make_shared("Cached value"); + std::unique_ptr req; + + dbfs->forward(resource, response, [&] { + req = dbfs->request(resource, [&](Response res1) { + EXPECT_EQ(nullptr, res1.error); + ASSERT_TRUE(res1.data.get()); + EXPECT_EQ("Cached value", *res1.data); + resource.storagePolicy = Resource::StoragePolicy::Volatile; + req = dbfs->request(resource, [&](Response res2) { + req.reset(); + ASSERT_TRUE(res2.error.get()); + EXPECT_EQ(Response::Error::Reason::NotFound, res2.error->reason); + EXPECT_EQ("Cached resource is unusable", res2.error->message); + loop.stop(); + }); + }); + }); loop.run(); } \ No newline at end of file