Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smoketests: Use docker compose logs if compose file is specified #2142

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions smoketests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
# and a dotnet installation is detected
HAVE_DOTNET = False

# default value can be overriden by `--compose-file` flag
COMPOSE_FILE = "./docker-compose.yml"

# we need to late-bind the output stream to allow unittests to capture stdout/stderr.
class CapturableHandler(logging.StreamHandler):

Expand Down
11 changes: 8 additions & 3 deletions smoketests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def check_docker():
docker_ps = smoketests.run_cmd("docker", "ps", "--format=json")
docker_ps = (json.loads(line) for line in docker_ps.splitlines())
for docker_container in docker_ps:
if "node" in docker_container["Image"]:
if "node" in docker_container["Image"] or "spacetime" in docker_container["Image"]:
return docker_container["Names"]
else:
print("Docker container not found, is SpacetimeDB running?")
Expand Down Expand Up @@ -58,6 +58,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("test", nargs="*", default=tests)
parser.add_argument("--docker", action="store_true")
parser.add_argument("--compose-file")
parser.add_argument("--skip-dotnet", action="store_true", help="ignore tests which require dotnet")
parser.add_argument("--show-all-output", action="store_true", help="show all stdout/stderr from the tests as they're running")
parser.add_argument("--parallel", action="store_true", help="run test classes in parallel")
Expand Down Expand Up @@ -94,9 +95,13 @@ def main():
build_template_target()

if args.docker:
docker_container = check_docker()
# have docker logs print concurrently with the test output
subprocess.Popen(["docker", "logs", "-f", docker_container])
if args.compose_file:
subprocess.Popen(["docker", "compose", "-f", args.compose_file, "logs", "-f"])
smoketests.COMPOSE_FILE = args.compose_file
else:
docker_container = check_docker()
subprocess.Popen(["docker", "logs", "-f", docker_container])
smoketests.HAVE_DOCKER = True

smoketests.new_identity(TEST_DIR / 'config.toml')
Expand Down
7 changes: 4 additions & 3 deletions smoketests/tests/zz_docker.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import time
from .. import Smoketest, run_cmd, requires_docker
from .. import Smoketest, run_cmd, requires_docker, COMPOSE_FILE
from urllib.request import urlopen
from .add_remove_index import AddRemoveIndex


def restart_docker():

# Behold!
#
# You thought stop/start restarts? How wrong. Restart restarts.
run_cmd("docker", "compose", "restart")
run_cmd("docker", "compose", "-f", COMPOSE_FILE, "restart")
# The suspense!
#
# Wait until compose believes the health probe succeeds.
#
# The container may decide to recompile, or grab a coffee at crates.io, or
# whatever. In any case, restart doesn't mean the server is up yet.
run_cmd("docker", "compose", "up", "--no-recreate", "--detach", "--wait-timeout", "60")
run_cmd("docker", "compose","-f", COMPOSE_FILE, "up", "--no-recreate", "--detach", "--wait-timeout", "60")
# Belts and suspenders!
#
# The health probe runs inside the container, but that doesn't mean we can
Expand Down