fixes
parent
b4f87f2bcb
commit
716c604f16
|
@ -5749,7 +5749,7 @@ class SharedWorkspaceLocking {
|
|||
return lines.map((x) => x.replace(`/`, ``)).includes(buildParametersContext.cacheKey);
|
||||
});
|
||||
}
|
||||
static GetAllLocks(workspace, buildParametersContext) {
|
||||
static GetAllLocksForWorkspace(workspace, buildParametersContext) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!(yield SharedWorkspaceLocking.DoesWorkspaceExist(workspace, buildParametersContext))) {
|
||||
return [];
|
||||
|
@ -5790,12 +5790,12 @@ class SharedWorkspaceLocking {
|
|||
}
|
||||
static DoesWorkspaceExist(workspace, buildParametersContext) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return ((yield SharedWorkspaceLocking.GetAllWorkspaces(buildParametersContext)).filter((x) => x.endsWith(`${workspace}_workspace`)).length > 0);
|
||||
return ((yield SharedWorkspaceLocking.GetAllWorkspaces(buildParametersContext)).filter((x) => x.includes(workspace) && x.endsWith(`_workspace`)).length > 0);
|
||||
});
|
||||
}
|
||||
static HasWorkspaceLock(workspace, runId, buildParametersContext) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const locks = (yield SharedWorkspaceLocking.GetAllLocks(workspace, buildParametersContext))
|
||||
const locks = (yield SharedWorkspaceLocking.GetAllLocksForWorkspace(workspace, buildParametersContext))
|
||||
.map((x) => {
|
||||
return {
|
||||
name: x,
|
||||
|
@ -5867,12 +5867,6 @@ class SharedWorkspaceLocking {
|
|||
return false;
|
||||
}
|
||||
const files = yield SharedWorkspaceLocking.ReadLines(`aws s3 ls ${SharedWorkspaceLocking.workspaceRoot}${buildParametersContext.cacheKey}/`);
|
||||
const workspaceFileDoesNotExists = files.filter((x) => {
|
||||
return x.endsWith(`${workspace}_workspace`);
|
||||
}).length === 0;
|
||||
if (workspaceFileDoesNotExists) {
|
||||
throw new Error(`Workspace file doesn't exist`);
|
||||
}
|
||||
const lockFilesExist = files.filter((x) => {
|
||||
return x.includes(workspace) && x.includes(`_lock`);
|
||||
}).length > 0;
|
||||
|
@ -5916,7 +5910,7 @@ class SharedWorkspaceLocking {
|
|||
}
|
||||
static ReleaseWorkspace(workspace, runId, buildParametersContext) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const files = yield SharedWorkspaceLocking.GetAllLocks(workspace, buildParametersContext);
|
||||
const files = yield SharedWorkspaceLocking.GetAllLocksForWorkspace(workspace, buildParametersContext);
|
||||
const file = files.find((x) => x.endsWith(`${workspace}_workspace_lock`) && x.includes(runId));
|
||||
cloud_runner_logger_1.default.log(`All Locks ${files} ${workspace} ${runId}`);
|
||||
cloud_runner_logger_1.default.log(`Deleting lock ${workspace}/${file}`);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -29,7 +29,10 @@ export class SharedWorkspaceLocking {
|
|||
|
||||
return lines.map((x) => x.replace(`/`, ``)).includes(buildParametersContext.cacheKey);
|
||||
}
|
||||
public static async GetAllLocks(workspace: string, buildParametersContext: BuildParameters): Promise<string[]> {
|
||||
public static async GetAllLocksForWorkspace(
|
||||
workspace: string,
|
||||
buildParametersContext: BuildParameters,
|
||||
): Promise<string[]> {
|
||||
if (!(await SharedWorkspaceLocking.DoesWorkspaceExist(workspace, buildParametersContext))) {
|
||||
return [];
|
||||
}
|
||||
|
@ -86,8 +89,8 @@ export class SharedWorkspaceLocking {
|
|||
|
||||
public static async DoesWorkspaceExist(workspace: string, buildParametersContext: BuildParameters) {
|
||||
return (
|
||||
(await SharedWorkspaceLocking.GetAllWorkspaces(buildParametersContext)).filter((x) =>
|
||||
x.endsWith(`${workspace}_workspace`),
|
||||
(await SharedWorkspaceLocking.GetAllWorkspaces(buildParametersContext)).filter(
|
||||
(x) => x.includes(workspace) && x.endsWith(`_workspace`),
|
||||
).length > 0
|
||||
);
|
||||
}
|
||||
|
@ -96,7 +99,7 @@ export class SharedWorkspaceLocking {
|
|||
runId: string,
|
||||
buildParametersContext: BuildParameters,
|
||||
): Promise<boolean> {
|
||||
const locks = (await SharedWorkspaceLocking.GetAllLocks(workspace, buildParametersContext))
|
||||
const locks = (await SharedWorkspaceLocking.GetAllLocksForWorkspace(workspace, buildParametersContext))
|
||||
.map((x) => {
|
||||
return {
|
||||
name: x,
|
||||
|
@ -189,15 +192,6 @@ export class SharedWorkspaceLocking {
|
|||
`aws s3 ls ${SharedWorkspaceLocking.workspaceRoot}${buildParametersContext.cacheKey}/`,
|
||||
);
|
||||
|
||||
const workspaceFileDoesNotExists =
|
||||
files.filter((x) => {
|
||||
return x.endsWith(`${workspace}_workspace`);
|
||||
}).length === 0;
|
||||
|
||||
if (workspaceFileDoesNotExists) {
|
||||
throw new Error(`Workspace file doesn't exist`);
|
||||
}
|
||||
|
||||
const lockFilesExist =
|
||||
files.filter((x) => {
|
||||
return x.includes(workspace) && x.includes(`_lock`);
|
||||
|
@ -267,7 +261,7 @@ export class SharedWorkspaceLocking {
|
|||
runId: string,
|
||||
buildParametersContext: BuildParameters,
|
||||
): Promise<boolean> {
|
||||
const files = await SharedWorkspaceLocking.GetAllLocks(workspace, buildParametersContext);
|
||||
const files = await SharedWorkspaceLocking.GetAllLocksForWorkspace(workspace, buildParametersContext);
|
||||
const file = files.find((x) => x.endsWith(`${workspace}_workspace_lock`) && x.includes(runId));
|
||||
CloudRunnerLogger.log(`All Locks ${files} ${workspace} ${runId}`);
|
||||
CloudRunnerLogger.log(`Deleting lock ${workspace}/${file}`);
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('Cloud Runner Locking', () => {
|
|||
expect(lines.map((x) => x.replace(`/`, ``)).includes(buildParameters.cacheKey));
|
||||
expect(await SharedWorkspaceLocking.DoesCacheKeyTopLevelExist(buildParameters)).toBeTruthy();
|
||||
expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy();
|
||||
const allLocks = await SharedWorkspaceLocking.GetAllLocks(newWorkspaceName, buildParameters);
|
||||
const allLocks = await SharedWorkspaceLocking.GetAllLocksForWorkspace(newWorkspaceName, buildParameters);
|
||||
expect(
|
||||
(
|
||||
await SharedWorkspaceLocking.ReadLines(
|
||||
|
@ -66,11 +66,14 @@ describe('Cloud Runner Locking', () => {
|
|||
const isExpectedLockedAfterLocking =
|
||||
(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)) === true;
|
||||
expect(isExpectedLockedAfterLocking).toBeTruthy();
|
||||
const locksBeforeRelease = await SharedWorkspaceLocking.GetAllLocks(newWorkspaceName, buildParameters);
|
||||
const locksBeforeRelease = await SharedWorkspaceLocking.GetAllLocksForWorkspace(
|
||||
newWorkspaceName,
|
||||
buildParameters,
|
||||
);
|
||||
CloudRunnerLogger.log(JSON.stringify(locksBeforeRelease, undefined, 4));
|
||||
expect(locksBeforeRelease.length).toBe(1);
|
||||
await SharedWorkspaceLocking.ReleaseWorkspace(newWorkspaceName, runId, buildParameters);
|
||||
const locks = await SharedWorkspaceLocking.GetAllLocks(newWorkspaceName, buildParameters);
|
||||
const locks = await SharedWorkspaceLocking.GetAllLocksForWorkspace(newWorkspaceName, buildParameters);
|
||||
expect(locks.length).toBe(0);
|
||||
const isExpectedNotLockedAfterReleasing =
|
||||
(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)) === false;
|
||||
|
@ -175,7 +178,7 @@ describe('Cloud Runner Locking', () => {
|
|||
expect(await SharedWorkspaceLocking.HasWorkspaceLock(newWorkspaceName, runId, buildParameters)).toBeTruthy();
|
||||
expect(await SharedWorkspaceLocking.DoesWorkspaceExist(newWorkspaceName, buildParameters)).toBeTruthy();
|
||||
expect(await SharedWorkspaceLocking.GetAllWorkspaces(buildParameters)).toHaveLength(1);
|
||||
expect(await SharedWorkspaceLocking.GetAllLocks(newWorkspaceName, buildParameters)).toHaveLength(1);
|
||||
expect(await SharedWorkspaceLocking.GetAllLocksForWorkspace(newWorkspaceName, buildParameters)).toHaveLength(1);
|
||||
expect(await SharedWorkspaceLocking.IsWorkspaceLocked(newWorkspaceName, buildParameters)).toBeTruthy();
|
||||
expect(await SharedWorkspaceLocking.GetFreeWorkspaces(buildParameters)).toHaveLength(0);
|
||||
}, 150000);
|
||||
|
|
Loading…
Reference in New Issue