test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
-63
View File
@@ -2,11 +2,8 @@
from __future__ import annotations
import asyncio
import json
from collections.abc import Callable
from threading import Thread
from types import SimpleNamespace
from typing import Any
import pytest
@@ -14,10 +11,8 @@ import responses
from tests.remote.unit.test_session_reopen import SERVER, make_service
from unshackle.core import remote_service
from unshackle.core.remote_channel import ServerMessages, WebSocketChannel
from unshackle.core.remote_protocol import ClientErrorKind
from unshackle.core.remote_service import RemoteClient
from unshackle.core.tunnel import TunnelClient, run_loop
pytestmark = pytest.mark.unit
@@ -94,61 +89,3 @@ def test_a_tunnel_copies_the_auth_header_the_server_reads(monkeypatch: pytest.Mo
remote_service.start_tunnel(client)
assert sent[0].get("X-Api-Key") == KEY and "X-Secret-Key" not in sent[0]
def test_a_channel_closes_after_its_loop_has_closed() -> None:
"""A refused upgrade closes the loop of the channel thread before the thread ends."""
service = make_service()
service.ctx = SimpleNamespace(obj=None)
messages = ServerMessages(service)
channel = WebSocketChannel(messages)
loop = asyncio.new_event_loop()
loop.close()
channel.loop, channel.task = loop, SimpleNamespace(cancel=lambda: None)
channel.thread = SimpleNamespace(is_alive=lambda: True, join=lambda timeout=None: None)
channel.close()
def refuse_threads_after_executor_use(monkeypatch: pytest.MonkeyPatch) -> Callable[[Any], Any]:
"""A run that uses the default executor, then refuses every new thread, as Python 3.12.0 to 3.12.2 do at exit."""
def refuse(self: Thread) -> None:
raise RuntimeError("can't create new thread at interpreter shutdown")
async def run(self: Any) -> None:
await asyncio.get_running_loop().run_in_executor(None, lambda: None)
monkeypatch.setattr(Thread, "start", refuse)
return run
def test_a_channel_loop_ends_without_starting_a_thread(monkeypatch: pytest.MonkeyPatch) -> None:
"""The channel thread shuts its loop's executor down without a new thread."""
monkeypatch.setattr(WebSocketChannel, "run", refuse_threads_after_executor_use(monkeypatch))
service = make_service()
service.ctx = SimpleNamespace(obj=None)
messages = ServerMessages(service)
channel = WebSocketChannel(messages)
channel.thread.run()
def test_a_tunnel_loop_ends_without_starting_a_thread(monkeypatch: pytest.MonkeyPatch) -> None:
"""The tunnel thread, which the same atexit close stops, shuts its loop's executor down without a new thread."""
monkeypatch.setattr(TunnelClient, "run", refuse_threads_after_executor_use(monkeypatch))
client = TunnelClient(SERVER, {})
client.thread.run()
def test_a_thread_loop_cancels_the_tasks_its_run_leaves() -> None:
"""A task that the run leaves, such as a channel answer still sending, ends cancelled when the loop closes."""
left: list[asyncio.Future[None]] = []
async def main() -> None:
left.append(asyncio.ensure_future(asyncio.sleep(10)))
run_loop(main)
assert left[0].cancelled()