Skip to content

Commit 1309f5a

Browse files
committed
Fix some annoyances with the smoketests
1 parent 3cc59de commit 1309f5a

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

smoketests/__init__.py

Lines changed: 5 additions & 2 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 = None
55+
5356
# we need to late-bind the output stream to allow unittests to capture stdout/stderr.
5457
class CapturableHandler(logging.StreamHandler):
5558

@@ -253,7 +256,7 @@ def publish_module(self, domain=None, *, clear=True, capture_stderr=True, num_re
253256

254257
@classmethod
255258
def reset_config(cls):
256-
shutil.copy(STDB_CONFIG, cls.config_path)
259+
cls.config_path.write_text(STDB_CONFIG)
257260

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

smoketests/__main__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
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
1516

1617
def check_docker():
1718
docker_ps = smoketests.run_cmd("docker", "ps", "--format=json")
@@ -112,16 +113,23 @@ def main():
112113
subprocess.Popen(["docker", "logs", "-f", docker_container])
113114
smoketests.HAVE_DOCKER = True
114115

116+
config_file = tempfile.NamedTemporaryFile(mode="w+b", suffix=".toml", buffering=0)
117+
config_file.write(BASE_STDB_CONFIG_PATH.read_bytes())
118+
config_file.flush()
119+
115120
if args.remote_server is not None:
116-
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "server", "edit", "localhost", "--url", args.remote_server, "--yes")
121+
smoketests.spacetime("--config-path", config_file.name, "server", "edit", "localhost", "--url", args.remote_server, "--yes")
117122
smoketests.REMOTE_SERVER = True
118123

119124
if args.spacetime_login:
120-
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "logout")
121-
smoketests.spacetime("--config-path", TEST_DIR / 'config.toml', "login")
125+
smoketests.spacetime("--config-path", config_file.name, "logout")
126+
smoketests.spacetime("--config-path", config_file.name, "login")
122127
smoketests.USE_SPACETIME_LOGIN = True
123128
else:
124-
smoketests.new_identity(TEST_DIR / 'config.toml')
129+
smoketests.new_identity(config_file.name)
130+
131+
config_file.seek(0)
132+
smoketests.STDB_CONFIG = config_file.read().decode()
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: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,18 @@ class ReplicationTest(Smoketest):
223223

224224
@classmethod
225225
def setUpClass(cls):
226-
super().setUpClass()
227226
cls.root_config = cls.project_path / "root_config"
228227

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

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

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

0 commit comments

Comments
 (0)