Don't fail to start a WSLCSession if anonymous volumes are present (#40077)

* Don't fail to start a WSLCSession if anonymous volumes are present

* Typo

* Cleanup diff

* Cleanup diff
This commit is contained in:
Blue
2026-04-02 12:24:48 -07:00
committed by GitHub
parent 9ae92f2592
commit da5efafd45
7 changed files with 70 additions and 6 deletions

View File

@@ -1516,6 +1516,62 @@ class WSLCTests
VERIFY_ARE_EQUAL(E_ABORT, result.get_future().get());
}
TEST_METHOD(AnonymousVolumes)
{
// TODO: Add more test coverage once anonymous volumes are fully supported and switch to using -v instead of building an image.
WSL2_TEST_ONLY();
auto contextDir = std::filesystem::current_path() / "build-context";
std::filesystem::create_directories(contextDir);
auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() {
std::error_code ec;
std::filesystem::remove_all(contextDir, ec);
wil::unique_cotaskmem_array_ptr<WSLCDeletedImageInformation> deletedImages;
WSLCDeleteImageOptions deleteOptions{.Image = "wslc-test-build:latest", .Flags = WSLCDeleteImageFlagsForce};
LOG_IF_FAILED(m_defaultSession->DeleteImage(&deleteOptions, &deletedImages, deletedImages.size_address<ULONG>()));
});
{
std::ofstream dockerfile(contextDir / "Dockerfile");
dockerfile << "FROM debian:latest\n";
dockerfile << "VOLUME /volume\n"; // Use VOLUME to force the creation of an anonymous volume.
}
VERIFY_SUCCEEDED(BuildImageFromContext(contextDir, "wslc-test-build:latest"));
ExpectImagePresent(*m_defaultSession, "wslc-test-build:latest");
WSLCContainerLauncher launcher("wslc-test-build:latest", "wslc-test-anonymous-volume", {"test", "-d", "/volume"});
auto container = launcher.Launch(*m_defaultSession);
auto result = container.GetInitProcess();
auto containerId = container.Id();
ValidateProcessOutput(result, {});
ResetTestSession();
container.SetDeleteOnClose(false);
// Manually cleanup the container since the session has been reset.
auto containerCleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() {
wil::com_ptr<IWSLCContainer> container;
VERIFY_SUCCEEDED(m_defaultSession->OpenContainer(containerId.c_str(), &container));
VERIFY_SUCCEEDED(container->Delete(WSLCDeleteFlagsForce));
});
// Validate that the session is correctly restarted.
wil::unique_cotaskmem_array_ptr<WSLCContainerEntry> containers;
wil::unique_cotaskmem_array_ptr<WSLCContainerPortMapping> ports;
VERIFY_SUCCEEDED(m_defaultSession->ListContainers(&containers, containers.size_address<ULONG>(), &ports, ports.size_address<ULONG>()));
VERIFY_ARE_EQUAL(containers.size(), 1);
VERIFY_ARE_EQUAL(containers[0].Id, containerId);
}
TEST_METHOD(TagImage)
{
WSL2_TEST_ONLY();