SynchronousThreadPoolExecutorFixture mock spec does not work

Bug #1823278 reported by melanie witt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
melanie witt

Bug Description

The fixture's fake submit() method returns a mocked future that is intended to be a Mock with spec=futurist.Future but the speccing doesn't work because the spec is passed a string when it needs to be a class or an instance. Because of the bug, code like this:

  self.useFixture(fixtures.SynchronousThreadPoolExecutorFixture())
  executor = futurist.GreenThreadPoolExecutor()
  future = executor.submit(...)
  result = future.result()

raises the following error:

  AttributeError: Mock object has no attribute 'result'

The mock spec just needs to be changed from a string to a class or instance.

Tags: testing
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/650171

Changed in nova:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.opendev.org/650171
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=87b7f0c2aff153eecd8bdf3cb5503287d0e77a24
Submitter: Zuul
Branch: master

commit 87b7f0c2aff153eecd8bdf3cb5503287d0e77a24
Author: melanie witt <email address hidden>
Date: Fri Apr 5 01:24:23 2019 +0000

    Fix SynchronousThreadPoolExecutorFixture mock of Future

    The fixture is not mocking the Future.result() method correctly and an
    attempt to access it results in the following error:

      AttributeError: Mock object has no attribute 'result'

    Instead of mocking the submit() method, we can just swap out the
    GreenThreadPoolExecutor for the SynchronousExecutor to make the
    executor synchronous for testing.

    A few changes were also needed in unit tests that are running with the
    thread pool executor. Because the thread pool executor is created in
    the compute manager's __init__ method, we need to patch the synchronous
    executor in before calling the base test class's setUp method. Next, a
    couple of unit tests were asserting that an exception would be raised
    from the thread pool executor's submit() method but that will not
    happen because if an exception is raised during a submitted task, that
    exception will not be raised until Future.result() is called. And
    Future.result() is never called in the compute manager.

    Closes-Bug: #1823278

    Change-Id: I719c222a5fa3d654e7397f126a1338e653b7bbcc

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 20.0.0.0rc1

This issue was fixed in the openstack/nova 20.0.0.0rc1 release candidate.

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.