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