summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/map/map.test.cpp48
-rwxr-xr-xtest/storage/server.js31
2 files changed, 79 insertions, 0 deletions
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index fa331288c5..fd3bfe58d7 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -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;
diff --git a/test/storage/server.js b/test/storage/server.js
index 92e9e9e0e7..b54ff835ec 100755
--- a/test/storage/server.js
+++ b/test/storage/server.js
@@ -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');