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

replication smoketest #2148

Draft
wants to merge 16 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
41 changes: 27 additions & 14 deletions smoketests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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 Expand Up @@ -172,6 +175,12 @@ def call(self, reducer, *args, anon=False):
anon = ["--anonymous"] if anon else []
self.spacetime("call", *anon, "--", self.database_identity, reducer, *map(json.dumps, args))


def sql(self, sql):
self._check_published()
anon = ["--anonymous"]
return self.spacetime("sql", *anon, "--", self.database_identity, sql)

def logs(self, n):
return [log["message"] for log in self.log_records(n)]

Expand All @@ -181,6 +190,7 @@ def log_records(self, n):
return list(map(json.loads, logs.splitlines()))

def publish_module(self, domain=None, *, clear=True, capture_stderr=True):
print("publishing module", self.publish_module)
publish_output = self.spacetime(
"publish",
*[domain] if domain is not None else [],
Expand Down Expand Up @@ -283,23 +293,26 @@ def setUpClass(cls):
logging.info(f"Compiling module for {cls.__qualname__}...")
cls.publish_module(cls, capture_stderr=True) # capture stderr because otherwise it clutters the top-level test logs for some reason.

#TODO: revert this
def tearDown(self):
# if this single test method published a database, clean it up now
if "database_identity" in self.__dict__:
try:
# TODO: save the credentials in publish_module()
self.spacetime("delete", self.database_identity)
except Exception:
pass

pass
# if this single test method published a database, clean it up now
# if "database_identity" in self.__dict__:
# try:
# # TODO: save the credentials in publish_module()
# self.spacetime("delete", self.database_identity)
# except Exception:
# pass
#
@classmethod
def tearDownClass(cls):
if hasattr(cls, "database_identity"):
try:
# TODO: save the credentials in publish_module()
cls.spacetime("delete", cls.database_identity)
except Exception:
pass
pass
# if hasattr(cls, "database_identity"):
# try:
# # TODO: save the credentials in publish_module()
# cls.spacetime("delete", cls.database_identity)
# except Exception:
# pass

if sys.version_info < (3, 11):
# polyfill; python 3.11 defines this classmethod on TestCase
Expand Down
14 changes: 11 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,8 @@ 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("--no-docker-logs", action="store_true")
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 +96,15 @@ 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:
smoketests.COMPOSE_FILE = args.compose_file
if not args.no_docker_logs:
if args.compose_file:
subprocess.Popen(["docker", "compose", "-f", args.compose_file, "logs", "-f"])
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
Loading
Loading