* Main gyp files are now standardized as platform/<platform>/platform.gyp. * Each platform gyp file defines appropriate loop_lib and headless_lib variables. * Each platform gyp file includes mbgl.gypi, which defines base targets which may be useful to all platforms. * CI targets are consistent across platforms: `make $(PLATFORM) && make test-$(PLATFORM)`. * Renamed the "linux" test app to "glfw". It's now built in OS X CI. * Android build flakiness is fixed. * iOS CI builds the bench and iosapp targets. * Mesa version is now in one place. * CI scripts use bash "strict mode" and correct error handling. * All build output goes to the build directory. * Removed vestigial iOS/OS X/Android Travis scripts.
88 lines
2.9 KiB
C++
88 lines
2.9 KiB
C++
#include "storage.hpp"
|
|
|
|
#include <mbgl/storage/online_file_source.hpp>
|
|
#include <mbgl/storage/network_status.hpp>
|
|
#include <mbgl/util/chrono.hpp>
|
|
#include <mbgl/util/run_loop.hpp>
|
|
|
|
#include <cmath>
|
|
|
|
TEST_F(Storage, TEST_REQUIRES_SERVER(HTTPTemporaryError)) {
|
|
SCOPED_TEST(HTTPTemporaryError)
|
|
|
|
using namespace mbgl;
|
|
|
|
util::RunLoop loop;
|
|
OnlineFileSource fs;
|
|
|
|
const auto start = Clock::now();
|
|
|
|
std::unique_ptr<AsyncRequest> req1 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/temporary-error" }, [&](Response res) {
|
|
static int counter = 0;
|
|
switch (counter++) {
|
|
case 0: {
|
|
const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
|
|
EXPECT_GT(0.2, duration) << "Initial error request took too long";
|
|
ASSERT_NE(nullptr, res.error);
|
|
EXPECT_EQ(Response::Error::Reason::Server, res.error->reason);
|
|
EXPECT_EQ("HTTP status code 500", res.error->message);
|
|
ASSERT_FALSE(bool(res.data));
|
|
EXPECT_FALSE(bool(res.expires));
|
|
EXPECT_FALSE(bool(res.modified));
|
|
EXPECT_FALSE(bool(res.etag));
|
|
} break;
|
|
case 1: {
|
|
req1.reset();
|
|
const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
|
|
EXPECT_LT(0.99, duration) << "Backoff timer didn't wait 1 second";
|
|
EXPECT_GT(1.2, duration) << "Backoff timer fired too late";
|
|
EXPECT_EQ(nullptr, res.error);
|
|
ASSERT_TRUE(res.data.get());
|
|
EXPECT_EQ("Hello World!", *res.data);
|
|
EXPECT_FALSE(bool(res.expires));
|
|
EXPECT_FALSE(bool(res.modified));
|
|
EXPECT_FALSE(bool(res.etag));
|
|
loop.stop();
|
|
HTTPTemporaryError.finish();
|
|
} break;
|
|
}
|
|
});
|
|
|
|
loop.run();
|
|
}
|
|
|
|
TEST_F(Storage, TEST_REQUIRES_SERVER(HTTPConnectionError)) {
|
|
SCOPED_TEST(HTTPConnectionError)
|
|
|
|
using namespace mbgl;
|
|
|
|
util::RunLoop loop;
|
|
OnlineFileSource fs;
|
|
|
|
const auto start = Clock::now();
|
|
|
|
std::unique_ptr<AsyncRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3001/" }, [&](Response res) {
|
|
static int counter = 0;
|
|
static int wait = 0;
|
|
const auto duration = std::chrono::duration<const double>(Clock::now() - start).count();
|
|
EXPECT_LT(wait - 0.01, duration) << "Backoff timer didn't wait 1 second";
|
|
EXPECT_GT(wait + 0.2, duration) << "Backoff timer fired too late";
|
|
ASSERT_NE(nullptr, res.error);
|
|
EXPECT_EQ(Response::Error::Reason::Connection, res.error->reason);
|
|
ASSERT_FALSE(res.data.get());
|
|
EXPECT_FALSE(bool(res.expires));
|
|
EXPECT_FALSE(bool(res.modified));
|
|
EXPECT_FALSE(bool(res.etag));
|
|
|
|
if (counter == 2) {
|
|
req2.reset();
|
|
loop.stop();
|
|
HTTPConnectionError.finish();
|
|
}
|
|
wait += (1 << counter);
|
|
counter++;
|
|
});
|
|
|
|
loop.run();
|
|
}
|