Skip to content

Commit

Permalink
Format + basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Nov 2, 2024
1 parent 3a3108d commit 5151135
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/viser/infra/_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import queue
import threading
from asyncio.events import AbstractEventLoop
from collections.abc import Awaitable, Coroutine
from collections.abc import Coroutine
from pathlib import Path
from typing import Any, Callable, Generator, NewType, TypeVar

Expand All @@ -22,7 +22,7 @@
import websockets.exceptions
from typing_extensions import Literal, assert_never, override
from websockets import Headers
from websockets.asyncio.server import Server, ServerConnection
from websockets.asyncio.server import ServerConnection
from websockets.http11 import Request, Response

from ._async_message_buffer import AsyncMessageBuffer
Expand Down
21 changes: 21 additions & 0 deletions tests/test_server_stop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import socket

import viser


def test_server_port_is_freed():
server = viser.ViserServer()
original_port = server.get_port()

# Assert that the port is not free.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(("localhost", original_port))
assert result == 0
sock.close()

server.stop()

# Assert that the port is now free.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(("localhost", original_port))
assert result != 0

0 comments on commit 5151135

Please sign in to comment.