2022-09-17 03:38:00 +00:00
|
|
|
import SharedWorkspaceLocking from '../../cli/shared-workspace-locking';
|
2022-09-17 04:09:36 +00:00
|
|
|
import { Cli } from '../../cli/cli';
|
2022-09-17 04:44:07 +00:00
|
|
|
import setups from './cloud-runner-suite.test';
|
2022-09-29 20:30:34 +00:00
|
|
|
import CloudRunnerLogger from '../services/cloud-runner-logger';
|
|
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2022-09-29 21:16:28 +00:00
|
|
|
import CloudRunnerOptions from '../cloud-runner-options';
|
2022-09-17 03:38:00 +00:00
|
|
|
|
2022-09-20 21:02:26 +00:00
|
|
|
describe('Cloud Runner Locking', () => {
|
2022-09-17 04:44:07 +00:00
|
|
|
setups();
|
2022-09-29 21:16:28 +00:00
|
|
|
it('Responds', () => {});
|
|
|
|
|
if (CloudRunnerOptions.cloudRunnerTests) {
|
|
|
|
|
it(`simple locking flow`, async () => {
|
|
|
|
|
Cli.options.retainWorkspaces = true;
|
|
|
|
|
const newWorkspaceName = `test-workspace-${uuidv4()}`;
|
|
|
|
|
const runId = uuidv4();
|
|
|
|
|
await SharedWorkspaceLocking.CreateLockableWorkspace(newWorkspaceName);
|
|
|
|
|
const isExpectedUnlockedBeforeLocking =
|
|
|
|
|
(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName)) === false;
|
|
|
|
|
expect(isExpectedUnlockedBeforeLocking).toBeTruthy();
|
|
|
|
|
await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId);
|
|
|
|
|
const isExpectedLockedAfterLocking = (await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName)) === true;
|
|
|
|
|
expect(isExpectedLockedAfterLocking).toBeTruthy();
|
|
|
|
|
const locksBeforeRelease = await SharedWorkspaceLocking.GetAllLocks(newWorkspaceName);
|
|
|
|
|
CloudRunnerLogger.log(JSON.stringify(locksBeforeRelease, undefined, 4));
|
|
|
|
|
expect(locksBeforeRelease.length > 1).toBeTruthy();
|
|
|
|
|
await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId);
|
|
|
|
|
const locks = await SharedWorkspaceLocking.GetAllLocks(newWorkspaceName);
|
|
|
|
|
expect(locks.length === 1).toBeTruthy();
|
|
|
|
|
const isExpectedLockedAfterReleasing =
|
|
|
|
|
(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName)) === false;
|
|
|
|
|
expect(isExpectedLockedAfterReleasing).toBeTruthy();
|
|
|
|
|
}, 150000);
|
|
|
|
|
it('Locking', async () => {
|
|
|
|
|
Cli.options.retainWorkspaces = true;
|
|
|
|
|
CloudRunnerLogger.log(`GetAllWorkspaces ${JSON.stringify(await SharedWorkspaceLocking.GetAllWorkspaces())}`);
|
|
|
|
|
CloudRunnerLogger.log(`GetFreeWorkspaces ${JSON.stringify(await SharedWorkspaceLocking.GetFreeWorkspaces())}`);
|
|
|
|
|
CloudRunnerLogger.log(
|
2022-10-04 22:12:56 +00:00
|
|
|
`IsWorkspaceLocked ${JSON.stringify(
|
|
|
|
|
await SharedWorkspaceLocking.IsWorkspaceLocked(`test-workspace-${uuidv4()}`),
|
|
|
|
|
)}`,
|
2022-09-29 21:16:28 +00:00
|
|
|
);
|
|
|
|
|
CloudRunnerLogger.log(`GetFreeWorkspaces ${JSON.stringify(await SharedWorkspaceLocking.GetFreeWorkspaces())}`);
|
|
|
|
|
CloudRunnerLogger.log(
|
2022-10-04 22:12:56 +00:00
|
|
|
`LockWorkspace ${JSON.stringify(
|
|
|
|
|
await SharedWorkspaceLocking.LockWorkspace(`test-workspace-${uuidv4()}`, uuidv4()),
|
|
|
|
|
)}`,
|
2022-09-29 21:16:28 +00:00
|
|
|
);
|
|
|
|
|
CloudRunnerLogger.log(
|
|
|
|
|
`CreateLockableWorkspace ${JSON.stringify(
|
2022-10-04 22:12:56 +00:00
|
|
|
await SharedWorkspaceLocking.CreateLockableWorkspace(`test-workspace-${uuidv4()}`),
|
2022-09-29 21:16:28 +00:00
|
|
|
)}`,
|
|
|
|
|
);
|
|
|
|
|
CloudRunnerLogger.log(
|
|
|
|
|
`GetLockedWorkspace ${JSON.stringify(
|
2022-10-04 22:12:56 +00:00
|
|
|
await SharedWorkspaceLocking.GetLockedWorkspace(`test-workspace-${uuidv4()}`, uuidv4()),
|
2022-09-29 21:16:28 +00:00
|
|
|
)}`,
|
|
|
|
|
);
|
|
|
|
|
}, 3000000);
|
|
|
|
|
}
|
2022-09-17 03:38:00 +00:00
|
|
|
});
|