[test] Added unit test for style request failures

This commit is contained in:
Thiago Marcos P. Santos
2017-02-06 16:27:51 +01:00
committed by Thiago Marcos P. Santos
parent e6659242bc
commit 318690645e
2 changed files with 79 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -244,6 +245,53 @@ TEST(Map, StyleLoadedSignal) {
EXPECT_FALSE(emitted);
}
// Test for https://github.com/mapbox/mapbox-gl-native/issues/7902
TEST(Map, TEST_REQUIRES_SERVER(StyleNetworkErrorRetry)) {
MapTest test;
OnlineFileSource fileSource;
Map map(test.backend, test.view.size, 1, fileSource, test.threadPool, MapMode::Still);
map.setStyleURL("http://127.0.0.1:3000/style-fail-once-500");
test.backend.setMapChangeCallback([&](MapChange change) {
if (change == mbgl::MapChangeDidFinishLoadingStyle) {
test.runLoop.stop();
}
});
test.runLoop.run();
}
TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
MapTest test;
OnlineFileSource fileSource;
Map map(test.backend, test.view.size, 1, fileSource, test.threadPool, MapMode::Still);
map.setStyleURL("http://127.0.0.1:3000/style-fail-once-404");
using namespace std::chrono_literals;
util::Timer timer;
// Not found errors should not trigger a retry like other errors.
test.backend.setMapChangeCallback([&](MapChange change) {
if (change == mbgl::MapChangeDidFinishLoadingStyle) {
FAIL() << "Should not retry on not found!";
}
if (change == mbgl::MapChangeDidFailLoadingMap) {
timer.start(Milliseconds(1100), 0s, [&] {
test.runLoop.stop();
});
}
});
test.runLoop.run();
// Should also not retry if the response has cache headers.
map.setStyleURL("http://127.0.0.1:3000/style-fail-once-404-cache");
test.runLoop.run();
}
TEST(Map, AddLayer) {
MapTest test;