Replaced start up tests.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2025-06-22 17:04:37 -04:00
parent e69dbf58fa
commit e555acfdb4
6 changed files with 121 additions and 16 deletions

View File

@@ -3,7 +3,6 @@
from asyncio import create_subprocess_exec
from socket import AF_INET, SOCK_STREAM, socket
from pathlib import Path
from release_tests.support import ADDR, get_port
EXECUTABLE = Path.cwd().joinpath("target", "release", "morethantext")
@@ -11,27 +10,51 @@ EXECUTABLE = Path.cwd().joinpath("target", "release", "morethantext")
class MTTServer:
"""Runs a MoreThanText server."""
def __init__(self):
def __init__(self, *args):
"""Initialization"""
self.port = get_port()
self.cmd = [EXECUTABLE, "-a", ADDR, "-p", str(self.port)]
self.port = 3000
self.address = "127.0.0.1"
self.cmd = [EXECUTABLE]
for item in list(args):
self.cmd.append(str(item))
try:
self.port = self.cmd[self.cmd.index("-p") + 1]
except ValueError:
pass
try:
self.port = self.cmd[self.cmd.index("--port") + 1]
except ValueError:
pass
try:
self.address = self.cmd[self.cmd.index("-a") + 1]
except ValueError:
pass
try:
self.address = self.cmd[self.cmd.index("--address") + 1]
except ValueError:
pass
self.server = None
@property
def baseurl(self):
"""URL to server"""
return f"http://{ADDR}:{self.port}"
return f"http://{self.address}:{self.port}"
async def start(self):
"""Starts the server."""
self.server = await create_subprocess_exec(*self.cmd)
# delays the return untul the serverr is responding.
with socket(AF_INET, SOCK_STREAM) as soc:
while soc.connect_ex((ADDR, self.port)) != 0:
while soc.connect_ex((self.address, int(self.port))) != 0:
continue
async def stop(self):
"""Stops the server."""
if self.server:
self.server.terminate()
await self.server.wait()
if not self.server.returncode:
self.server.terminate()
await self.server.wait()
async def cleanup(self):
"""Clean up."""
await self.stop()