'Test worker creation on race condition.
Test that we still create an entry if there is a rare race condition
that the entry gets removed from the DB between our failure to create
it and our try to update the entry.'

@mock.patch('cinder.db.worker_update', autospec=True)
@mock.patch('cinder.db.worker_create', autospec=True)
def test_create_worker_cleaning(self, mock_create, mock_update):

    rpc.LAST_OBJ_VERSIONS[Backup.get_rpc_api().BINARY] = '1.3'
    mock_create.side_effect = [exception.WorkerExists(type='type', id='id'), mock.sentinel.worker]
    mock_update.side_effect = exception.WorkerNotFound
    backup = Backup(_context=self.context, status='cleanable', id=mock.sentinel.id)
    self.assertTrue(backup.create_worker())
    self.assertEqual(2, mock_create.call_count)
    self.assertTrue(mock_update.called)
