Sometimes, the test suite fails with a AssertionError: No matching class found for... error

Bug #1238498 reported by Guewen Baconnier @ Camptocamp
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenERP Connector
Fix Released
Undecided
Unassigned

Bug Description

Steps to reproduce:

Launch the test suite of the 'connector' module.
I'm using the buildout, so that's bin/rununittests -m connector
Most of the times, it's all green, but sometimes I an error like the following on some tests:

======================================================================
FAIL: test_get_class_replacing_module (openerp.addons.connector.tests.test_backend.test_backend_register)
Returns the replacing ConnectorUnit
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gbaconnier/code/dev_instances/openerp_magento7/parts/connector/connector/tests/test_backend.py", line 155, in test_get_class_replacing_module
    'res.users')
  File "/home/gbaconnier/code/dev_instances/openerp_magento7/parts/connector/connector/backend.py", line 263, in get_class
    (base_class, session, model_name))
AssertionError: No matching class found for <class 'openerp.addons.connector.tests.test_backend.LambdaUnit'> with session: <Session db_name: openerp_magento7, uid: 1>, model name: res.users

This seems to be related to the initialization of the registry, which does not populate it with the models.

I couldn't find the exact cause, but it occurs in the WorkerWatcher, because it starts probably before OpenERP could finish the initialization of the registry.

In the code below, the line "dbworker_obj = session.pool.get('queue.worker')" provoke the error, and we get a registry without any models.

    def check_alive(self, db_name, worker):
        """ Check if the the worker is still alive and notify
        its aliveness.
        Check if the other workers are still alive, if they are
        dead, remove them from the worker's pool.
        """
        session_hdl = ConnectorSessionHandler(db_name,
                                              openerp.SUPERUSER_ID)
        with session_hdl.session() as session:
            if worker.is_alive():
                self._notify_alive(session, worker)
                session.commit()
            self._purge_dead_workers(session)
            session.commit()

    def _notify_alive(self, session, worker):
        _logger.debug('Worker %s is alive on process %s',
                      worker.uuid, os.getpid())
        dbworker_obj = session.pool.get('queue.worker')
        # at startup (especially when running tests),
        # registry is not yet initialized, so we just skip
        # the notify in such case
        if not dbworker_obj:
            return
        dbworker_obj._notify_alive(session.cr,
                                   session.uid,
                                   worker,
                                   context=session.context)

If I put a delay before the start of the WorkerWatcher, the error does no longer appears, but that's not a correct solution though.

Changed in openerp-connector:
status: New → Confirmed
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Here is the cause of the bug: https://bugs.launchpad.net/openobject-server/+bug/1238560
And my proposal: https://code.launchpad.net/~camptocamp/openobject-server/7.0-registrymanager-rlock-1238560-gbr/+merge/190570

Note that once fixed, we can safely remove the lines:

        # at startup (especially when running tests),
        # registry is not yet initialized, so we just skip
        # the notify in such case
        if not dbworker_obj:
            return

description: updated
information type: Embargoed → Public
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Solved by:

https://bugs.launchpad.net/openobject-addons/+bug/1238560

I keep the bug open until we resolve my comment #1

Changed in openerp-connector:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.