diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-13 14:00:57 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-14 11:54:02 +0200 |
commit | f42b5e94edd086d09d131b0e53aa72030d30afd7 (patch) | |
tree | 4b453a3b4cfca96f9da741a3f486eb690cf9216f /test | |
parent | 89eab0530df08baf292d6d1260a3ae43019e3541 (diff) | |
download | qtlocation-mapboxgl-f42b5e94edd086d09d131b0e53aa72030d30afd7.tar.gz |
[core] Add unit test
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/main_resource_loader.test.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/storage/main_resource_loader.test.cpp b/test/storage/main_resource_loader.test.cpp index ee9211b064..b5245dbad8 100644 --- a/test/storage/main_resource_loader.test.cpp +++ b/test/storage/main_resource_loader.test.cpp @@ -8,6 +8,7 @@ #include <mbgl/storage/resource_transform.hpp> #include <mbgl/test/util.hpp> #include <mbgl/util/run_loop.hpp> +#include <mbgl/util/timer.hpp> using namespace mbgl; @@ -749,3 +750,38 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CachedResourceLowPriority)) { loop.run(); } + +TEST(MainResourceLoader, TEST_REQUIRES_SERVER(NoDoubleDispatch)) { + util::RunLoop loop; + MainResourceLoader fs(ResourceOptions{}); + + const Resource resource{Resource::Unknown, "http://127.0.0.1:3000/revalidate-same"}; + Response response; + response.data = std::make_shared<std::string>("data"); + response.etag.emplace("snowfall"); + + std::unique_ptr<AsyncRequest> req; + unsigned responseCount = 0u; + auto dbfs = FileSourceManager::get()->getFileSource(FileSourceType::Database, ResourceOptions{}); + dbfs->forward(resource, response, [&] { + req = fs.request(resource, [&](Response res) { + EXPECT_EQ(nullptr, res.error); + EXPECT_FALSE(bool(res.modified)); + EXPECT_TRUE(bool(res.etag)); + EXPECT_EQ("snowfall", *res.etag); + if (!res.notModified) { + ASSERT_TRUE(res.data.get()); + EXPECT_EQ("data", *res.data); + ++responseCount; + } + }); + }); + + util::Timer timer; + timer.start(Milliseconds(100), Duration::zero(), [&loop, &responseCount] { + EXPECT_EQ(1u, responseCount); + loop.stop(); + }); + + loop.run(); +} |