Add socket reuse tests (#911)

* Add socket reuse tests
* Address comments.
This commit is contained in:
Karthik Nadig 2018-10-13 00:51:40 -07:00 committed by GitHub
parent 99cd1595f8
commit 52aeb0fae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

31
pytests/test_socket.py Normal file
View file

@ -0,0 +1,31 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
import pytest
from ptvsd.socket import create_server, shut_down
class TestSocketServerReuse(object):
HOST1 = '127.0.0.1'
HOST2 = '127.0.0.2'
PORT1 = 7890
def test_reuse_same_address_port(self):
try:
sock1 = create_server(self.HOST1, self.PORT1)
with pytest.raises(Exception):
create_server(self.HOST1, self.PORT1)
assert sock1.getsockname() == (self.HOST1, self.PORT1)
finally:
shut_down(sock1)
def test_reuse_same_port(self):
try:
sock1 = create_server(self.HOST1, self.PORT1)
sock2 = create_server(self.HOST2, self.PORT1)
assert sock1.getsockname() == (self.HOST1, self.PORT1)
assert sock2.getsockname() == (self.HOST2, self.PORT1)
finally:
shut_down(sock1)
shut_down(sock2)