tests - wait until swarm services are running

This commit is contained in:
bunkerity 2022-07-27 13:56:05 +02:00
parent a48200bc02
commit d3b725294f
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
4 changed files with 16 additions and 6 deletions

View File

@ -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.

View File

@ -33,7 +33,6 @@ services:
location ~ ^/(app1|app2)$$ {
rewrite ^(.*)$$ $$1/ permanent;
}
app1:
image: tutum/hello-world

View File

@ -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()

View File

@ -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