Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/cloud-hypervisor-runtime-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
createCloudHypervisorRuntimeBackend,
type CloudHypervisorRuntimeBackendDependencies,
} from './cloud-hypervisor-runtime-backend';
import {
createCloudHypervisorRuntimeBackend as createCloudHypervisorRuntimeBackendFromModule,
} from './cloud-hypervisor/runtime-backend';
import {
cloudHypervisorHostTools,
createCloudHypervisorInfrastructureSnapshot as infrastructure,
Expand Down Expand Up @@ -186,6 +189,8 @@ describe('Cloud Hypervisor runtime backend', () => {
)).toBeDefined();
expect(createCloudHypervisorRuntimeBackend(config(), startInfrastructure))
.toEqual(expect.objectContaining({ runtime: 'cloud-hypervisor' }));
expect(createCloudHypervisorRuntimeBackendFromModule(config(), startInfrastructure))
.toEqual(expect.objectContaining({ runtime: 'cloud-hypervisor' }));
} finally {
if (previousWorkspace === undefined) delete process.env.GITHUB_WORKSPACE;
else process.env.GITHUB_WORKSPACE = previousWorkspace;
Expand Down Expand Up @@ -952,6 +957,27 @@ describe('Cloud Hypervisor runtime backend', () => {
);
});

it('stops the in-flight microVM when cleanup races an unfinished boot', async () => {
const { manager, deps } = harness();
let releaseBoot!: () => void;
manager.startInstance.mockImplementationOnce(
() => new Promise<void>((resolve) => { releaseBoot = () => resolve(); }),
);
const backend = createBackend(config(), deps);
const startup = backend.start('/tmp/awf', ['github.com']);
while (manager.startInstance.mock.calls.length === 0) {
await new Promise<void>((resolve) => setImmediate(resolve));
}

await backend.stop();
expect(manager.stop).toHaveBeenCalledWith({ preserve: false });
expect(deps.removeArtifactSnapshot).toHaveBeenCalledWith('/snapshot');

releaseBoot();
await expect(startup).rejects.toThrow(/aborted by shutdown/);
expect(manager.stop).toHaveBeenCalledTimes(1);
});

it('cancels an active guest command before stopping', async () => {
const { manager, deps } = harness();
const resolveExecution = mockNetworkReadyProbeSequence(manager);
Expand Down
Loading
Loading