From c0b75f1af77e78e309cb18807de74f3788488a7a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 27 Apr 2015 13:05:30 -0700 Subject: [PATCH] Remove Environment::terminate and associated code Fixes #1336 --- include/mbgl/map/environment.hpp | 5 -- include/mbgl/storage/default_file_source.hpp | 9 +-- include/mbgl/storage/file_source.hpp | 14 +---- include/mbgl/storage/request.hpp | 8 +-- src/mbgl/map/environment.cpp | 10 +--- src/mbgl/storage/default_file_source.cpp | 41 +------------ src/mbgl/storage/default_file_source_impl.hpp | 1 - src/mbgl/storage/request.cpp | 4 +- test/fixtures/database/cache.db | Bin 0 -> 4096 bytes test/fixtures/database/invalid.db | Bin 0 -> 4096 bytes test/storage/cache_response.cpp | 5 +- test/storage/cache_revalidate.cpp | 14 ++--- test/storage/directory_reading.cpp | 6 +- test/storage/file_reading.cpp | 12 +--- test/storage/http_cancel.cpp | 9 +-- test/storage/http_coalescing.cpp | 4 +- test/storage/http_environment.cpp | 54 ------------------ test/storage/http_error.cpp | 6 +- test/storage/http_header_parsing.cpp | 6 +- test/storage/http_load.cpp | 4 +- test/storage/http_noloop.cpp | 4 +- test/storage/http_other_loop.cpp | 4 +- test/storage/http_reading.cpp | 14 ++--- test/test.gypi | 1 - 24 files changed, 42 insertions(+), 193 deletions(-) create mode 100644 test/fixtures/database/cache.db create mode 100644 test/fixtures/database/invalid.db delete mode 100644 test/storage/http_environment.cpp diff --git a/include/mbgl/map/environment.hpp b/include/mbgl/map/environment.hpp index 1cd33a5e6..a00fb2445 100644 --- a/include/mbgl/map/environment.hpp +++ b/include/mbgl/map/environment.hpp @@ -54,11 +54,6 @@ public: // Only call this while the OpenGL context is exclusive to this thread. void performCleanup(); - // ############################################################################################# - - // Request to terminate the environment. - void terminate(); - private: unsigned id; FileSource& fileSource; diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index f39374716..d50d5ddea 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -16,12 +16,9 @@ public: ~DefaultFileSource() override; // FileSource API - Request *request(const Resource &resource, uv_loop_t *loop, const Environment &env, - Callback callback) override; - void cancel(Request *request) override; - void request(const Resource &resource, const Environment &env, Callback callback) override; - - void abort(const Environment &env) override; + Request* request(const Resource&, uv_loop_t*, Callback) override; + void cancel(Request*) override; + void request(const Resource&, Callback) override; public: class Impl; diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 30e88c39f..535c41e81 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -15,7 +15,6 @@ typedef struct uv_loop_s uv_loop_t; namespace mbgl { class Request; -class Environment; class FileSource : private util::noncopyable { protected: @@ -28,19 +27,12 @@ public: // These can be called from any thread. The callback will be invoked in the loop. // You can only cancel a request from the same thread it was created in. - virtual Request *request(const Resource &resource, uv_loop_t *loop, const Environment &env, - Callback callback) = 0; - virtual void cancel(Request *request) = 0; + virtual Request* request(const Resource&, uv_loop_t*, Callback) = 0; + virtual void cancel(Request*) = 0; // These can be called from any thread. The callback will be invoked in an arbitrary other thread. // You cannot cancel these requests. - virtual void request(const Resource &resource, const Environment &env, Callback callback) = 0; - - // This can be called from any thread. All requests with the environment pointer env should be - // notified as errored. Note that this is /different/ from canceling requests; a canceled - // request's callback is never called, while an aborted request's callback is called with - // a error message. - virtual void abort(const Environment &env) = 0; + virtual void request(const Resource&, Callback) = 0; }; } diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp index 00157329b..a01808ce8 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -17,14 +17,13 @@ typedef struct uv_loop_s uv_loop_t; namespace mbgl { class Response; -class Environment; class Request : private util::noncopyable { MBGL_STORE_THREAD(tid) public: using Callback = std::function; - Request(const Resource &resource, uv_loop_t *loop, const Environment &env, Callback callback); + Request(const Resource &resource, uv_loop_t *loop, Callback callback); public: // May be called from any thread. @@ -48,11 +47,6 @@ private: public: const Resource resource; - - // The environment ref is used to associate requests with a particular environment. This allows - // us to only terminate requests associated with that environment, e.g. when the map the env - // belongs to is discarded. - const Environment &env; }; } diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp index 469790501..4c7a5faf8 100644 --- a/src/mbgl/map/environment.cpp +++ b/src/mbgl/map/environment.cpp @@ -122,13 +122,13 @@ unsigned Environment::getID() const { void Environment::requestAsync(const Resource& resource, std::function callback) { - fileSource.request(resource, *this, std::move(callback)); + fileSource.request(resource, std::move(callback)); } Request* Environment::request(const Resource& resource, std::function callback) { assert(currentlyOn(ThreadType::Map)); - return fileSource.request(resource, loop, *this, std::move(callback)); + return fileSource.request(resource, loop, std::move(callback)); } void Environment::cancelRequest(Request* req) { @@ -178,10 +178,4 @@ void Environment::performCleanup() { } } -// ############################################################################################# - -void Environment::terminate() { - fileSource.abort(*this); -} - } diff --git a/src/mbgl/storage/default_file_source.cpp b/src/mbgl/storage/default_file_source.cpp index 3e02c05fa..7080809d7 100644 --- a/src/mbgl/storage/default_file_source.cpp +++ b/src/mbgl/storage/default_file_source.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" @@ -38,9 +37,8 @@ DefaultFileSource::~DefaultFileSource() { Request* DefaultFileSource::request(const Resource& resource, uv_loop_t* l, - const Environment& env, Callback callback) { - auto req = new Request(resource, l, env, std::move(callback)); + auto req = new Request(resource, l, std::move(callback)); // This function can be called from any thread. Make sure we're executing the actual call in the // file source loop by sending it over the queue. @@ -49,8 +47,8 @@ Request* DefaultFileSource::request(const Resource& resource, return req; } -void DefaultFileSource::request(const Resource& resource, const Environment& env, Callback callback) { - request(resource, nullptr, env, std::move(callback)); +void DefaultFileSource::request(const Resource& resource, Callback callback) { + request(resource, nullptr, std::move(callback)); } void DefaultFileSource::cancel(Request *req) { @@ -61,10 +59,6 @@ void DefaultFileSource::cancel(Request *req) { thread->invoke(&Impl::cancel, req); } -void DefaultFileSource::abort(const Environment &env) { - thread->invoke(&Impl::abort, std::ref(env)); -} - // ----- Impl ----- DefaultFileSource::Impl::Impl(FileCache* cache_, const std::string& root) @@ -163,35 +157,6 @@ void DefaultFileSource::Impl::cancel(Request* req) { req->destruct(); } -// Aborts all requests that are part of the current environment. -void DefaultFileSource::Impl::abort(const Environment& env) { - // Construct a cancellation response. - auto response = std::make_shared(); - response->status = Response::Error; - response->message = "Environment is terminating"; - - // Iterate through all pending requests and remove them in case they're abandoned. - util::erase_if(pending, [&](std::pair& it) -> bool { - // Notify all pending requests that are in the current environment. - util::erase_if(it.second.observers, [&](Request* req) -> bool { - if (&req->env == &env) { - req->notify(response); - return true; - } else { - return false; - } - }); - - bool abandoned = it.second.observers.empty(); - - if (abandoned && it.second.request) { - it.second.request->cancel(); - } - - return abandoned; - }); -} - void DefaultFileSource::Impl::notify(DefaultFileRequest* request, std::shared_ptr response, FileCache::Hint hint) { // First, remove the request, since it might be destructed at any point now. assert(find(request->resource) == request); diff --git a/src/mbgl/storage/default_file_source_impl.hpp b/src/mbgl/storage/default_file_source_impl.hpp index d3f83af38..1d4da0906 100644 --- a/src/mbgl/storage/default_file_source_impl.hpp +++ b/src/mbgl/storage/default_file_source_impl.hpp @@ -26,7 +26,6 @@ public: void add(Request*, uv_loop_t*); void cancel(Request*); - void abort(const Environment&); private: DefaultFileRequest* find(const Resource&); diff --git a/src/mbgl/storage/request.cpp b/src/mbgl/storage/request.cpp index ea80e5950..d413cabbe 100644 --- a/src/mbgl/storage/request.cpp +++ b/src/mbgl/storage/request.cpp @@ -16,8 +16,8 @@ namespace mbgl { struct Request::Canceled { std::mutex mutex; bool confirmed = false; }; // Note: This requires that loop is running in the current thread (or not yet running). -Request::Request(const Resource &resource_, uv_loop_t *loop, const Environment &env_, Callback callback_) - : callback(callback_), resource(resource_), env(env_) { +Request::Request(const Resource &resource_, uv_loop_t *loop, Callback callback_) + : callback(callback_), resource(resource_) { // When there is no loop supplied (== nullptr), the callback will be fired in an arbitrary // thread (the thread notify() is called from) rather than kicking back to the calling thread. if (loop) { diff --git a/test/fixtures/database/cache.db b/test/fixtures/database/cache.db new file mode 100644 index 0000000000000000000000000000000000000000..c358381f1f2df0b84c23809ec23b385c7d082388 GIT binary patch literal 4096 zcmeH`-A=+V6oA`p5o5xY7u=rRNur5{7jQ@=$Q(LH0#|EgMHayUD+#yi6ZsUriBI8$ zWdpVl@Bx-KY1;GC)6=i#JU!Z>;4qBl6DFXB41_Vd20#dDavE}O#;%MvhJRKKUHlxE z^QxT@T*^z8ncL^#^P);{K~t_+gM!88{$rx{5=qAE&rfF-`nA6YP1+v$NSwTZi|ox=nVXfE;u&A5-v1&w~fIb#J+S zXp=rT9S@wYZJ#GTv0!2mQ<UO7|%7bV!m0oc!+%^?xkXx&3dvIB;X-Ac&iBZBno{eQs`)nbiMD{Z@{#CZu wWf>afRW0VbypXl29;FB<0{aM@tdy$%_n}cbMWFBmRR0(Li`4@afrAA800yR#H~;_u literal 0 HcmV?d00001 diff --git a/test/fixtures/database/invalid.db b/test/fixtures/database/invalid.db new file mode 100644 index 0000000000000000000000000000000000000000..f07e4af03da4e33ef3ee4027f39c92c6a2ec2ab0 GIT binary patch literal 4096 zcmeH}K~KUk6oA{6=rAEM(S*d))m?7o$ieT3d!%{ zQ^)qO=k-N$LOkno$r)6vMkTg8f!|ZB!kKW>RG>y+X-Y$)4meir9xwT~*T# zAIKoGodk`upXgD2XVhE7}PUlV2%$S>|&wK4)cu*`#5z4CYgEe(u pOumq6S~LMoV7UpblYDya8xYsO`ad5n_r>+?GyzRuo&X_c`WrA$q!IuC literal 0 HcmV?d00001 diff --git a/test/storage/cache_response.cpp b/test/storage/cache_response.cpp index d5dd8b36e..87de62025 100644 --- a/test/storage/cache_response.cpp +++ b/test/storage/cache_response.cpp @@ -14,9 +14,8 @@ TEST_F(Storage, CacheResponse) { DefaultFileSource fs(&cache); const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/cache" }; - auto &env = *static_cast(nullptr); - fs.request(resource, uv_default_loop(), env, [&](const Response &res) { + fs.request(resource, uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Response 1", res.data); EXPECT_LT(0, res.expires); @@ -24,7 +23,7 @@ TEST_F(Storage, CacheResponse) { EXPECT_EQ("", res.etag); EXPECT_EQ("", res.message); - fs.request(resource, uv_default_loop(), env, [&, res](const Response &res2) { + fs.request(resource, uv_default_loop(), [&, res](const Response &res2) { EXPECT_EQ(res.status, res2.status); EXPECT_EQ(res.data, res2.data); EXPECT_EQ(res.expires, res2.expires); diff --git a/test/storage/cache_revalidate.cpp b/test/storage/cache_revalidate.cpp index ceb6b2969..1bfd6941b 100644 --- a/test/storage/cache_revalidate.cpp +++ b/test/storage/cache_revalidate.cpp @@ -15,10 +15,8 @@ TEST_F(Storage, CacheRevalidate) { SQLiteCache cache(":memory:"); DefaultFileSource fs(&cache); - auto &env = *static_cast(nullptr); - const Resource revalidateSame { Resource::Unknown, "http://127.0.0.1:3000/revalidate-same" }; - fs.request(revalidateSame, uv_default_loop(), env, [&](const Response &res) { + fs.request(revalidateSame, uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Response", res.data); EXPECT_EQ(0, res.expires); @@ -26,7 +24,7 @@ TEST_F(Storage, CacheRevalidate) { EXPECT_EQ("snowfall", res.etag); EXPECT_EQ("", res.message); - fs.request(revalidateSame, uv_default_loop(), env, [&, res](const Response &res2) { + fs.request(revalidateSame, uv_default_loop(), [&, res](const Response &res2) { EXPECT_EQ(Response::Successful, res2.status); EXPECT_EQ("Response", res2.data); // We use this to indicate that a 304 reply came back. @@ -42,7 +40,7 @@ TEST_F(Storage, CacheRevalidate) { const Resource revalidateModified{ Resource::Unknown, "http://127.0.0.1:3000/revalidate-modified" }; - fs.request(revalidateModified, uv_default_loop(), env, [&](const Response &res) { + fs.request(revalidateModified, uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Response", res.data); EXPECT_EQ(0, res.expires); @@ -50,7 +48,7 @@ TEST_F(Storage, CacheRevalidate) { EXPECT_EQ("", res.etag); EXPECT_EQ("", res.message); - fs.request(revalidateModified, uv_default_loop(), env, [&, res](const Response &res2) { + fs.request(revalidateModified, uv_default_loop(), [&, res](const Response &res2) { EXPECT_EQ(Response::Successful, res2.status); EXPECT_EQ("Response", res2.data); // We use this to indicate that a 304 reply came back. @@ -64,7 +62,7 @@ TEST_F(Storage, CacheRevalidate) { }); const Resource revalidateEtag { Resource::Unknown, "http://127.0.0.1:3000/revalidate-etag" }; - fs.request(revalidateEtag, uv_default_loop(), env, [&](const Response &res) { + fs.request(revalidateEtag, uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Response 1", res.data); EXPECT_EQ(0, res.expires); @@ -72,7 +70,7 @@ TEST_F(Storage, CacheRevalidate) { EXPECT_EQ("response-1", res.etag); EXPECT_EQ("", res.message); - fs.request(revalidateEtag, uv_default_loop(), env, [&, res](const Response &res2) { + fs.request(revalidateEtag, uv_default_loop(), [&, res](const Response &res2) { EXPECT_EQ(Response::Successful, res2.status); EXPECT_EQ("Response 2", res2.data); EXPECT_EQ(0, res2.expires); diff --git a/test/storage/directory_reading.cpp b/test/storage/directory_reading.cpp index ccae4177c..4459b42c2 100644 --- a/test/storage/directory_reading.cpp +++ b/test/storage/directory_reading.cpp @@ -15,10 +15,8 @@ TEST_F(Storage, AssetReadDirectory) { DefaultFileSource fs(nullptr); #endif - auto &env = *static_cast(nullptr); - fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage" }, uv_default_loop(), - env, [&](const Response &res) { + [&](const Response &res) { EXPECT_EQ(Response::Error, res.status); EXPECT_EQ(0ul, res.data.size()); EXPECT_EQ(0, res.expires); @@ -27,7 +25,7 @@ TEST_F(Storage, AssetReadDirectory) { #ifdef MBGL_ASSET_ZIP EXPECT_EQ("No such file", res.message); #elif MBGL_ASSET_FS - EXPECT_EQ("illegal operation on a directory", res.message); + EXPECT_EQ("illegal operation on a directory", res.message); #endif ReadDirectory.finish(); }); diff --git a/test/storage/file_reading.cpp b/test/storage/file_reading.cpp index 01db75d5c..8db911f65 100644 --- a/test/storage/file_reading.cpp +++ b/test/storage/file_reading.cpp @@ -16,10 +16,8 @@ TEST_F(Storage, AssetEmptyFile) { DefaultFileSource fs(nullptr); #endif - auto &env = *static_cast(nullptr); - fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/empty" }, uv_default_loop(), - env, [&](const Response &res) { + [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ(0ul, res.data.size()); EXPECT_EQ(0, res.expires); @@ -43,10 +41,8 @@ TEST_F(Storage, AssetNonEmptyFile) { DefaultFileSource fs(nullptr); #endif - auto &env = *static_cast(nullptr); - fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }, - uv_default_loop(), env, [&](const Response &res) { + uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ(16ul, res.data.size()); EXPECT_EQ(0, res.expires); @@ -71,10 +67,8 @@ TEST_F(Storage, AssetNonExistentFile) { DefaultFileSource fs(nullptr); #endif - auto &env = *static_cast(nullptr); - fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/does_not_exist" }, - uv_default_loop(), env, [&](const Response &res) { + uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Error, res.status); EXPECT_EQ(0ul, res.data.size()); EXPECT_EQ(0, res.expires); diff --git a/test/storage/http_cancel.cpp b/test/storage/http_cancel.cpp index 80efb3977..a73182da5 100644 --- a/test/storage/http_cancel.cpp +++ b/test/storage/http_cancel.cpp @@ -14,10 +14,8 @@ TEST_F(Storage, HTTPCancel) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - auto req = - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), env, + fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), [&](const Response &) { ADD_FAILURE() << "Callback should not be called"; }); fs.cancel(req); @@ -33,13 +31,12 @@ TEST_F(Storage, HTTPCancelMultiple) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; - auto req2 = fs.request(resource, uv_default_loop(), env, [&](const Response &) { + auto req2 = fs.request(resource, uv_default_loop(), [&](const Response &) { ADD_FAILURE() << "Callback should not be called"; }); - fs.request(resource, uv_default_loop(), env, [&](const Response &res) { + 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); diff --git a/test/storage/http_coalescing.cpp b/test/storage/http_coalescing.cpp index 28fa4415b..5c90009f8 100644 --- a/test/storage/http_coalescing.cpp +++ b/test/storage/http_coalescing.cpp @@ -14,8 +14,6 @@ TEST_F(Storage, HTTPCoalescing) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - static const Response *reference = nullptr; const auto complete = [&](const Response &res) { @@ -43,7 +41,7 @@ TEST_F(Storage, HTTPCoalescing) { const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/test" }; for (int i = 0; i < total; i++) { - fs.request(resource, uv_default_loop(), env, complete); + fs.request(resource, uv_default_loop(), complete); } uv_run(uv_default_loop(), UV_RUN_DEFAULT); diff --git a/test/storage/http_environment.cpp b/test/storage/http_environment.cpp deleted file mode 100644 index 41a9d43d5..000000000 --- a/test/storage/http_environment.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "storage.hpp" - -#include - -#include -#include - -#include - -TEST_F(Storage, HTTPCancelEnvironment) { - SCOPED_TEST(HTTPRetainedEnvironment) - SCOPED_TEST(HTTPCanceledEnvironment) - - using namespace mbgl; - - DefaultFileSource fs(nullptr); - - // Create two fake environment pointers. The FileSource implementation treats these as opaque - // pointers and doesn't reach into them. - auto &env1 = *reinterpret_cast(1); - auto &env2 = *reinterpret_cast(2); - - const Resource resource { Resource::Unknown, "http://127.0.0.1:3000/delayed" }; - - // Environment 1 - fs.request(resource, uv_default_loop(), env1, [&](const Response &res) { - // This environment gets aborted below. This means the request is marked as failing and - // will return an error here. - EXPECT_EQ(Response::Error, res.status); - EXPECT_EQ("", res.data); - EXPECT_EQ(0, res.expires); - EXPECT_EQ(0, res.modified); - EXPECT_EQ("", res.etag); - EXPECT_EQ("Environment is terminating", res.message); - HTTPCanceledEnvironment.finish(); - }); - - // Environment 2 - fs.request(resource, uv_default_loop(), env2, [&](const Response &res) { - // The same request as above, but in a different environment which doesn't get aborted. This - // means the request should succeed. - EXPECT_EQ(Response::Successful, res.status); - EXPECT_EQ("Response", res.data); - EXPECT_EQ(0, res.expires); - EXPECT_EQ(0, res.modified); - EXPECT_EQ("", res.etag); - EXPECT_EQ("", res.message); - HTTPRetainedEnvironment.finish(); - }); - - fs.abort(env1); - - uv_run(uv_default_loop(), UV_RUN_DEFAULT); -} diff --git a/test/storage/http_error.cpp b/test/storage/http_error.cpp index e5728d97b..eeb8117a0 100644 --- a/test/storage/http_error.cpp +++ b/test/storage/http_error.cpp @@ -22,12 +22,10 @@ TEST_F(Storage, HTTPError) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - auto start = uv_hrtime(); fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, uv_default_loop(), - env, [&](const Response &res) { + [&](const Response &res) { const auto duration = double(uv_hrtime() - start) / 1e9; EXPECT_LT(1, duration) << "Backoff timer didn't wait 1 second"; EXPECT_GT(1.2, duration) << "Backoff timer fired too late"; @@ -41,7 +39,7 @@ TEST_F(Storage, HTTPError) { HTTPTemporaryError.finish(); }); - fs.request({ Resource::Unknown, "http://127.0.0.1:3001/" }, uv_default_loop(), env, + fs.request({ Resource::Unknown, "http://127.0.0.1:3001/" }, uv_default_loop(), [&](const Response &res) { const auto duration = double(uv_hrtime() - start) / 1e9; // 1.5 seconds == 4 retries, with a 500ms timeout (see above). diff --git a/test/storage/http_header_parsing.cpp b/test/storage/http_header_parsing.cpp index 1561660b6..5f18b163a 100644 --- a/test/storage/http_header_parsing.cpp +++ b/test/storage/http_header_parsing.cpp @@ -15,11 +15,9 @@ TEST_F(Storage, HTTPHeaderParsing) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?modified=1420794326&expires=1420797926&etag=foo" }, - uv_default_loop(), env, [&](const Response &res) { + uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Hello World!", res.data); EXPECT_EQ(1420797926, res.expires); @@ -33,7 +31,7 @@ TEST_F(Storage, HTTPHeaderParsing) { SystemClock::now().time_since_epoch()).count(); fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=120" }, - uv_default_loop(), env, [&](const Response &res) { + uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Hello World!", res.data); EXPECT_GT(2, std::abs(res.expires - now - 120)) << "Expiration date isn't about 120 seconds in the future"; diff --git a/test/storage/http_load.cpp b/test/storage/http_load.cpp index c4069eba3..2347a76ab 100644 --- a/test/storage/http_load.cpp +++ b/test/storage/http_load.cpp @@ -11,8 +11,6 @@ TEST_F(Storage, HTTPLoad) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - const int concurrency = 50; const int max = 10000; int number = 1; @@ -21,7 +19,7 @@ TEST_F(Storage, HTTPLoad) { const auto current = number++; fs.request({ Resource::Unknown, std::string("http://127.0.0.1:3000/load/") + std::to_string(current) }, - uv_default_loop(), env, [&, current](const Response &res) { + uv_default_loop(), [&, current](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ(std::string("Request ") + std::to_string(current), res.data); EXPECT_EQ(0, res.expires); diff --git a/test/storage/http_noloop.cpp b/test/storage/http_noloop.cpp index cd4ebeb2c..e133d3e0c 100644 --- a/test/storage/http_noloop.cpp +++ b/test/storage/http_noloop.cpp @@ -12,8 +12,6 @@ TEST_F(Storage, HTTPNoLoop) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - const auto mainThread = uv_thread_self(); // Async handle that keeps the main loop alive until the thread finished @@ -22,7 +20,7 @@ TEST_F(Storage, HTTPNoLoop) { uv::close(as); }); - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, nullptr, env, + fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, nullptr, [&](const Response &res) { EXPECT_NE(uv_thread_self(), mainThread) << "Response was called in the same thread"; EXPECT_EQ(Response::Successful, res.status); diff --git a/test/storage/http_other_loop.cpp b/test/storage/http_other_loop.cpp index 9ad673cf7..64612f13d 100644 --- a/test/storage/http_other_loop.cpp +++ b/test/storage/http_other_loop.cpp @@ -12,9 +12,7 @@ TEST_F(Storage, HTTPOtherLoop) { // This file source launches a separate thread to do the processing. DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), env, + fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), [&](const Response &res) { EXPECT_EQ(Response::Successful, res.status); EXPECT_EQ("Hello World!", res.data); diff --git a/test/storage/http_reading.cpp b/test/storage/http_reading.cpp index 350a8eaa4..09d33fd6a 100644 --- a/test/storage/http_reading.cpp +++ b/test/storage/http_reading.cpp @@ -14,11 +14,9 @@ TEST_F(Storage, HTTPReading) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - const auto mainThread = uv_thread_self(); - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), env, + fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), [&](const Response &res) { EXPECT_EQ(uv_thread_self(), mainThread); EXPECT_EQ(Response::Successful, res.status); @@ -31,7 +29,7 @@ TEST_F(Storage, HTTPReading) { }); fs.request({ Resource::Unknown, "http://127.0.0.1:3000/doesnotexist" }, uv_default_loop(), - env, [&](const Response &res) { + [&](const Response &res) { EXPECT_EQ(uv_thread_self(), mainThread); EXPECT_EQ(Response::Error, res.status); EXPECT_EQ("HTTP status code 404", res.message); @@ -51,9 +49,7 @@ TEST_F(Storage, HTTPNoCallback) { DefaultFileSource fs(nullptr); - auto &env = *static_cast(nullptr); - - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), env, + fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, uv_default_loop(), nullptr); uv_run(uv_default_loop(), UV_RUN_DEFAULT); @@ -68,10 +64,8 @@ TEST_F(Storage, HTTPCallbackNotOnLoop) { SCOPED_TEST(HTTPTest) - auto &env = *static_cast(nullptr); - std::promise promise; - fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, env, [&] (const Response &) { + fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test" }, [&] (const Response &) { promise.set_value(); }); diff --git a/test/test.gypi b/test/test.gypi index 5c975d547..d22dc3b43 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -62,7 +62,6 @@ 'storage/file_reading.cpp', 'storage/http_cancel.cpp', 'storage/http_coalescing.cpp', - 'storage/http_environment.cpp', 'storage/http_error.cpp', 'storage/http_header_parsing.cpp', 'storage/http_load.cpp',