[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;

View File

@@ -127,6 +127,37 @@ app.get('/rate-limit', function(req, res) {
res.status(429).end();
});
var styleFailOnce500 = true;
app.get('/style-fail-once-500', function (req, res) {
if (styleFailOnce500) {
res.status(500).send('Server Error!');
styleFailOnce500 = false;
} else {
res.status(200).send('{ "version": 8, "name": "Teste Style" }');
}
});
var styleFailOnce404 = true;
app.get('/style-fail-once-404', function (req, res) {
if (styleFailOnce404) {
res.status(404).send('Not found!');
styleFailOnce404 = false;
} else {
res.status(200).send('{ "version": 8, "name": "Teste Style" }');
}
});
var styleFailOnce404Cache = true;
app.get('/style-fail-once-404-cache', function (req, res) {
if (styleFailOnce404Cache) {
res.setHeader('Cache-Control', 'max-age=30');
res.status(404).send('Not found!');
styleFailOnce404Cache = false;
} else {
res.status(200).send('{ "version": 8, "name": "Teste Style" }');
}
});
app.get('/delayed', function(req, res) {
setTimeout(function() {
res.status(200).send('Response');