From fe8313c2f7408573e7e3df5bfbd6963699feacee Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Fri, 5 Jan 2024 22:22:14 +0000 Subject: [PATCH] [tests] Check null head after capture failure --- tests/test_base_virtual_machine.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_base_virtual_machine.cpp b/tests/test_base_virtual_machine.cpp index 615b75d3b16..ef22018864d 100644 --- a/tests/test_base_virtual_machine.cpp +++ b/tests/test_base_virtual_machine.cpp @@ -940,4 +940,17 @@ TEST_F(BaseVM, snapshotDeletionKeepsHeadOnFailure) EXPECT_EQ(vm.take_snapshot(specs, "", "")->get_parent().get(), snapshot_album[1].get()); } +TEST_F(BaseVM, takeSnapshotRevertsToNullHeadOnFirstFailure) +{ + auto snapshot = std::make_shared>(); + EXPECT_CALL(*snapshot, capture).WillOnce(Throw(std::runtime_error{"intentional"})); + EXPECT_CALL(vm, make_specific_snapshot(_, _, _, _)).WillOnce(Return(snapshot)).RetiresOnSaturation(); + + mp::VMSpecs specs{}; + EXPECT_ANY_THROW(vm.take_snapshot(specs, "", "")); + + mock_snapshotting(); + EXPECT_EQ(vm.take_snapshot(specs, "", "")->get_parent().get(), nullptr); +} + } // namespace