Skip to content

Commit dae1a1b

Browse files
committed
Fix [Errno 111] Connection refused
Fixes issue: #1010 When running the tests this error appears "[Errno 111] Connection refused". After some digging Lukas found another error "No module named tests.simple_server" which is the root case for error 111. With the help of Joshua Lock, we found out that the simple_server.py was not being found because subprocess.Popen was being passed a cwd kwarg which moved the current working directory away from tuf/tests. Signed-off-by: Martin Vrachev <[email protected]>
1 parent 808ac0c commit dae1a1b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

tests/test_multiple_repositories_integration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ 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', 'tests.simple_server', str(self.SERVER_PORT)]
132-
command2 = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT2)]
131+
# Needed because in some tests simple_server.py cannot be found.
132+
# The reason is that the current working directory
133+
# has been changed when executing a subprocess.
134+
SIMPLE_SERVER_PATH = os.path.join(os.getcwd(), 'simple_server.py')
135+
136+
command = ['python', SIMPLE_SERVER_PATH, str(self.SERVER_PORT)]
137+
command2 = ['python', SIMPLE_SERVER_PATH, str(self.SERVER_PORT2)]
133138

134139
self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE,
135140
cwd=self.repository_directory)

tests/test_updater.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def setUpClass(cls):
9090
# temporary files are always removed, even when exceptions occur.
9191
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())
9292

93+
# Needed because in some tests simple_server.py cannot be found.
94+
# The reason is that the current working directory
95+
# has been changed when executing a subprocess.
96+
cls.SIMPLE_SERVER_PATH = os.path.join(os.getcwd(), 'simple_server.py')
97+
9398
# Launch a SimpleHTTPServer (serves files in the current directory).
9499
# Test cases will request metadata and target files that have been
95100
# pre-generated in 'tuf/tests/repository_data', which will be served
@@ -98,7 +103,7 @@ def setUpClass(cls):
98103
# as a delegated role 'targets/role1', three target files, five key files,
99104
# etc.
100105
cls.SERVER_PORT = random.randint(30000, 45000)
101-
command = ['python', '-m', 'tests.simple_server', str(cls.SERVER_PORT)]
106+
command = ['python', cls.SIMPLE_SERVER_PATH, str(cls.SERVER_PORT)]
102107
cls.server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
103108
logger.info('\n\tServer process started.')
104109
logger.info('\tServer process id: '+str(cls.server_process.pid))
@@ -1091,7 +1096,7 @@ def test_6_get_one_valid_targetinfo(self):
10911096
# The SimpleHTTPServer started in the setupclass has a tendency to
10921097
# timeout in Windows after a few tests.
10931098
SERVER_PORT = random.randint(30000, 45000)
1094-
command = ['python', '-m', 'tests.simple_server', str(SERVER_PORT)]
1099+
command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)]
10951100
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
10961101

10971102
# NOTE: Following error is raised if a delay is not long enough:
@@ -1359,7 +1364,7 @@ def test_7_updated_targets(self):
13591364
# The SimpleHTTPServer started in the setupclass has a tendency to
13601365
# timeout in Windows after a few tests.
13611366
SERVER_PORT = random.randint(30000, 45000)
1362-
command = ['python', '-m', 'tests.simple_server', str(SERVER_PORT)]
1367+
command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)]
13631368
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
13641369

13651370
# NOTE: Following error is raised if a delay is not long enough to allow
@@ -1491,7 +1496,7 @@ def test_8_remove_obsolete_targets(self):
14911496
# The SimpleHTTPServer started in the setupclass has a tendency to
14921497
# timeout in Windows after a few tests.
14931498
SERVER_PORT = random.randint(30000, 45000)
1494-
command = ['python', '-m', 'tests.simple_server', str(SERVER_PORT)]
1499+
command = ['python', self.SIMPLE_SERVER_PATH, str(SERVER_PORT)]
14951500
server_process = subprocess.Popen(command, stderr=subprocess.PIPE)
14961501

14971502
# NOTE: Following error is raised if a delay is not long enough to allow
@@ -1824,6 +1829,11 @@ def setUp(self):
18241829
self.temporary_repository_root = self.make_temp_directory(directory=
18251830
self.temporary_directory)
18261831

1832+
# Needed because in some tests simple_server.py cannot be found.
1833+
# The reason is that the current working directory
1834+
# has been changed when executing a subprocess.
1835+
self.SIMPLE_SERVER_PATH = os.path.join(os.getcwd(), 'simple_server.py')
1836+
18271837
# The original repository, keystore, and client directories will be copied
18281838
# for each test case.
18291839
original_repository = os.path.join(original_repository_files, 'repository')
@@ -1875,8 +1885,8 @@ def setUp(self):
18751885
self.SERVER_PORT = 30001
18761886
self.SERVER_PORT2 = 30002
18771887

1878-
command = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT)]
1879-
command2 = ['python', '-m', 'tests.simple_server', str(self.SERVER_PORT2)]
1888+
command = ['python', self.SIMPLE_SERVER_PATH, str(self.SERVER_PORT)]
1889+
command2 = ['python', self.SIMPLE_SERVER_PATH, str(self.SERVER_PORT2)]
18801890

18811891
self.server_process = subprocess.Popen(command, stderr=subprocess.PIPE,
18821892
cwd=self.repository_directory)

0 commit comments

Comments
 (0)