@@ -118,6 +118,8 @@ struct Daemon : public mpt::DaemonTestFixture
118118 EXPECT_CALL (mock_platform, multipass_storage_location ()).Times (AnyNumber ()).WillRepeatedly (Return (QString ()));
119119 EXPECT_CALL (mock_platform, create_alias_script (_, _)).WillRepeatedly (Return ());
120120 EXPECT_CALL (mock_platform, remove_alias_script (_)).WillRepeatedly (Return ());
121+ EXPECT_CALL (mock_platform, setup_permission_inheritance (_)).Times (AnyNumber ()).WillRepeatedly (Return ());
122+ EXPECT_CALL (mock_platform, bridge_nomenclature).Times (AnyNumber ()).WillRepeatedly (Return (" notabridge" ));
121123 }
122124
123125 void SetUp () override
@@ -356,6 +358,59 @@ TEST_F(Daemon, blueprintsURLOverrideIsCorrect)
356358 EXPECT_EQ (downloader->downloaded_urls .front (), QUrl::fromLocalFile (test_blueprints_zip).toString ());
357359}
358360
361+ TEST_F (Daemon, ensure_that_on_restart_future_completes)
362+ {
363+ auto mock_factory = use_a_mock_vm_factory ();
364+
365+ constexpr auto instance_json = R"( {
366+ "yakety-yak": {
367+ "deleted": false,
368+ "disk_space": "3232323232",
369+ "mac_addr": "ab:cd:ef:12:34:56",
370+ "mem_size": "2323232323",
371+ "metadata": {},
372+ "mounts": [],
373+ "num_cores": 4,
374+ "ssh_username": "ubuntu",
375+ "state": 4
376+ }
377+ })" ;
378+ const auto [temp_dir, _] = plant_instance_json (instance_json);
379+ config_builder.data_directory = temp_dir->path ();
380+ config_builder.vault = std::make_unique<NiceMock<mpt::MockVMImageVault>>();
381+
382+ // This VM was running before, but not now.
383+ auto mock_vm = std::make_unique<NiceMock<mpt::MockVirtualMachine>>(" yakety-yak" );
384+ EXPECT_CALL (*mock_vm, current_state)
385+ .WillOnce (Return (mp::VirtualMachine::State::stopped))
386+ .WillOnce (Return (mp::VirtualMachine::State::stopped));
387+ EXPECT_CALL (*mock_vm, start).Times (1 );
388+
389+ std::mutex mtx;
390+ std::condition_variable cv;
391+ bool ready = false ;
392+ // update_state is called by the finished() handler of the future. If it's called, then
393+ // everything's ok.
394+ EXPECT_CALL (*mock_vm, update_state).WillOnce ([&cv, &mtx, &ready] {
395+ // Ensure that update_state is delayed until daemon's destructor call.
396+ std::unique_lock lock (mtx);
397+ cv.wait (lock, [&] { return ready; });
398+ // Wait a bit to ensure that daemon's destructor has been run
399+ std::this_thread::sleep_for (std::chrono::milliseconds{50 });
400+ });
401+ EXPECT_CALL (*mock_vm, wait_until_ssh_up).Times (1 );
402+ EXPECT_CALL (*mock_factory, create_virtual_machine).WillOnce (Return (std::move (mock_vm)));
403+
404+ {
405+ mp::Daemon daemon{config_builder.build ()};
406+ {
407+ std::lock_guard lock (mtx);
408+ ready = true ;
409+ }
410+ cv.notify_one ();
411+ }
412+ }
413+
359414namespace
360415{
361416struct DaemonCreateLaunchTestSuite : public Daemon , public WithParamInterface <std::string>
@@ -2378,6 +2433,12 @@ struct DaemonIsBridged : public Daemon,
23782433 public WithParamInterface<
23792434 std::tuple<std::vector<mp::NetworkInterfaceInfo>, std::vector<mp::NetworkInterface>, bool >>
23802435{
2436+ DaemonIsBridged ()
2437+ {
2438+ EXPECT_CALL (mock_platform, bridge_nomenclature)
2439+ .Times (AnyNumber ())
2440+ .WillRepeatedly (Return (" this is not a bridge" ));
2441+ }
23812442};
23822443
23832444TEST_P (DaemonIsBridged, is_bridged_works)
0 commit comments