forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f674f2ed6c |
File diff suppressed because one or more lines are too long
@@ -2,8 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
from devplacepy.config import XMLRPC_BIND, XMLRPC_PORT
|
||||
from devplacepy.services.base import BaseService
|
||||
@@ -25,20 +27,48 @@ class XmlrpcService(BaseService):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("xmlrpc", interval_seconds=XMLRPC_INTERVAL_SECONDS)
|
||||
self._process: subprocess.Popen | None = None
|
||||
self._last_stderr: str | None = None
|
||||
|
||||
def _alive(self) -> bool:
|
||||
return self._process is not None and self._process.poll() is None
|
||||
|
||||
def _spawn(self) -> None:
|
||||
self._last_stderr = None
|
||||
self._process = subprocess.Popen(
|
||||
[sys.executable, "-m", SERVER_MODULE],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
self.log(
|
||||
f"Forking XML-RPC server started (pid {self._process.pid}) on "
|
||||
f"Forking XML-RPC server spawning (pid {self._process.pid}) on "
|
||||
f"{XMLRPC_BIND}:{XMLRPC_PORT}"
|
||||
)
|
||||
time.sleep(0.5)
|
||||
if self._process.poll() is not None:
|
||||
stderr_data = self._process.communicate()[1]
|
||||
if stderr_data:
|
||||
self._last_stderr = stderr_data.decode("utf-8", errors="replace")
|
||||
self.log(
|
||||
f"Forking XML-RPC server died after spawn (pid {self._process.pid}, "
|
||||
f"exit code {self._process.returncode})"
|
||||
)
|
||||
if self._last_stderr:
|
||||
for line in self._last_stderr.strip().split("\n"):
|
||||
self.log(f" stderr: {line}")
|
||||
return
|
||||
try:
|
||||
sock = socket.create_connection((XMLRPC_BIND, XMLRPC_PORT), timeout=1)
|
||||
sock.close()
|
||||
except (OSError, socket.timeout):
|
||||
self.log(
|
||||
f"Forking XML-RPC server not yet ready (pid {self._process.pid}) "
|
||||
f"on {XMLRPC_BIND}:{XMLRPC_PORT}"
|
||||
)
|
||||
else:
|
||||
self.log(
|
||||
f"Forking XML-RPC server started (pid {self._process.pid}) on "
|
||||
f"{XMLRPC_BIND}:{XMLRPC_PORT}"
|
||||
)
|
||||
|
||||
def _terminate(self) -> None:
|
||||
if not self._alive():
|
||||
@@ -65,6 +95,13 @@ class XmlrpcService(BaseService):
|
||||
self.log(f"XML-RPC server healthy (pid {self._process.pid})")
|
||||
return
|
||||
self.log("XML-RPC server not running, starting it")
|
||||
if self._process is not None:
|
||||
self.log(
|
||||
f"Previous process exited with code {self._process.returncode}"
|
||||
)
|
||||
if self._last_stderr:
|
||||
for line in self._last_stderr.strip().split("\n"):
|
||||
self.log(f" last stderr: {line}")
|
||||
self._spawn()
|
||||
|
||||
def collect_metrics(self) -> dict:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from socketserver import ForkingMixIn
|
||||
from xmlrpc.server import SimpleXMLRPCDispatcher, SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
||||
|
||||
@@ -116,6 +117,9 @@ def main() -> None:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
logger.info("XML-RPC server interrupted")
|
||||
except Exception:
|
||||
logging.exception("XML-RPC server crashed with unhandled exception")
|
||||
sys.exit(1)
|
||||
finally:
|
||||
server.server_close()
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export class MessagesLayout {
|
||||
}
|
||||
this.thread = document.querySelector(".messages-thread");
|
||||
this.form = document.querySelector(".messages-input-area");
|
||||
this.input = this.form ? this.form.querySelector('textarea[name="content"]') : null;
|
||||
this.input = this.form ? this.form.querySelector('input[name="content"]') : null;
|
||||
this.upload = this.form ? this.form.querySelector("dp-upload") : null;
|
||||
this.sendBtn = this.form ? this.form.querySelector(".messages-send-btn") : null;
|
||||
this._uploading = false;
|
||||
|
||||
@@ -176,7 +176,7 @@ def test_send_message_appears_in_thread(alice):
|
||||
f"{BASE_URL}/messages?with_uid={bob['uid']}", wait_until="domcontentloaded"
|
||||
)
|
||||
msg = f"Hello bob {int(time.time() * 1000)}"
|
||||
page.fill("textarea[name='content']", msg)
|
||||
page.fill("input[name='content']", msg)
|
||||
page.locator(".messages-send-btn").click()
|
||||
page.wait_for_url("**/messages**", wait_until="domcontentloaded")
|
||||
page.locator(f".message-bubble:has-text('{msg}')").first.wait_for(state="visible")
|
||||
|
||||
@@ -440,7 +440,7 @@ def test_message_notification(app_server, browser, seeded_db):
|
||||
pb.goto(f"{BASE_URL}/messages?search=alice_test", wait_until="domcontentloaded")
|
||||
pb.wait_for_timeout(2000)
|
||||
|
||||
msg_input = pb.locator("textarea[name='content']").first
|
||||
msg_input = pb.locator("input[name='content']").first
|
||||
msg_input.wait_for(state="visible", timeout=10000)
|
||||
msg_input.fill("Hello from bob_test!")
|
||||
pb.locator("button[type='submit']").last.click()
|
||||
@@ -753,7 +753,7 @@ def test_message_notification_click_opens_conversation(app_server, browser, seed
|
||||
|
||||
pb.goto(f"{BASE_URL}/messages?search=alice_test", wait_until="domcontentloaded")
|
||||
pb.wait_for_timeout(2000)
|
||||
msg_input = pb.locator("textarea[name='content']").first
|
||||
msg_input = pb.locator("input[name='content']").first
|
||||
msg_input.wait_for(state="visible", timeout=10000)
|
||||
msg_input.fill("Click-through message from bob")
|
||||
pb.locator("button[type='submit']").last.click()
|
||||
|
||||
Reference in New Issue
Block a user