summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-10-27 12:11:16 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-10-27 12:11:16 +0100
commit32c0fb468f21a4ee9fc606d4536c3687c3412b7d (patch)
tree661c94cc41d51f918e035a2cc86a598c179d6419 /test
parentf3ffb45cf6adbdca375217c645eb455ff47991ec (diff)
downloadqtlocation-mapboxgl-32c0fb468f21a4ee9fc606d4536c3687c3412b7d.tar.gz
[http] don't retry when there's already a request in progress
Diffstat (limited to 'test')
-rw-r--r--test/storage/http_retry_network_status.cpp52
-rw-r--r--test/test.gypi1
2 files changed, 53 insertions, 0 deletions
diff --git a/test/storage/http_retry_network_status.cpp b/test/storage/http_retry_network_status.cpp
new file mode 100644
index 0000000000..238108153d
--- /dev/null
+++ b/test/storage/http_retry_network_status.cpp
@@ -0,0 +1,52 @@
+#include "storage.hpp"
+
+#include <uv.h>
+
+#include <mbgl/storage/default_file_source.hpp>
+#include <mbgl/storage/network_status.hpp>
+
+
+// Test for https://github.com/mapbox/mapbox-gl-native/issues/2123
+//
+// A request is made. While the request is in progress, the network status changes. This should
+// trigger an immediate retry of all requests that are not in progress. This test makes sure that
+// we don't accidentally double-trigger the request.
+
+TEST_F(Storage, HTTPNetworkStatusChange) {
+ SCOPED_TEST(HTTPNetworkStatusChange)
+
+ using namespace mbgl;
+
+ DefaultFileSource fs(nullptr);
+
+ const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" };
+
+ // This request takes 200 milliseconds to answer.
+ Request* req = fs.request(resource, uv_default_loop(), [&](const Response& res) {
+ fs.cancel(req);
+ EXPECT_EQ(Response::Successful, res.status);
+ EXPECT_EQ(false, res.stale);
+ ASSERT_TRUE(res.data.get());
+ EXPECT_EQ("Response", *res.data);
+ EXPECT_EQ(0, res.expires);
+ EXPECT_EQ(0, res.modified);
+ EXPECT_EQ("", res.etag);
+ EXPECT_EQ("", res.message);
+ HTTPNetworkStatusChange.finish();
+ });
+
+ // After 50 milliseconds, we're going to trigger a NetworkStatus change.
+ uv_timer_t reachableTimer;
+ uv_timer_init(uv_default_loop(), &reachableTimer);
+ uv_timer_start(&reachableTimer, [] (uv_timer_t*) {
+ mbgl::NetworkStatus::Reachable();
+ }, 50, 0);
+
+ // This timer will keep the loop alive to make sure we would be getting a response in caes the
+ // network status change triggered another change (which it shouldn't).
+ uv_timer_t delayTimer;
+ uv_timer_init(uv_default_loop(), &delayTimer);
+ uv_timer_start(&delayTimer, [] (uv_timer_t*) {}, 300, 0);
+
+ uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+}
diff --git a/test/test.gypi b/test/test.gypi
index 3631c14ef1..e8d9a9fcc7 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -84,6 +84,7 @@
'storage/http_issue_1369.cpp',
'storage/http_load.cpp',
'storage/http_other_loop.cpp',
+ 'storage/http_retry_network_status.cpp',
'storage/http_reading.cpp',
'storage/http_timeout.cpp',