'Verify that if every call to the :class:`GCEOperations` is
duplicated that we handle the errors correctly.
This should force some specific scheduling situations that resemble
race conditions with another agent trying to converge to the same
state, or a condition where the dataset agent as rebooted after a crash
that happened in the middle of an :class:`IBlockDeviceAPI` call.
In these situations we should verify that the second call to many of
the underlying atomic methods would result in the correct underlying
:class:`VolumeException`.'

def test_duplicated_calls(self):

    actual_api = gceblockdeviceapi_for_test(self)
    operations = actual_api._operations
    api = actual_api.set('_operations', repeat_call_proxy_for(IGCEOperations, operations))
    dataset_id = uuid4()
    self.assertThat((lambda : api.create_volume(dataset_id=dataset_id, size=get_minimum_allocatable_size())), Raises(MatchesException(GCEVolumeException)))
    volumes = api.list_volumes()
    self.assertThat(volumes, AnyMatch(MatchesStructure(dataset_id=Equals(dataset_id))))
    volume = next((v for v in volumes if (v.dataset_id == dataset_id)))
    compute_instance_id = api.compute_instance_id()
    self.assertThat((lambda : api.attach_volume(blockdevice_id=volume.blockdevice_id, attach_to=compute_instance_id)), Raises(MatchesException(AlreadyAttachedVolume)))
    self.assertThat(api.get_device_path(volume.blockdevice_id).path, Contains('/dev/sd'))
    api.detach_volume(blockdevice_id=volume.blockdevice_id)
    self.assertThat((lambda : api.destroy_volume(blockdevice_id=volume.blockdevice_id)), Raises(MatchesException(UnknownVolume)))
    self.assertThat(api.list_volumes(), AllMatch(Not(MatchesStructure(dataset_id=Equals(dataset_id)))))
