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

Commit

Permalink
[core] Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Feb 13, 2020
1 parent 3e6c161 commit 0ff2992
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/storage/main_resource_loader.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

0 comments on commit 0ff2992

Please sign in to comment.