summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sosa <sosa@chromium.org>2014-06-10 18:18:24 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-06-11 22:08:28 +0000
commit0a364bb65efa5c5cdcd49114080a646a39e030fc (patch)
tree17377e9bd8ca1fafe00d3edd1f57e88767ac4a9a
parenta8262e23b4d94af58e8e92d2a4b6e15ae4b4cf50 (diff)
Fix ServerDiesTest and FailureTest which depended on you running apache.
This CL fixes the issue that URL in both of these tests defaulted to no-port which meaned the tests were going to http://localhost. On some machines, that might point to an existing server running on port 80 (for me it was apache2 configured by autotest). This CL changes FailureTest to use a different hostname that should never match. In the case of the ServerDiesTest, we use the correct port of the server we kill during the test. I've also added documentation to what these tests should actually do. BUG=chromium:383200 TEST=Ran unittests with and without apache up. Change-Id: I6b4168eada48dcd59fad23ed7ff6577b18e4ef81 Reviewed-on: https://chromium-review.googlesource.com/203347 Reviewed-by: Chris Sosa <sosa@chromium.org> Commit-Queue: Chris Sosa <sosa@chromium.org> Tested-by: Chris Sosa <sosa@chromium.org>
-rw-r--r--http_fetcher_unittest.cc21
1 files changed, 17 insertions, 4 deletions
diff --git a/http_fetcher_unittest.cc b/http_fetcher_unittest.cc
index 33920984..b2848f3f 100644
--- a/http_fetcher_unittest.cc
+++ b/http_fetcher_unittest.cc
@@ -679,6 +679,9 @@ TYPED_TEST(HttpFetcherTest, FlakyTest) {
}
namespace {
+// This delegate kills the server attached to it after receiving any bytes.
+// This can be used for testing what happens when you try to fetch data and
+// the server dies.
class FailureHttpFetcherTestDelegate : public HttpFetcherDelegate {
public:
FailureHttpFetcherTestDelegate(PythonHttpServer* server)
@@ -704,7 +707,7 @@ class FailureHttpFetcherTestDelegate : public HttpFetcherDelegate {
}
virtual void TransferComplete(HttpFetcher* fetcher, bool successful) {
EXPECT_FALSE(successful);
- EXPECT_EQ(404, fetcher->http_response_code());
+ EXPECT_EQ(0, fetcher->http_response_code());
g_main_loop_quit(loop_);
}
virtual void TransferTerminated(HttpFetcher* fetcher) {
@@ -717,6 +720,8 @@ class FailureHttpFetcherTestDelegate : public HttpFetcherDelegate {
TYPED_TEST(HttpFetcherTest, FailureTest) {
+ // This test ensures that a fetcher responds correctly when a server isn't
+ // available at all.
if (this->test_.IsMock())
return;
GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
@@ -728,7 +733,7 @@ TYPED_TEST(HttpFetcherTest, FailureTest) {
StartTransferArgs start_xfer_args = {
fetcher.get(),
- this->test_.SmallUrl(0)
+ "http://host_doesnt_exist99999999",
};
g_timeout_add(0, StartTransfer, &start_xfer_args);
@@ -740,18 +745,26 @@ TYPED_TEST(HttpFetcherTest, FailureTest) {
}
TYPED_TEST(HttpFetcherTest, ServerDiesTest) {
+ // This test starts a new http server and kills it after receiving its first
+ // set of bytes. It test whether or not our fetcher eventually gives up on
+ // retries and aborts correctly.
if (this->test_.IsMock())
return;
GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
{
- FailureHttpFetcherTestDelegate delegate(new PythonHttpServer);
+ PythonHttpServer* server = new PythonHttpServer();
+ int port = server->GetPort();
+ ASSERT_TRUE(server->started_);
+
+ // Handles destruction and claims ownership.
+ FailureHttpFetcherTestDelegate delegate(server);
delegate.loop_ = loop;
scoped_ptr<HttpFetcher> fetcher(this->test_.NewSmallFetcher());
fetcher->set_delegate(&delegate);
StartTransferArgs start_xfer_args = {
fetcher.get(),
- LocalServerUrlForPath(0,
+ LocalServerUrlForPath(port,
base::StringPrintf("/flaky/%d/%d/%d/%d", kBigLength,
kFlakyTruncateLength,
kFlakySleepEvery,