From 1eb1257b8846c2228e3f3bb9a3afb5398df3b4fe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 9 Feb 2014 09:30:01 +0100 Subject: always show error on HTTP test fails --- _test/tests/inc/httpclient_http.test.php | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to '_test/tests/inc/httpclient_http.test.php') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 43dd4478f..a19f2d238 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -9,7 +9,7 @@ class httpclient_http_test extends DokuWikiTest { function test_simpleget(){ $http = new HTTPClient(); $data = $http->get($this->server.'/get?foo=bar'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('args',$resp); @@ -22,7 +22,7 @@ class httpclient_http_test extends DokuWikiTest { function test_dget(){ $http = new HTTPClient(); $data = $http->dget($this->server.'/get',array('foo'=>'bar')); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('args',$resp); @@ -35,7 +35,7 @@ class httpclient_http_test extends DokuWikiTest { function test_gzip(){ $http = new HTTPClient(); $data = $http->get($this->server.'/gzip'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('gzipped',$resp); @@ -48,7 +48,7 @@ class httpclient_http_test extends DokuWikiTest { function test_simplepost(){ $http = new HTTPClient(); $data = $http->post($this->server.'/post',array('foo'=>'bar')); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('form',$resp); @@ -61,7 +61,7 @@ class httpclient_http_test extends DokuWikiTest { function test_redirect(){ $http = new HTTPClient(); $data = $http->get($this->server.'/redirect/3'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('url',$resp); @@ -74,7 +74,7 @@ class httpclient_http_test extends DokuWikiTest { function test_relredirect(){ $http = new HTTPClient(); $data = $http->get($this->server.'/relative-redirect/3'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('url',$resp); @@ -87,7 +87,7 @@ class httpclient_http_test extends DokuWikiTest { function test_redirectfail(){ $http = new HTTPClient(); $data = $http->get($this->server.'/redirect/5'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals('Maximum number of redirects exceeded',$http->error); } @@ -99,7 +99,7 @@ class httpclient_http_test extends DokuWikiTest { $http->get($this->server.'/cookies/set/foo/bar'); $this->assertEquals(array('foo' => 'bar'), $http->cookies); $data = $http->get($this->server.'/cookies'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('cookies',$resp); @@ -112,7 +112,7 @@ class httpclient_http_test extends DokuWikiTest { function test_teapot(){ $http = new HTTPClient(); $data = $http->get($this->server.'/status/418'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(418,$http->status); } @@ -125,13 +125,13 @@ class httpclient_http_test extends DokuWikiTest { // this should abort completely $data = $http->get($this->server.'/stream/30'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); // this should read just the needed bytes $http->max_bodysize_abort = false; $http->keep_alive = false; $data = $http->get($this->server.'/stream/30'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); /* should read no more than max_bodysize+1 */ $this->assertLessThanOrEqual(251,strlen($data)); } @@ -143,10 +143,10 @@ class httpclient_http_test extends DokuWikiTest { $http = new HTTPClient(); $http->max_bodysize = 500*1024; $data = $http->get($this->server.'/stream/5'); - $this->assertTrue($data !== false, 'HTTP response'); + $this->assertTrue($data !== false, 'HTTP response '.$http->error); $http->max_bodysize_abort = false; $data = $http->get($this->server.'/stream/5'); - $this->assertTrue($data !== false, 'HTTP response'); + $this->assertTrue($data !== false, 'HTTP response '.$http->error); } /** @@ -157,7 +157,7 @@ class httpclient_http_test extends DokuWikiTest { $http->user = 'user'; $http->pass = 'pass'; $data = $http->get($this->server.'/basic-auth/user/pass'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertEquals(array('authenticated'=>true,'user'=>'user'), $resp); @@ -171,7 +171,7 @@ class httpclient_http_test extends DokuWikiTest { $http->user = 'user'; $http->pass = 'invalid'; $data = $http->get($this->server.'/basic-auth/user/pass'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(401,$http->status); } @@ -182,7 +182,7 @@ class httpclient_http_test extends DokuWikiTest { $http = new HTTPClient(); $http->timeout = 5; $data = $http->get($this->server.'/delay/10'); - $this->assertTrue($data === false, 'HTTP response'); + $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(-100,$http->status); } @@ -192,7 +192,7 @@ class httpclient_http_test extends DokuWikiTest { function test_headers(){ $http = new HTTPClient(); $data = $http->get($this->server.'/response-headers?baz=&foo=bar'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); $this->assertArrayHasKey('baz',$http->resp_headers); @@ -206,7 +206,7 @@ class httpclient_http_test extends DokuWikiTest { function test_chunked(){ $http = new HTTPClient(); $data = $http->get('http://whoopdedo.org/cgi-bin/chunked/2550'); - $this->assertFalse($data === false, 'HTTP response'); + $this->assertFalse($data === false, 'HTTP response '.$http->error); $this->assertEquals(2550,strlen($data)); } @@ -218,7 +218,7 @@ class httpclient_http_test extends DokuWikiTest { function test_wikimatrix(){ $http = new HTTPClient(); $data = $http->get('http://www.wikimatrix.org/cfeed/dokuwiki/-/-'); - $this->assertTrue($data !== false, $http->error); + $this->assertTrue($data !== false, 'HTTP response '.$http->error); } function test_postencode(){ -- cgit v1.2.3 From 95e6ded1b26c14b1ef55699b171ce422827364b1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 9 Feb 2014 10:08:48 +0100 Subject: more robust HTTP testing connections are now retried after timeout and failing connections will be marked as skipped instead of failing. This should reduce false alarms on travis --- _test/tests/inc/httpclient_http.test.php | 115 ++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 18 deletions(-) (limited to '_test/tests/inc/httpclient_http.test.php') diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index a19f2d238..3446e1184 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -1,14 +1,21 @@ get($this->server.'/get?foo=bar'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -20,8 +27,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_dget(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->dget($this->server.'/get',array('foo'=>'bar')); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -33,8 +44,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_gzip(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/gzip'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -46,8 +61,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_simplepost(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->post($this->server.'/post',array('foo'=>'bar')); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -59,8 +78,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_redirect(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/redirect/3'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -72,8 +95,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_relredirect(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/relative-redirect/3'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -85,8 +112,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_redirectfail(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/redirect/5'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals('Maximum number of redirects exceeded',$http->error); } @@ -95,10 +126,18 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_cookies(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $http->get($this->server.'/cookies/set/foo/bar'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertEquals(array('foo' => 'bar'), $http->cookies); $data = $http->get($this->server.'/cookies'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -110,8 +149,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_teapot(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/status/418'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(418,$http->status); } @@ -120,17 +163,25 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_maxbody(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $http->max_bodysize = 250; // this should abort completely $data = $http->get($this->server.'/stream/30'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data === false, 'HTTP response '.$http->error); // this should read just the needed bytes $http->max_bodysize_abort = false; $http->keep_alive = false; $data = $http->get($this->server.'/stream/30'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); /* should read no more than max_bodysize+1 */ $this->assertLessThanOrEqual(251,strlen($data)); @@ -140,12 +191,20 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_maxbodyok(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $http->max_bodysize = 500*1024; $data = $http->get($this->server.'/stream/5'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data !== false, 'HTTP response '.$http->error); $http->max_bodysize_abort = false; $data = $http->get($this->server.'/stream/5'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data !== false, 'HTTP response '.$http->error); } @@ -153,10 +212,14 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_basicauth(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $http->user = 'user'; $http->pass = 'pass'; $data = $http->get($this->server.'/basic-auth/user/pass'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -167,10 +230,14 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_basicauthfail(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $http->user = 'user'; $http->pass = 'invalid'; $data = $http->get($this->server.'/basic-auth/user/pass'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data === false, 'HTTP response '.$http->error); $this->assertEquals(401,$http->status); } @@ -179,7 +246,7 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_timeout(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $http->timeout = 5; $data = $http->get($this->server.'/delay/10'); $this->assertTrue($data === false, 'HTTP response '.$http->error); @@ -190,8 +257,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_headers(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get($this->server.'/response-headers?baz=&foo=bar'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $resp = json_decode($data, true); $this->assertTrue(is_array($resp), 'JSON response'); @@ -204,8 +275,12 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_chunked(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get('http://whoopdedo.org/cgi-bin/chunked/2550'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertFalse($data === false, 'HTTP response '.$http->error); $this->assertEquals(2550,strlen($data)); } @@ -216,13 +291,17 @@ class httpclient_http_test extends DokuWikiTest { * @group internet */ function test_wikimatrix(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); $data = $http->get('http://www.wikimatrix.org/cfeed/dokuwiki/-/-'); + if($http->noconnection()) { + $this->markTestSkipped('connection timed out'); + return; + } $this->assertTrue($data !== false, 'HTTP response '.$http->error); } function test_postencode(){ - $http = new HTTPClient(); + $http = new HTTPMockClient(); // check simple data -- cgit v1.2.3