Merge "Fix race condition with enabling SG on many ports at once"

This commit is contained in:
Zuul 2018-01-27 10:36:37 +00:00 committed by Gerrit Code Review
commit a34b61f0c2
2 changed files with 18 additions and 1 deletions

View File

@ -80,7 +80,7 @@ class RemoteResourceCache(object):
# been updated already and pushed to us in another thread.
LOG.debug("Ignoring stale update for %s: %s", rtype, resource)
continue
self._type_cache(rtype)[resource.id] = resource
self.record_resource_update(context, rtype, resource)
LOG.debug("%s resources returned for queries %s", len(resources),
query_ids)
self._satisfied_server_queries.update(query_ids)

View File

@ -55,22 +55,39 @@ class RemoteResourceCacheTestCase(base.BaseTestCase):
self.assertIsNone(self.rcache.get_resource_by_id('goose', 2))
def test__flood_cache_for_query_pulls_once(self):
resources = [OVOLikeThing(66), OVOLikeThing(67)]
received_kw = []
receiver = lambda *a, **k: received_kw.append(k)
registry.subscribe(receiver, 'goose', events.AFTER_UPDATE)
self._pullmock.bulk_pull.side_effect = [
resources,
[resources[0]],
[resources[1]],
[resources[1]]
]
self.rcache._flood_cache_for_query('goose', id=(66, 67),
name=('a', 'b'))
self._pullmock.bulk_pull.assert_called_once_with(
mock.ANY, 'goose',
filter_kwargs={'id': (66, 67), 'name': ('a', 'b')})
self._pullmock.bulk_pull.reset_mock()
self.rcache._flood_cache_for_query('goose', id=(66, ), name=('a', ))
self.assertFalse(self._pullmock.called)
self.rcache._flood_cache_for_query('goose', id=(67, ), name=('b', ))
self.assertFalse(self._pullmock.called)
# querying by just ID should trigger a new call since ID+name is a more
# specific query
self.rcache._flood_cache_for_query('goose', id=(67, ))
self._pullmock.bulk_pull.assert_called_once_with(
mock.ANY, 'goose', filter_kwargs={'id': (67, )})
self.assertItemsEqual(
resources, [rec['updated'] for rec in received_kw])
def test_bulk_pull_doesnt_wipe_out_newer_data(self):
self.rcache.record_resource_update(
self.ctx, 'goose', OVOLikeThing(1, revision_number=5))