From 2021121cb8712871fa1dbd0a9634eb47cf9c20c5 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Tue, 3 Dec 2024 17:54:59 +0100 Subject: [PATCH] Create the lock file for kube job runs Issue: ZENKO-4941 --- tests/ctst/steps/utils/kubernetes.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/ctst/steps/utils/kubernetes.ts b/tests/ctst/steps/utils/kubernetes.ts index 249275614..3f9c9520d 100644 --- a/tests/ctst/steps/utils/kubernetes.ts +++ b/tests/ctst/steps/utils/kubernetes.ts @@ -1,3 +1,4 @@ +import fs from 'fs'; import * as path from 'path'; import lockFile from 'proper-lockfile'; import { KubernetesHelper, Utils } from 'cli-testing'; @@ -84,6 +85,10 @@ export async function createJobAndWaitForCompletion( const lockFilePath = path.join('/tmp', `${jobName}.lock`); let releaseLock: (() => Promise) | false = false; + if (!fs.existsSync(lockFilePath)) { + fs.writeFileSync(lockFilePath, 'job'); + } + try { // Acquire lock on the file releaseLock = await lockFile.lock(lockFilePath, { stale: 600000 }); @@ -148,6 +153,7 @@ export async function createJobAndWaitForCompletion( // Ensure the lock is released if (releaseLock) { await releaseLock(); + fs.unlinkSync(lockFilePath); world.logger.debug(`Released lock for job: ${jobName}`); } }