diff --git a/tests/integration/test_mysql.py b/tests/integration/test_mysql.py index 77cde33..9394abf 100644 --- a/tests/integration/test_mysql.py +++ b/tests/integration/test_mysql.py @@ -27,6 +27,8 @@ IMAGE = ( "f4a1ba2d463d692fada04ec7f40be00" ) +IMAGE_REF = "mysql@" + IMAGE + LABEL = "absdev.framework.integration" SOURCE_DATABASE = "example_db" @@ -103,9 +105,9 @@ class MySQLIntegrationTests(unittest.TestCase): import socket - if socket.gethostname().split(".")[0].lower() == "absdev": + if socket.gethostname().split(".")[0].lower() != "absdev-ci": self.skipTest( - "Database integration tests prohibited on ABSDEV" + "Database integration tests permitted only on ABSDEV-CI" ) if os.environ.get("ABSDEV_INTEGRATION_TESTS") != "1": @@ -137,6 +139,12 @@ class MySQLIntegrationTests(unittest.TestCase): ROOT / "runtime/integration" ) + runtime.mkdir(mode=0o700, parents=True, exist_ok=True) + require( + runtime.resolve() == runtime.absolute(), + "Unsafe integration runtime path", + ) + work = runtime / name work.mkdir(mode=0o700) @@ -156,7 +164,7 @@ class MySQLIntegrationTests(unittest.TestCase): ) require( - available >= 786432, + available >= 2097152, "Insufficient available memory", ) @@ -170,12 +178,13 @@ class MySQLIntegrationTests(unittest.TestCase): image = json.loads( command( - "docker", "image", "inspect", IMAGE + "docker", "image", "inspect", IMAGE_REF ) )[0] require( - image["Id"] == IMAGE, + image["Id"] == IMAGE + and IMAGE_REF in image["RepoDigests"], "Unexpected database image", ) @@ -207,14 +216,14 @@ class MySQLIntegrationTests(unittest.TestCase): "--label", f"absdev.integration.token={token}", "--network", "none", "--restart", "no", - "--memory", "512m", - "--memory-swap", "768m", - "--cpus", "0.5", + "--memory", "1024m", + "--memory-swap", "1024m", + "--cpus", "1.0", "--pids-limit", "256", "--security-opt", "no-new-privileges=true", "--env-file", str(envfile), - IMAGE, + IMAGE_REF, "--innodb-buffer-pool-size=64M", "--max-connections=20", "--performance-schema=OFF", @@ -255,9 +264,14 @@ class MySQLIntegrationTests(unittest.TestCase): ) require( - host["Memory"] == 512 * 1024 * 1024 + host["Memory"] == 1024 * 1024 * 1024 and host["MemorySwap"] - == 768 * 1024 * 1024, + == 1024 * 1024 * 1024 + and host["NanoCpus"] == 1000000000 + and host["PidsLimit"] == 256 + and "no-new-privileges" in " ".join( + host.get("SecurityOpt") or [] + ), "Resource limits changed", ) @@ -288,7 +302,7 @@ class MySQLIntegrationTests(unittest.TestCase): print("PASS: Disposable container started") - deadline = time.monotonic() + 180 + deadline = time.monotonic() + 300 while time.monotonic() < deadline: @@ -315,7 +329,7 @@ class MySQLIntegrationTests(unittest.TestCase): if b"mysqld is alive" in result: break - except RuntimeError: + except (RuntimeError, subprocess.TimeoutExpired): pass time.sleep(2)