Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix test_socket_manager.py with PyPy #1679

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions supervisor/tests/test_socket_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test suite for supervisor.socket_manager"""

import gc
import os
import unittest
import socket
Expand Down Expand Up @@ -49,6 +50,7 @@ def test_on_delete(self):
proxy = self._makeOne(Subject(), on_delete=self.setOnDeleteCalled)
self.assertEqual(5, proxy.getValue())
proxy = None
gc_collect()
self.assertTrue(self.on_deleteCalled)

class ReferenceCounterTest(unittest.TestCase):
Expand Down Expand Up @@ -91,6 +93,9 @@ def test_decr_at_zero_raises_error(self):

class SocketManagerTest(unittest.TestCase):

def tearDown(self):
gc_collect()

def _getTargetClass(self):
from supervisor.socket_manager import SocketManager
return SocketManager
Expand Down Expand Up @@ -154,10 +159,12 @@ def test_socket_lifecycle(self):
self.assertTrue(sock_manager.is_prepared())
self.assertFalse(sock_manager.socket.close_called)
sock = None
gc_collect()
# Socket not actually closed yet b/c ref ct is 1
self.assertTrue(sock_manager.is_prepared())
self.assertFalse(sock_manager.socket.close_called)
sock2 = None
gc_collect()
# Socket closed
self.assertFalse(sock_manager.is_prepared())
self.assertTrue(sock_manager.socket.close_called)
Expand All @@ -170,6 +177,7 @@ def test_socket_lifecycle(self):
self.assertNotEqual(sock_id, sock3_id)
# Drop ref ct to zero
del sock3
gc_collect()
# Now assert that socket is closed
self.assertFalse(sock_manager.is_prepared())
self.assertTrue(sock_manager.socket.close_called)
Expand All @@ -184,6 +192,7 @@ def test_logging(self):
self.assertEqual('Creating socket %s' % repr(conf), logger.data[0])
# socket close
del sock
gc_collect()
self.assertEqual(len(logger.data), 2)
self.assertEqual('Closing socket %s' % repr(conf), logger.data[1])

Expand Down Expand Up @@ -232,3 +241,9 @@ def test_close_requires_prepared_socket(self):
self.fail()
except Exception as e:
self.assertEqual(e.args[0], 'Socket has not been prepared')

def gc_collect():
if __pypy__ is not None:
gc.collect()
gc.collect()
gc.collect()
Loading