From 8df0845e438ac8db3adb77e29d82b9446dcdf3ff Mon Sep 17 00:00:00 2001 From: Frostebite Date: Mon, 20 Mar 2023 01:15:56 +0000 Subject: [PATCH] shorter names --- .../tests/cloud-runner-locking-upsert.test.ts | 169 ++++++++++++++++++ .../tests/cloud-runner-locking.test.ts | 151 +--------------- .../e2e/cloud-runner-end2end-locking.test.ts | 2 +- .../cloud-runner-end2end-retaining.test.ts | 2 +- 4 files changed, 174 insertions(+), 150 deletions(-) create mode 100644 src/model/cloud-runner/tests/cloud-runner-locking-upsert.test.ts diff --git a/src/model/cloud-runner/tests/cloud-runner-locking-upsert.test.ts b/src/model/cloud-runner/tests/cloud-runner-locking-upsert.test.ts new file mode 100644 index 00000000..f1daadf8 --- /dev/null +++ b/src/model/cloud-runner/tests/cloud-runner-locking-upsert.test.ts @@ -0,0 +1,169 @@ +import SharedWorkspaceLocking from '../services/shared-workspace-locking'; +import { Cli } from '../../cli/cli'; +import setups from './cloud-runner-suite.test'; +import CloudRunnerLogger from '../services/cloud-runner-logger'; +import { v4 as uuidv4 } from 'uuid'; +import CloudRunnerOptions from '../cloud-runner-options'; +import UnityVersioning from '../../unity-versioning'; +import BuildParameters from '../../build-parameters'; +import CloudRunner from '../cloud-runner'; + +async function CreateParameters(overrides: any) { + if (overrides) { + Cli.options = overrides; + } + + return await BuildParameters.create(); +} + +describe('Cloud Runner Locking Upsert', () => { + setups(); + it('Responds', () => {}); + if (CloudRunnerOptions.cloudRunnerDebug) { + it(`Get Or Create From No Workspace`, async () => { + const overrides: any = { + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), + targetPlatform: 'StandaloneLinux64', + cacheKey: `test-case-${uuidv4()}`, + maxRetainedWorkspaces: 3, + }; + const buildParameters = await CreateParameters(overrides); + + const newWorkspaceName = `test-workspace-${uuidv4()}`; + const runId = uuidv4(); + CloudRunner.buildParameters = buildParameters; + expect( + await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId, buildParameters), + ).toBeTruthy(); + }, 150000); + it(`Get Or Create From Unlocked`, async () => { + const overrides: any = { + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), + targetPlatform: 'StandaloneLinux64', + cacheKey: `test-case-${uuidv4()}`, + maxRetainedWorkspaces: 3, + }; + const buildParameters = await CreateParameters(overrides); + + const newWorkspaceName = `test-workspace-${uuidv4()}`; + const runId = uuidv4(); + CloudRunner.buildParameters = buildParameters; + expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); + expect( + await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId, buildParameters), + ).toBeTruthy(); + expect(CloudRunner.lockedWorkspace).toMatch(newWorkspaceName); + }, 300000); + it(`Get Or Create From Locked`, async () => { + const overrides: any = { + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), + targetPlatform: 'StandaloneLinux64', + cacheKey: `test-case-${uuidv4()}`, + maxRetainedWorkspaces: 3, + }; + const buildParameters = await CreateParameters(overrides); + + const newWorkspaceName = `test-workspace-${uuidv4()}`; + const runId = uuidv4(); + const runId2 = uuidv4(); + CloudRunner.buildParameters = buildParameters; + expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceBelowMax(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy(); + expect( + await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId2, buildParameters), + ).toBeTruthy(); + expect(CloudRunner.lockedWorkspace).not.toMatch(newWorkspaceName); + }, 300000); + it(`Get Or Create After Double Lock And One Unlock`, async () => { + const overrides: any = { + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), + targetPlatform: 'StandaloneLinux64', + cacheKey: `test-case-${uuidv4()}`, + maxRetainedWorkspaces: 3, + }; + const buildParameters = await CreateParameters(overrides); + + const newWorkspaceName = `test-workspace-${uuidv4()}`; + const runId = uuidv4(); + const runId2 = uuidv4(); + CloudRunner.buildParameters = buildParameters; + expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeFalsy(); + expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy(); + expect( + await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId2, buildParameters), + ).toBeTruthy(); + expect(CloudRunner.lockedWorkspace).not.toContain(newWorkspaceName); + }, 300000); + it(`Get Or Create After Double Lock And Unlock`, async () => { + const overrides: any = { + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), + targetPlatform: 'StandaloneLinux64', + cacheKey: `test-case-${uuidv4()}`, + maxRetainedWorkspaces: 3, + }; + const buildParameters = await CreateParameters(overrides); + + const newWorkspaceName = `test-workspace-${uuidv4()}`; + const runId = uuidv4(); + const runId2 = uuidv4(); + CloudRunner.buildParameters = buildParameters; + expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeFalsy(); + expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeFalsy(); + expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy(); + expect( + await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId2, buildParameters), + ).toBeTruthy(); + expect(CloudRunner.lockedWorkspace).toContain(newWorkspaceName); + }, 300000); + it(`Get Or Create From Unlocked Was Locked`, async () => { + const overrides: any = { + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), + targetPlatform: 'StandaloneLinux64', + cacheKey: `test-case-${uuidv4()}`, + maxRetainedWorkspaces: 3, + }; + const buildParameters = await CreateParameters(overrides); + + const newWorkspaceName = `test-workspace-${uuidv4()}`; + const runId = uuidv4(); + CloudRunner.buildParameters = buildParameters; + expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); + expect( + await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId, buildParameters), + ).toBeTruthy(); + expect(CloudRunner.lockedWorkspace).toMatch(newWorkspaceName); + }, 300000); + } +}); diff --git a/src/model/cloud-runner/tests/cloud-runner-locking.test.ts b/src/model/cloud-runner/tests/cloud-runner-locking.test.ts index 7059eb91..5f78de3e 100644 --- a/src/model/cloud-runner/tests/cloud-runner-locking.test.ts +++ b/src/model/cloud-runner/tests/cloud-runner-locking.test.ts @@ -27,7 +27,7 @@ describe('Cloud Runner Locking', () => { unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), targetPlatform: 'StandaloneLinux64', cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, + maxRetainedWorkspaces: 3, }; const buildParameters = await CreateParameters(overrides); CloudRunner.buildParameters = buildParameters; @@ -41,7 +41,7 @@ describe('Cloud Runner Locking', () => { unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), targetPlatform: 'StandaloneLinux64', cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, + maxRetainedWorkspaces: 3, }; const runId = uuidv4(); const buildParameters = await CreateParameters(overrides); @@ -50,129 +50,6 @@ describe('Cloud Runner Locking', () => { expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); }, 150000); - it(`Get Or Create From No Workspace`, async () => { - const overrides: any = { - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), - targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, - }; - const buildParameters = await CreateParameters(overrides); - - const newWorkspaceName = `test-workspace-${uuidv4()}`; - const runId = uuidv4(); - CloudRunner.buildParameters = buildParameters; - expect( - await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId, buildParameters), - ).toBeTruthy(); - }, 150000); - it(`Get Or Create From Unlocked`, async () => { - const overrides: any = { - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), - targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, - }; - const buildParameters = await CreateParameters(overrides); - - const newWorkspaceName = `test-workspace-${uuidv4()}`; - const runId = uuidv4(); - CloudRunner.buildParameters = buildParameters; - expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); - expect( - await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId, buildParameters), - ).toBeTruthy(); - expect(CloudRunner.lockedWorkspace).toMatch(newWorkspaceName); - }, 300000); - it(`Get Or Create From Locked`, async () => { - const overrides: any = { - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), - targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, - }; - const buildParameters = await CreateParameters(overrides); - - const newWorkspaceName = `test-workspace-${uuidv4()}`; - const runId = uuidv4(); - const runId2 = uuidv4(); - CloudRunner.buildParameters = buildParameters; - expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceBelowMax(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy(); - expect( - await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId2, buildParameters), - ).toBeTruthy(); - expect(CloudRunner.lockedWorkspace).not.toMatch(newWorkspaceName); - }, 300000); - it(`Get Or Create After Double Lock And One Unlock`, async () => { - const overrides: any = { - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), - targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, - }; - const buildParameters = await CreateParameters(overrides); - - const newWorkspaceName = `test-workspace-${uuidv4()}`; - const runId = uuidv4(); - const runId2 = uuidv4(); - CloudRunner.buildParameters = buildParameters; - expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeFalsy(); - expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy(); - expect( - await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId2, buildParameters), - ).toBeTruthy(); - expect(CloudRunner.lockedWorkspace).not.toContain(newWorkspaceName); - }, 300000); - it(`Get Or Create After Double Lock And Unlock`, async () => { - const overrides: any = { - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), - targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, - }; - const buildParameters = await CreateParameters(overrides); - - const newWorkspaceName = `test-workspace-${uuidv4()}`; - const runId = uuidv4(); - const runId2 = uuidv4(); - CloudRunner.buildParameters = buildParameters; - expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeFalsy(); - expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeFalsy(); - expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy(); - expect( - await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId2, buildParameters), - ).toBeTruthy(); - expect(CloudRunner.lockedWorkspace).toContain(newWorkspaceName); - }, 300000); it(`0 free workspaces after locking`, async () => { const overrides: any = { versioning: 'None', @@ -180,7 +57,7 @@ describe('Cloud Runner Locking', () => { unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), targetPlatform: 'StandaloneLinux64', cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, + maxRetainedWorkspaces: 3, }; const buildParameters = await CreateParameters(overrides); @@ -234,27 +111,5 @@ describe('Cloud Runner Locking', () => { expect(result).toHaveLength(0); expect(await SharedWorkspaceLocking.GetFreeWorkspaces(buildParameters)).toHaveLength(0); }, 300000); - it(`Get Or Create From Unlocked Was Locked`, async () => { - const overrides: any = { - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), - targetPlatform: 'StandaloneLinux64', - cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, - }; - const buildParameters = await CreateParameters(overrides); - - const newWorkspaceName = `test-workspace-${uuidv4()}`; - const runId = uuidv4(); - CloudRunner.buildParameters = buildParameters; - expect(await SharedWorkspaceLocking.CreateWorkspace(newWorkspaceName, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.LockWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect(await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters)).toBeTruthy(); - expect( - await SharedWorkspaceLocking.GetOrCreateLockedWorkspace(newWorkspaceName, runId, buildParameters), - ).toBeTruthy(); - expect(CloudRunner.lockedWorkspace).toMatch(newWorkspaceName); - }, 300000); } }); diff --git a/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-locking.test.ts b/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-locking.test.ts index 933a52b1..7f95a59b 100644 --- a/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-locking.test.ts +++ b/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-locking.test.ts @@ -27,7 +27,7 @@ describe('Cloud Runner Locking', () => { unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), targetPlatform: 'StandaloneLinux64', cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 3, + maxRetainedWorkspaces: 3, }; const buildParameters = await CreateParameters(overrides); diff --git a/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-retaining.test.ts b/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-retaining.test.ts index 5ffab25f..c5407679 100644 --- a/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-retaining.test.ts +++ b/src/model/cloud-runner/tests/e2e/cloud-runner-end2end-retaining.test.ts @@ -23,7 +23,7 @@ describe('Cloud Runner Retain Workspace', () => { unityVersion: UnityVersioning.determineUnityVersion('test-project', UnityVersioning.read('test-project')), targetPlatform: 'StandaloneLinux64', cacheKey: `test-case-${uuidv4()}`, - retainWorkspaces: 1, + maxRetainedWorkspaces: 1, }; const buildParameter = await CreateParameters(overrides); expect(buildParameter.projectPath).toEqual(overrides.projectPath);