Skip to content
Merged
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
10 changes: 7 additions & 3 deletions smoketests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
exe_suffix = ".exe" if sys.platform == "win32" else ""
SPACETIME_BIN = STDB_DIR / ("target/debug/spacetime" + exe_suffix)
TEMPLATE_TARGET_DIR = STDB_DIR / "target/_stdbsmoketests"
STDB_CONFIG = TEST_DIR / "config.toml"
BASE_STDB_CONFIG_PATH = TEST_DIR / "config.toml"

# the contents of files for the base smoketest project template
TEMPLATE_LIB_RS = open(STDB_DIR / "crates/cli/templates/basic-rust/server/src/lib.rs").read()
Expand Down Expand Up @@ -50,6 +50,9 @@
# default value can be overridden by `--compose-file` flag
COMPOSE_FILE = "./docker-compose.yml"

# this will be initialized by main()
STDB_CONFIG = ''

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

Expand Down Expand Up @@ -234,7 +237,6 @@ def log_records(self, n):
return list(map(json.loads, logs.splitlines()))

def publish_module(self, domain=None, *, clear=True, capture_stderr=True, num_replicas=None, break_clients=False):
print("publishing module", self.publish_module)
publish_output = self.spacetime(
"publish",
*[domain] if domain is not None else [],
Expand All @@ -253,7 +255,9 @@ def publish_module(self, domain=None, *, clear=True, capture_stderr=True, num_re

@classmethod
def reset_config(cls):
shutil.copy(STDB_CONFIG, cls.config_path)
if not STDB_CONFIG:
raise Exception("config toml has not been initialized yet")
cls.config_path.write_text(STDB_CONFIG)

def fingerprint(self):
# Fetch the server's fingerprint; required for `identity list`.
Expand Down
34 changes: 21 additions & 13 deletions smoketests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import re
import fnmatch
import json
from . import TEST_DIR, SPACETIME_BIN, exe_suffix, build_template_target
from . import TEST_DIR, SPACETIME_BIN, BASE_STDB_CONFIG_PATH, exe_suffix, build_template_target
import smoketests
import sys
import logging
import itertools
import tempfile
from pathlib import Path
import shutil

def check_docker():
docker_ps = smoketests.run_cmd("docker", "ps", "--format=json")
Expand Down Expand Up @@ -93,13 +96,10 @@ def main():
try:
os.symlink(update_bin_name, SPACETIME_BIN)
except OSError:
import shutil
shutil.copyfile(SPACETIME_BIN.with_name(update_bin_name), SPACETIME_BIN)

os.environ["SPACETIME_SKIP_CLIPPY"] = "1"

build_template_target()

if args.docker:
# have docker logs print concurrently with the test output
if args.compose_file:
Expand All @@ -112,16 +112,24 @@ def main():
subprocess.Popen(["docker", "logs", "-f", docker_container])
smoketests.HAVE_DOCKER = True

if args.remote_server is not None:
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "server", "edit", "localhost", "--url", args.remote_server, "--yes")
smoketests.REMOTE_SERVER = True
with tempfile.NamedTemporaryFile(mode="w+b", suffix=".toml", buffering=0, delete_on_close=False) as config_file:
with BASE_STDB_CONFIG_PATH.open("rb") as src, config_file.file as dst:
shutil.copyfileobj(src, dst)

if args.spacetime_login:
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "logout")
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "login")
smoketests.USE_SPACETIME_LOGIN = True
else:
smoketests.new_identity(TEST_DIR / 'config.toml')
if args.remote_server is not None:
smoketests.spacetime("--config-path", config_file.name, "server", "edit", "localhost", "--url", args.remote_server, "--yes")
smoketests.REMOTE_SERVER = True

if args.spacetime_login:
smoketests.spacetime("--config-path", config_file.name, "logout")
smoketests.spacetime("--config-path", config_file.name, "login")
smoketests.USE_SPACETIME_LOGIN = True
else:
smoketests.new_identity(config_file.name)

smoketests.STDB_CONFIG = Path(config_file.name).read_text()

build_template_target()

if not args.skip_dotnet:
smoketests.HAVE_DOTNET = check_dotnet()
Expand Down
1 change: 0 additions & 1 deletion smoketests/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
default_server = "localhost"
spacetimedb_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiJjMjAwMTU3NGEwMjgyNDRjNzZhNTE1MjU1NGMzY2ZjMWJiNmIzNzZlNjY4YmU1Yjg2MzE0MDAyYWRmOTMyYWVlIiwic3ViIjoiYzYwOWJkYjUtMDAyNS00YzZkLWIyZTktOGYyODEwM2IzNWUzIiwiaXNzIjoibG9jYWxob3N0IiwiYXVkIjpbInNwYWNldGltZWRiIl0sImlhdCI6MTc1NjkwOTQ3NywiZXhwIjpudWxsfQ.t6Aobx9fTe6kwvq7H01-2RO7vdK4SjQB7Uw-Lh4Daz0lG43WzIw3oVG_65txqlsFSkpx40wYElByj4jMolutpA"

[[server_configs]]
nickname = "localhost"
Expand Down
15 changes: 6 additions & 9 deletions smoketests/tests/replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,17 @@ def setUpClass(cls):
super().setUpClass()
cls.root_config = cls.project_path / "root_config"

def tearDown(self):
# Ensure containers that were brought down during a test are back up.
self.docker.compose("up", "-d")
super().tearDown()

# TODO: This function seems to run even when `--docker` is not passed, leading to errors unless `-x replication` is passed, due to the docker-related code below.
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def setUp(self):
self.docker = DockerManager(COMPOSE_FILE)
self.root_token = self.docker.generate_root_token()

self.cluster = Cluster(self.docker, self)

def tearDown(self):
# Ensure containers that were brought down during a test are back up.
self.docker.compose("up", "-d")
super().tearDown()

def add_me_as_admin(self):
"""Add the current user as an admin account"""
db_owner_id = str(self.spacetime("login", "show")).split()[-1]
Expand Down
28 changes: 0 additions & 28 deletions smoketests/tests/template

This file was deleted.

Loading