summaryrefslogtreecommitdiff
path: root/_test/tests/inc/httpclient_mock.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-02-09 10:08:48 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-02-09 10:08:48 +0100
commit95e6ded1b26c14b1ef55699b171ce422827364b1 (patch)
treec440e43ee53000aeb1cdd37616f7d145ae39399a /_test/tests/inc/httpclient_mock.php
parent1eb1257b8846c2228e3f3bb9a3afb5398df3b4fe (diff)
downloadrpg-95e6ded1b26c14b1ef55699b171ce422827364b1.tar.gz
rpg-95e6ded1b26c14b1ef55699b171ce422827364b1.tar.bz2
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
Diffstat (limited to '_test/tests/inc/httpclient_mock.php')
-rw-r--r--_test/tests/inc/httpclient_mock.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/_test/tests/inc/httpclient_mock.php b/_test/tests/inc/httpclient_mock.php
new file mode 100644
index 000000000..038045c8b
--- /dev/null
+++ b/_test/tests/inc/httpclient_mock.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Class HTTPMockClient
+ *
+ * Does not really mock the client, it still does real connections but will retry failed connections
+ * to work around shaky connectivity.
+ */
+class HTTPMockClient extends HTTPClient {
+ protected $tries;
+
+ /**
+ * Sets shorter timeout
+ */
+ function __construct() {
+ parent::__construct();
+ $this->timeout = 8; // slightly faster timeouts
+ }
+
+ /**
+ * Returns true if the connection timed out
+ *
+ * @return bool
+ */
+ function noconnection() {
+ return ($this->tries === 0);
+ }
+
+ /**
+ * Retries sending the request multiple times
+ *
+ * @param string $url
+ * @param string $data
+ * @param string $method
+ * @return bool
+ */
+ function sendRequest($url, $data = '', $method = 'GET') {
+ $this->tries = 2; // configures the number of retries
+ $return = false;
+ while($this->tries) {
+ $return = parent::sendRequest($url, $data, $method);
+ if($this->status != -100) break;
+ $this->tries--;
+ }
+ return $return;
+ }
+} \ No newline at end of file