diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-05-08 11:20:10 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-05-08 11:20:10 -0700 |
commit | 1cf5af9c3155ea3e7261cf85be2004a528ac3763 (patch) | |
tree | 422dec6bfa5e26f23c202398a621bf71b12eda22 /test | |
parent | 499efc8fef29ef797a97734992f1a6660408b042 (diff) | |
parent | bd8d10bab68cff8cdd7cebf2629a7fe6b20c08e5 (diff) | |
download | qtlocation-mapboxgl-1cf5af9c3155ea3e7261cf85be2004a528ac3763.tar.gz |
Merge remote-tracking branch 'origin/1369-alternate-fix'
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/http_issue_1369.cpp | 44 | ||||
-rw-r--r-- | test/test.gypi | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/test/storage/http_issue_1369.cpp b/test/storage/http_issue_1369.cpp new file mode 100644 index 0000000000..44c190c825 --- /dev/null +++ b/test/storage/http_issue_1369.cpp @@ -0,0 +1,44 @@ +#include "storage.hpp" + +#include <uv.h> + +#include <mbgl/storage/default_file_source.hpp> +#include <mbgl/storage/sqlite_cache.hpp> + +// Test for https://github.com/mapbox/mapbox-gl-native/issue/1369 +// +// A request for http://example.com is made. This triggers a cache get. While the cache get is +// pending, the request is canceled. This removes it from pending. Then, still while the cache get +// is pending, a second request is made for the same resource. This adds an entry back to pending +// and queues another cache request, even though the first one is still pending. Now both cache +// requests resolve to misses, resulting in two HTTP requests for the same resource. The first one +// will notify as expected, the second one will have bound a DefaultFileRequest* in the lambda that +// gets invalidated by the first notify's pending.erase, and when it gets notified, the crash +// occurs. + +TEST_F(Storage, HTTPIssue1369) { + SCOPED_TEST(HTTPIssue1369) + + using namespace mbgl; + + SQLiteCache cache; + DefaultFileSource fs(&cache); + + const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; + + auto req = fs.request(resource, uv_default_loop(), [&](const Response&) { + ADD_FAILURE() << "Callback should not be called"; + }); + fs.cancel(req); + fs.request(resource, uv_default_loop(), [&](const Response &res) { + EXPECT_EQ(Response::Successful, res.status); + EXPECT_EQ("Hello World!", res.data); + EXPECT_EQ(0, res.expires); + EXPECT_EQ(0, res.modified); + EXPECT_EQ("", res.etag); + EXPECT_EQ("", res.message); + HTTPIssue1369.finish(); + }); + + uv_run(uv_default_loop(), UV_RUN_DEFAULT); +} diff --git a/test/test.gypi b/test/test.gypi index 9c6abb7d31..b6afb4fd9f 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -66,6 +66,7 @@ 'storage/http_coalescing.cpp', 'storage/http_error.cpp', 'storage/http_header_parsing.cpp', + 'storage/http_issue_1369.cpp', 'storage/http_load.cpp', 'storage/http_noloop.cpp', 'storage/http_other_loop.cpp', |