diff --git a/tests/ctst/world/Zenko.ts b/tests/ctst/world/Zenko.ts index 12d94e94f..5c9b57c10 100644 --- a/tests/ctst/world/Zenko.ts +++ b/tests/ctst/world/Zenko.ts @@ -4,6 +4,7 @@ import { AccessKey } from '@aws-sdk/client-iam'; import { Credentials } from '@aws-sdk/client-sts'; import { aws4Interceptor } from 'aws4-axios'; import qs from 'qs'; +import lockFile from 'proper-lockfile'; import Werelogs from 'werelogs'; import { CacheHelper, @@ -635,22 +636,29 @@ export default class Zenko extends World { Identity.useIdentity(IdentityEnum.ADMIN, site.adminIdentityName); let account = null; - CacheHelper.logger.debug('Creating account', { - accountName, - adminIdentityName: site.adminIdentityName, - credentials: Identity.getCurrentCredentials(), - }); - // Create the account if already exist will not throw any error + let releaseLock: (() => Promise) | null = null; try { - await SuperAdmin.createAccount({ accountName }); - /* eslint-disable */ - } catch (err: any) { - CacheHelper.logger.debug('Error while creating account', { - accountName, - err, + releaseLock = await lockFile.lock('/tmp/account-init.lock', { + stale: Constants.DEFAULT_TIMEOUT / 2, + retries: { + retries: 5, + factor: 3, + minTimeout: 1000, + maxTimeout: 5000, + } }); - if (!err.EntityAlreadyExists && err.code !== 'EntityAlreadyExists') { - throw err; + + try { + await SuperAdmin.createAccount({ accountName }); + /* eslint-disable */ + } catch (err: any) { + if (!err.EntityAlreadyExists && err.code !== 'EntityAlreadyExists') { + throw err; + } + } + } finally { + if (releaseLock) { + await releaseLock(); } } /* eslint-enable */