Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Database file source does not return stored tiles for volatile…
Browse files Browse the repository at this point in the history
… resources

The `DatabaseFileSource.VolatileResource` test is included.
  • Loading branch information
pozdnyakov committed Apr 22, 2020
1 parent efcdfe6 commit a5c0f58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion platform/default/src/mbgl/storage/database_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DatabaseFileSourceThread {
offlineResponse->noContent = true;
offlineResponse->error =
std::make_unique<Response::Error>(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>(Response::Error::Reason::NotFound, "Cached resource is unusable");
}
Expand Down
29 changes: 29 additions & 0 deletions test/storage/database_file_source.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileSource> 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<std::string>("Cached value");
std::unique_ptr<mbgl::AsyncRequest> 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();
}

0 comments on commit a5c0f58

Please sign in to comment.