Skip to content

Commit 3b5f5e1

Browse files
committed
Fix ResourceWarning when running tests
supervisor/supervisor/http.py:581: ResourceWarning: unclosed <socket.socket fd=14, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0> used = self.checkused(socketname) ResourceWarning: Enable tracemalloc to get the object allocation traceback Unlinking stale socket /var/folders/4l/30_vf63152bflw8hnvyvnw_00000gn/T/tmpbpxj02zu In 1849019, uses of tempfile.mktemp() were replaced with tempfile.NamedTemporaryFile(). Some tests did not run as intended afterward because they expected the file to not exist on disk.
1 parent e3c3ff9 commit 3b5f5e1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

supervisor/tests/test_http.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,10 @@ def test_make_http_servers_socket_type_error(self):
620620
self.assertEqual(exc.args[0], 'Cannot determine socket type 999')
621621

622622
def test_make_http_servers_noauth(self):
623-
with tempfile.NamedTemporaryFile(delete=False) as f:
623+
with tempfile.NamedTemporaryFile(delete=True) as f:
624624
socketfile = f.name
625+
self.assertFalse(os.path.exists(socketfile))
626+
625627
inet = {'family':socket.AF_INET, 'host':'localhost', 'port':17735,
626628
'username':None, 'password':None, 'section':'inet_http_server'}
627629
unix = {'family':socket.AF_UNIX, 'file':socketfile, 'chmod':0o700,
@@ -648,8 +650,10 @@ def test_make_http_servers_noauth(self):
648650
self.assertEqual([x.IDENT for x in server.handlers], idents)
649651

650652
def test_make_http_servers_withauth(self):
651-
with tempfile.NamedTemporaryFile(delete=False) as f:
653+
with tempfile.NamedTemporaryFile(delete=True) as f:
652654
socketfile = f.name
655+
self.assertFalse(os.path.exists(socketfile))
656+
653657
inet = {'family':socket.AF_INET, 'host':'localhost', 'port':17736,
654658
'username':'username', 'password':'password',
655659
'section':'inet_http_server'}

supervisor/tests/test_options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,10 @@ def test_reopenlogs(self):
16411641
self.assertEqual(logger.data[0], 'supervisord logreopen')
16421642

16431643
def test_write_pidfile_ok(self):
1644-
with tempfile.NamedTemporaryFile(delete=False) as f:
1644+
with tempfile.NamedTemporaryFile(delete=True) as f:
16451645
fn = f.name
1646+
self.assertFalse(os.path.exists(fn))
1647+
16461648
try:
16471649
instance = self._makeOne()
16481650
instance.logger = DummyLogger()

0 commit comments

Comments
 (0)