-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new websockets API, fix
.stop()
(#313)
* Fix `server.stop()` * HTTP server fixes * Format + basic test * Fix Python 3.8 * Don't build client in test * Add sleep to server stop test
- Loading branch information
Showing
3 changed files
with
101 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import socket | ||
import time | ||
|
||
import viser | ||
import viser._client_autobuild | ||
|
||
|
||
def test_server_port_is_freed(): | ||
# Mock the client autobuild to avoid building the client. | ||
viser._client_autobuild.ensure_client_is_built = lambda: None | ||
|
||
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() | ||
|
||
time.sleep(0.05) | ||
|
||
# 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 |