Skip to content

Commit bb94304

Browse files
author
lukpueh
authored
Merge pull request #985 from lukpueh/quickfix-win-py27-tests
Fix failing AppVeyor Python2.7 tests
2 parents 83d6ded + 842f843 commit bb94304

File tree

5 files changed

+28
-78
lines changed

5 files changed

+28
-78
lines changed

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
packages = find_packages(exclude=['tests']),
125125
scripts = [
126126
'tuf/scripts/repo.py',
127-
'tuf/scripts/client.py',
128-
'tuf/scripts/simple_server.py',
127+
'tuf/scripts/client.py'
129128
]
130129
)

tests/simple_server.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535

3636
import sys
3737
import random
38+
import platform
3839

3940
import six
41+
from six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler
4042

4143
PORT = 0
4244

@@ -55,7 +57,22 @@ def _port_gen():
5557
else:
5658
PORT = _port_gen()
5759

58-
Handler = six.moves.SimpleHTTPServer.SimpleHTTPRequestHandler
59-
httpd = six.moves.socketserver.TCPServer(('', PORT), Handler)
60+
61+
class QuietHTTPRequestHandler(SimpleHTTPRequestHandler):
62+
"""A SimpleHTTPRequestHandler that does not write incoming requests to
63+
stderr. """
64+
def log_request(self, code='-', size='-'):
65+
pass
66+
67+
# NOTE: On Windows/Python2 tests that use this simple_server.py in a
68+
# subprocesses hang after a certain amount of requests (~68), if a PIPE is
69+
# passed as Popen's stderr argument. As a simple workaround we silence the
70+
# server on those Windows/Py2 to not fill the buffer.
71+
if six.PY2 and platform.system() == 'Windows':
72+
handler = QuietHTTPRequestHandler
73+
else:
74+
handler = SimpleHTTPRequestHandler
75+
76+
httpd = six.moves.socketserver.TCPServer(('', PORT), handler)
6077

6178
httpd.serve_forever()

tests/test_multiple_repositories_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ def setUp(self):
128128
while self.SERVER_PORT == self.SERVER_PORT2:
129129
self.SERVER_PORT2 = random.SystemRandom().randint(30000, 45000)
130130

131-
command = ['python', '-m', 'tuf.scripts.simple_server', str(self.SERVER_PORT)]
132-
command2 = ['python', '-m', 'tuf.scripts.simple_server', str(self.SERVER_PORT2)]
131+
command = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT)]
132+
command2 = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT2)]
133133

134134
self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE,
135135
cwd=self.repository_directory)

tests/test_updater.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def setUpClass(cls):
9898
# as a delegated role 'targets/role1', three target files, five key files,
9999
# etc.
100100
cls.SERVER_PORT = random.randint(30000, 45000)
101-
command = ['python', '-m', 'tuf.scripts.simple_server', str(cls.SERVER_PORT)]
101+
command = ['python', '-m', 'tests.simple_server', str(cls.SERVER_PORT)]
102102
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
103103
logger.info('\n\tServer process started.')
104104
logger.info('\tServer process id: '+str(cls.server_process.pid))
@@ -1094,7 +1094,7 @@ def test_6_get_one_valid_targetinfo(self):
10941094
# The SimpleHTTPServer started in the setupclass has a tendency to
10951095
# timeout in Windows after a few tests.
10961096
SERVER_PORT = random.randint(30000, 45000)
1097-
command = ['python', '-m', 'tuf.scripts.simple_server', str(SERVER_PORT)]
1097+
command = ['python', '-m', 'tests.simple_server', str(SERVER_PORT)]
10981098
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
10991099

11001100
# NOTE: Following error is raised if a delay is not long enough:
@@ -1361,7 +1361,7 @@ def test_7_updated_targets(self):
13611361
# The SimpleHTTPServer started in the setupclass has a tendency to
13621362
# timeout in Windows after a few tests.
13631363
SERVER_PORT = random.randint(30000, 45000)
1364-
command = ['python', '-m', 'tuf.scripts.simple_server', str(SERVER_PORT)]
1364+
command = ['python', '-m', 'tests.simple_server', str(SERVER_PORT)]
13651365
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
13661366

13671367
# NOTE: Following error is raised if a delay is not long enough to allow
@@ -1493,7 +1493,7 @@ def test_8_remove_obsolete_targets(self):
14931493
# The SimpleHTTPServer started in the setupclass has a tendency to
14941494
# timeout in Windows after a few tests.
14951495
SERVER_PORT = random.randint(30000, 45000)
1496-
command = ['python', '-m', 'tuf.scripts.simple_server', str(SERVER_PORT)]
1496+
command = ['python', '-m', 'tests.simple_server', str(SERVER_PORT)]
14971497
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
14981498

14991499
# NOTE: Following error is raised if a delay is not long enough to allow
@@ -1877,8 +1877,8 @@ def setUp(self):
18771877
self.SERVER_PORT = 30001
18781878
self.SERVER_PORT2 = 30002
18791879

1880-
command = ['python', '-m', 'tuf.scripts.simple_server', str(self.SERVER_PORT)]
1881-
command2 = ['python', '-m', 'tuf.scripts.simple_server', str(self.SERVER_PORT2)]
1880+
command = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT)]
1881+
command2 = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT2)]
18821882

18831883
self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE,
18841884
cwd=self.repository_directory)

tuf/scripts/simple_server.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)