mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-11 07:47:12 +02:00
tests: proper handling of event loops
Event loops have to be closed properly, otherwise pytest will throw a warning / error. Disconnecting clients and closing the server is important for that, as well as stopping tasks. Additionally, I had to add loop_scope parameters to share the event loop throughout modules which all use the same pydase.Server instance.
This commit is contained in:
@ -2,8 +2,9 @@ import threading
|
||||
from collections.abc import Generator
|
||||
from typing import Any
|
||||
|
||||
import pydase
|
||||
import pytest
|
||||
|
||||
import pydase
|
||||
from pydase.client.proxy_loader import ProxyAttributeError
|
||||
|
||||
|
||||
@ -52,6 +53,7 @@ def pydase_client() -> Generator[pydase.Client, None, Any]:
|
||||
|
||||
yield client
|
||||
|
||||
client.disconnect()
|
||||
server.handle_exit()
|
||||
thread.join()
|
||||
|
||||
|
@ -2,27 +2,26 @@ import threading
|
||||
from collections.abc import Callable, Generator
|
||||
from typing import Any
|
||||
|
||||
import pydase
|
||||
import pytest
|
||||
import socketio.exceptions
|
||||
|
||||
import pydase
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def pydase_restartable_server() -> (
|
||||
Generator[
|
||||
tuple[
|
||||
pydase.Server,
|
||||
threading.Thread,
|
||||
pydase.DataService,
|
||||
Callable[
|
||||
[pydase.Server, threading.Thread, pydase.DataService],
|
||||
tuple[pydase.Server, threading.Thread],
|
||||
],
|
||||
def pydase_restartable_server() -> Generator[
|
||||
tuple[
|
||||
pydase.Server,
|
||||
threading.Thread,
|
||||
pydase.DataService,
|
||||
Callable[
|
||||
[pydase.Server, threading.Thread, pydase.DataService],
|
||||
tuple[pydase.Server, threading.Thread],
|
||||
],
|
||||
None,
|
||||
Any,
|
||||
]
|
||||
):
|
||||
],
|
||||
None,
|
||||
Any,
|
||||
]:
|
||||
class MyService(pydase.DataService):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
@ -62,9 +61,6 @@ def pydase_restartable_server() -> (
|
||||
|
||||
yield server, thread, service_instance, restart
|
||||
|
||||
server.handle_exit()
|
||||
thread.join()
|
||||
|
||||
|
||||
def test_reconnection(
|
||||
pydase_restartable_server: tuple[
|
||||
@ -105,3 +101,6 @@ def test_reconnection(
|
||||
# the service proxies successfully reconnect and get the new service name
|
||||
assert client.proxy.name == "New service name"
|
||||
assert client_2.proxy.name == "New service name"
|
||||
|
||||
server.handle_exit()
|
||||
thread.join()
|
||||
|
Reference in New Issue
Block a user