Skip to content

Commit 18af6c4

Browse files
coolreader18bfops
andauthored
Fix some annoyances with the smoketests (#3556)
# Description of Changes Now running `python -m smoketests` no longer updates `smoketests/config.toml` with a new identity, and also `replication` doesn't fail when docker isn't available. # Expected complexity level and risk 1 # Testing - [x] those things no longer happen --------- Co-authored-by: Zeke Foppa <[email protected]>
1 parent 5c42b09 commit 18af6c4

File tree

5 files changed

+34
-54
lines changed

5 files changed

+34
-54
lines changed

smoketests/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
exe_suffix = ".exe" if sys.platform == "win32" else ""
2323
SPACETIME_BIN = STDB_DIR / ("target/debug/spacetime" + exe_suffix)
2424
TEMPLATE_TARGET_DIR = STDB_DIR / "target/_stdbsmoketests"
25-
STDB_CONFIG = TEST_DIR / "config.toml"
25+
BASE_STDB_CONFIG_PATH = TEST_DIR / "config.toml"
2626

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

53+
# this will be initialized by main()
54+
STDB_CONFIG = ''
55+
5356
# we need to late-bind the output stream to allow unittests to capture stdout/stderr.
5457
class CapturableHandler(logging.StreamHandler):
5558

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

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

254256
@classmethod
255257
def reset_config(cls):
256-
shutil.copy(STDB_CONFIG, cls.config_path)
258+
if not STDB_CONFIG:
259+
raise Exception("config toml has not been initialized yet")
260+
cls.config_path.write_text(STDB_CONFIG)
257261

258262
def fingerprint(self):
259263
# Fetch the server's fingerprint; required for `identity list`.

smoketests/__main__.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import re
88
import fnmatch
99
import json
10-
from . import TEST_DIR, SPACETIME_BIN, exe_suffix, build_template_target
10+
from . import TEST_DIR, SPACETIME_BIN, BASE_STDB_CONFIG_PATH, exe_suffix, build_template_target
1111
import smoketests
1212
import sys
1313
import logging
1414
import itertools
15+
import tempfile
16+
from pathlib import Path
17+
import shutil
1518

1619
def check_docker():
1720
docker_ps = smoketests.run_cmd("docker", "ps", "--format=json")
@@ -93,13 +96,10 @@ def main():
9396
try:
9497
os.symlink(update_bin_name, SPACETIME_BIN)
9598
except OSError:
96-
import shutil
9799
shutil.copyfile(SPACETIME_BIN.with_name(update_bin_name), SPACETIME_BIN)
98100

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

101-
build_template_target()
102-
103103
if args.docker:
104104
# have docker logs print concurrently with the test output
105105
if args.compose_file:
@@ -112,16 +112,24 @@ def main():
112112
subprocess.Popen(["docker", "logs", "-f", docker_container])
113113
smoketests.HAVE_DOCKER = True
114114

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

119-
if args.spacetime_login:
120-
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "logout")
121-
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "login")
122-
smoketests.USE_SPACETIME_LOGIN = True
123-
else:
124-
smoketests.new_identity(TEST_DIR / 'config.toml')
119+
if args.remote_server is not None:
120+
smoketests.spacetime("--config-path", config_file.name, "server", "edit", "localhost", "--url", args.remote_server, "--yes")
121+
smoketests.REMOTE_SERVER = True
122+
123+
if args.spacetime_login:
124+
smoketests.spacetime("--config-path", config_file.name, "logout")
125+
smoketests.spacetime("--config-path", config_file.name, "login")
126+
smoketests.USE_SPACETIME_LOGIN = True
127+
else:
128+
smoketests.new_identity(config_file.name)
129+
130+
smoketests.STDB_CONFIG = Path(config_file.name).read_text()
131+
132+
build_template_target()
125133

126134
if not args.skip_dotnet:
127135
smoketests.HAVE_DOTNET = check_dotnet()

smoketests/config.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
default_server = "localhost"
2-
spacetimedb_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJoZXhfaWRlbnRpdHkiOiJjMjAwMTU3NGEwMjgyNDRjNzZhNTE1MjU1NGMzY2ZjMWJiNmIzNzZlNjY4YmU1Yjg2MzE0MDAyYWRmOTMyYWVlIiwic3ViIjoiYzYwOWJkYjUtMDAyNS00YzZkLWIyZTktOGYyODEwM2IzNWUzIiwiaXNzIjoibG9jYWxob3N0IiwiYXVkIjpbInNwYWNldGltZWRiIl0sImlhdCI6MTc1NjkwOTQ3NywiZXhwIjpudWxsfQ.t6Aobx9fTe6kwvq7H01-2RO7vdK4SjQB7Uw-Lh4Daz0lG43WzIw3oVG_65txqlsFSkpx40wYElByj4jMolutpA"
32

43
[[server_configs]]
54
nickname = "localhost"

smoketests/tests/replication.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,17 @@ def setUpClass(cls):
227227
cls.root_config = cls.project_path / "root_config"
228228
spacetime("--config-path", cls.root_config, "server", "set-default", "local")
229229

230-
def tearDown(self):
231-
# Ensure containers that were brought down during a test are back up.
232-
self.docker.compose("up", "-d")
233-
super().tearDown()
234-
235-
# 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.
236-
def __init__(self, *args, **kwargs):
237-
super().__init__(*args, **kwargs)
238-
230+
def setUp(self):
239231
self.docker = DockerManager(COMPOSE_FILE)
240232
self.root_token = self.docker.generate_root_token()
241233

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

236+
def tearDown(self):
237+
# Ensure containers that were brought down during a test are back up.
238+
self.docker.compose("up", "-d")
239+
super().tearDown()
240+
244241
def add_me_as_admin(self):
245242
"""Add the current user as an admin account"""
246243
db_owner_id = str(self.spacetime("login", "show")).split()[-1]

smoketests/tests/template

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)