golemfactory / clay

Golem is creating a global market for computing power.
https://golem.network
GNU General Public License v3.0
2.91k stars 284 forks source link

Not properly mocking PaymentProcessor #2729

Closed etam closed 6 years ago

etam commented 6 years ago
self = <tests.golem.test_client.TestClient testMethod=test_restart_task>
    def tearDown(self):
        if hasattr(self, 'client'):
            self.client.quit()
>       super().tearDown()
tests\golem\test_client.py:88: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
golem\testutils.py:130: in tearDown
    super(DatabaseFixture, self).tearDown()
golem\testutils.py:76: in tearDown
    self.__remove_files()
golem\testutils.py:117: in __remove_files
    shutil.rmtree(self.tempdir)
C:\Python36\lib\shutil.py:494: in rmtree
    return _rmtree_unsafe(path, onerror)
C:\Python36\lib\shutil.py:389: in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
path = 'C:\\Users\\buildbot-worker\\AppData\\Local\\Temp\\golem-tests-t3z73szq\\test_restart_task67qo1kfp'
onerror = <function rmtree.<locals>.onerror at 0x0000025A96553488>
    def _rmtree_unsafe(path, onerror):
        try:
            if os.path.islink(path):
                # symlinks to directories are forbidden, see bug #1669
                raise OSError("Cannot call rmtree on a symbolic link")
        except OSError:
            onerror(os.path.islink, path, sys.exc_info())
            # can't continue even if onerror hook returns
            return
        names = []
        try:
            names = os.listdir(path)
        except OSError:
            onerror(os.listdir, path, sys.exc_info())
        for name in names:
            fullname = os.path.join(path, name)
            try:
                mode = os.lstat(fullname).st_mode
            except OSError:
                mode = 0
            if stat.S_ISDIR(mode):
                _rmtree_unsafe(fullname, onerror)
            else:
                try:
>                   os.unlink(fullname)
E                   PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\buildbot-worker\\AppData\\Local\\Temp\\golem-tests-t3z73szq\\test_restart_task67qo1kfp\\golem.db'

This might be related:

_____ TestKeysAuthWithReactor.test_generate_keys_stop_when_reactor_stopped _____
self = <tests.golem.core.test_keysauth.TestKeysAuthWithReactor testMethod=test_generate_keys_stop_when_reactor_stopped>
logger = <MagicMock name='logger' id='139869773798928'>
    @patch('golem.core.keysauth.logger')
    def test_generate_keys_stop_when_reactor_stopped(self, logger):
        # given
        from twisted.internet import threads
        reactor = self._get_reactor()

        # when
        threads.deferToThread(KeysAuth._generate_keys, difficulty=200)

        time.sleep(0.01)
        reactor.stop()
        time.sleep(0.01)

        # then
        assert not reactor.running
        assert logger.info.call_count == 1
        assert logger.info.call_args_list[0][0][0] == 'Generating new key pair'
>       assert logger.warning.call_count == 1
E       AssertionError: assert 0 == 1
E        +  where 0 = <MagicMock name='logger.warning' id='139869774039976'>.call_count
E        +    where <MagicMock name='logger.warning' id='139869774039976'> = <MagicMock name='logger' id='139869773798928'>.warning
etam commented 6 years ago

Ok, this seems to be related to a change I did (it's is my branch, not merged yet), which seems reasonable:

modified   golem/report.py
@@ -78,7 +77,7 @@ def done_deferred(return_value=None):
 )
 @patch('signal.signal')
 @patch('golem.network.p2p.node.Node.collect_network_info')
-class TestClient(TestWithDatabase, TestWithReactor):
+class TestClient(TestDatabaseWithReactor):
     # FIXME: if we someday decide to run parallel tests,
     # this may completely break. Issue #2456
     # pylint: disable=attribute-defined-outside-init
@@ -86,6 +85,7 @@ class TestClient(TestWithDatabase, TestWithReactor):
     def tearDown(self):
         if hasattr(self, 'client'):
             self.client.quit()
+        super().tearDown()

     def test_get_payments(self, *_):
         self.client = Client(
@@ -917,11 +917,11 @@ def make_mock_payment_processor(sci, eth=100, gnt=100):

 @patch('signal.signal')
 @patch('golem.network.p2p.node.Node.collect_network_info')
-class TestClientRPCMethods(TestWithDatabase, LogTestCase):
+class TestClientRPCMethods(TestDatabaseWithReactor, LogTestCase):
     def setUp(self):
-        super(TestClientRPCMethods, self).setUp()
+        super().setUp()
         with patch('golem.network.concent.handlers_library.HandlersLibrary'
                    '.register_handler', ):
             apps_manager = AppsManager(False)
@@ -955,6 +955,7 @@ class TestClientRPCMethods(TestWithDatabase, LogTestCase):

     def tearDown(self):
         self.client.quit()
+        super().tearDown()

     def test_node(self, *_):
         c = self.client