'Test for race conditions on num_of_mapped_volumes.
This test confirms that num_of_mapped_volumes won\'t break even if we
receive a NotFound exception when retrieving info on a specific
mapping, as that specific mapping could have been deleted between
the request to get the list of exiting mappings and the request to get
the info on one of them.'

def test_race_on_terminate_connection(self, req):

    req.side_effect = xms_request
    self.driver.client = xtremio.XtremIOClient3(self.config, self.config.xtremio_cluster_name)
    original_method = self.driver.client.num_of_mapped_volumes
    def fake_num_of_mapped_volumes(*args, **kwargs):
        mappings = [{'href': 'volumes/1'}, {'href': 'volumes/12'}]
        side_effect = [{'lun-maps': mappings}, {'content': xms_data['lun-maps'][1]}, exception.NotFound]
        with mock.patch.object(self.driver.client, 'req', side_effect=side_effect):
            return original_method(*args, **kwargs)
    self.driver.create_volume(self.data.test_volume)
    map_data = self.driver.initialize_connection(self.data.test_volume, self.data.connector)
    self.assertEqual(1, map_data['data']['target_lun'])
    with mock.patch.object(self.driver.client, 'num_of_mapped_volumes', side_effect=fake_num_of_mapped_volumes):
        self.driver.terminate_connection(self.data.test_volume, self.data.connector)
    self.driver.delete_volume(self.data.test_volume)
