From d3b725294f5eadb064f9f2a340e1a0d7e5fe4383 Mon Sep 17 00:00:00 2001 From: bunkerity Date: Wed, 27 Jul 2022 13:56:05 +0200 Subject: [PATCH] tests - wait until swarm services are running --- docs/quickstart-guide.md | 2 +- examples/reverse-proxy-singlesite/docker-compose.yml | 1 - tests/SwarmTest.py | 11 +++++++++++ tests/Test.py | 8 ++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/quickstart-guide.md b/docs/quickstart-guide.md index 20f5881e7..32e295694 100644 --- a/docs/quickstart-guide.md +++ b/docs/quickstart-guide.md @@ -2288,7 +2288,7 @@ BunkerWeb supports PHP using external or remote [PHP-FPM](https://www.php.net/ma === "Linux" -We will assume that you already have the [Linux integration](/1.4/integrations/#linux) stack running on your machine. + We will assume that you already have the [Linux integration](/1.4/integrations/#linux) stack running on your machine. By default, BunkerWeb will search for web files inside the `/opt/bunkerweb/www` folder. You can use it for storing your PHP applications : each application will be in its own subfolder named the same as the primary server name. Please note that you will need to configure your PHP-FPM service to get or set the user/group of the running processes and the UNIX socket file used to communicate with BunkerWeb. diff --git a/examples/reverse-proxy-singlesite/docker-compose.yml b/examples/reverse-proxy-singlesite/docker-compose.yml index f8d413a6a..303ecbecd 100644 --- a/examples/reverse-proxy-singlesite/docker-compose.yml +++ b/examples/reverse-proxy-singlesite/docker-compose.yml @@ -33,7 +33,6 @@ services: location ~ ^/(app1|app2)$$ { rewrite ^(.*)$$ $$1/ permanent; } - app1: image: tutum/hello-world diff --git a/tests/SwarmTest.py b/tests/SwarmTest.py index b9e50f8c9..981a72b3c 100644 --- a/tests/SwarmTest.py +++ b/tests/SwarmTest.py @@ -91,6 +91,17 @@ class SwarmTest(Test) : proc = run('docker stack deploy -c swarm.yml "' + self._name + '"', shell=True, cwd=test) if proc.returncode != 0 : raise(Exception("docker stack deploy failed")) + i = 0 + healthy = False + while i < self._timeout : + proc = run('docker stack ps --no-trunc --format "{{ .CurrentState }}" ' + self._name + ' | grep -v "Running"', cwd="/tmp/swarm", shell=True, capture_output=True) + if "" == proc.stdout.decode() : + healthy = True + break + sleep(1) + i += 1 + if not healthy : + raise(Exception("swarm stack is not healthy")) except : log("SWARM", "❌", "exception while running SwarmTest._setup_test()\n" + format_exc()) self._cleanup_test() diff --git a/tests/Test.py b/tests/Test.py index 385cae262..267b1beae 100644 --- a/tests/Test.py +++ b/tests/Test.py @@ -16,7 +16,7 @@ class Test(ABC) : def __init__(self, name, kind, timeout, tests, no_copy_container=False) : self._name = name self.__kind = kind - self.__timeout = timeout + self._timeout = timeout self.__tests = tests self._no_copy_container = no_copy_container log("TEST", "ℹ️", "instiantiated with " + str(len(tests)) + " tests and timeout of " + str(timeout) + "s for " + self._name) @@ -74,7 +74,7 @@ class Test(ABC) : if not self._setup_test() : return False start = time() - while time() < start + self.__timeout : + while time() < start + self._timeout : all_ok = True for test in self.__tests : ok = self.__run_test(test) @@ -84,12 +84,12 @@ class Test(ABC) : break if all_ok : elapsed = str(int(time() - start)) - log("TEST", "ℹ️", "success (" + elapsed + "/" + str(self.__timeout) + "s)") + log("TEST", "ℹ️", "success (" + elapsed + "/" + str(self._timeout) + "s)") return self._cleanup_test() log("TEST", "⚠️", "tests not ok, retrying in 1s ...") self._debug_fail() self._cleanup_test() - log("TEST", "❌", "failed (timeout = " + str(self.__timeout) + "s)") + log("TEST", "❌", "failed (timeout = " + str(self._timeout) + "s)") return False # run a single test