summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-16 12:57:48 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-19 08:26:04 +0200
commitc452390d591b50f2dc603e8f077d7489d5f22cbc (patch)
tree130ba2f6a903317bee26d94b56b1f86d64ea5669
parent34510b73a254a0c7c87ac631cdf2aa06d57d0c49 (diff)
downloadnextcloud-server-c452390d591b50f2dc603e8f077d7489d5f22cbc.tar.gz
nextcloud-server-c452390d591b50f2dc603e8f077d7489d5f22cbc.zip
Extract waiting for the server to start to the Utils class
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--build/acceptance/features/core/NextcloudTestServerDockerHelper.php22
-rw-r--r--build/acceptance/features/core/Utils.php31
2 files changed, 32 insertions, 21 deletions
diff --git a/build/acceptance/features/core/NextcloudTestServerDockerHelper.php b/build/acceptance/features/core/NextcloudTestServerDockerHelper.php
index 5e7c0b2df76..120e13fe70c 100644
--- a/build/acceptance/features/core/NextcloudTestServerDockerHelper.php
+++ b/build/acceptance/features/core/NextcloudTestServerDockerHelper.php
@@ -111,14 +111,8 @@ class NextcloudTestServerDockerHelper implements NextcloudTestServerHelper {
public function setUp() {
$this->createAndStartContainer();
- $serverAddress = $this->getNextcloudTestServerAddress();
-
- $isServerReadyCallback = function() use ($serverAddress) {
- return $this->isServerReady($serverAddress);
- };
$timeout = 10;
- $timeoutStep = 0.5;
- if (!Utils::waitFor($isServerReadyCallback, $timeout, $timeoutStep)) {
+ if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) {
throw new Exception("Docker container for Nextcloud (" . $this->containerName . ") or its Nextcloud test server could not be started");
}
}
@@ -144,20 +138,6 @@ class NextcloudTestServerDockerHelper implements NextcloudTestServerHelper {
$this->executeDockerCommand("run --detach --user=www-data --publish 127.0.0.1:" . $this->hostPortRangeForContainer . ":80 --name=" . $this->containerName . " " . $this->imageName);
}
- private function isServerReady($serverAddress) {
- $curlHandle = curl_init("http://" . $serverAddress);
-
- // Returning the transfer as the result of curl_exec prevents the
- // transfer from being written to the output.
- curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
-
- $transfer = curl_exec($curlHandle);
-
- curl_close($curlHandle);
-
- return $transfer !== false;
- }
-
/**
* Cleans up the Nextcloud test server.
*
diff --git a/build/acceptance/features/core/Utils.php b/build/acceptance/features/core/Utils.php
index 5dc52cd7377..86b7515e4c6 100644
--- a/build/acceptance/features/core/Utils.php
+++ b/build/acceptance/features/core/Utils.php
@@ -56,4 +56,35 @@ class Utils {
return $conditionMet;
}
+ /**
+ * Waits at most $timeout seconds for the server at the given URL to be up,
+ * checking it again every $timeoutStep seconds.
+ *
+ * Note that it does not verify whether the URL returns a valid HTTP status
+ * or not; it simply checks that the server at the given URL is accessible.
+ *
+ * @param string $url the URL for the server to check.
+ * @param float $timeout the number of seconds (decimals allowed) to wait at
+ * most for the server.
+ * @param float $timeoutStep the number of seconds (decimals allowed) to
+ * wait before checking the server again; by default, 0.5 seconds.
+ * @return boolean true if the server was found, false otherwise.
+ */
+ public static function waitForServer($url, $timeout, $timeoutStep = 0.5) {
+ $isServerUpCallback = function() use ($url) {
+ $curlHandle = curl_init($url);
+
+ // Returning the transfer as the result of curl_exec prevents the
+ // transfer from being written to the output.
+ curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
+
+ $transfer = curl_exec($curlHandle);
+
+ curl_close($curlHandle);
+
+ return $transfer !== false;
+ };
+ return self::waitFor($isServerUpCallback, $timeout, $timeoutStep);
+ }
+
}