Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support psg update awaiter timeout #155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions resources/schemas/sfdx-project.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,13 @@
"additionalProperties": false,
"properties": {
"adapter": {
"enum": ["mixedContent", "matchingContentFile", "decomposed", "bundle", "default"],
"enum": [
"mixedContent",
"matchingContentFile",
"decomposed",
"bundle",
"default"
],
"type": "string"
},
"decomposition": {
Expand Down Expand Up @@ -1149,6 +1155,18 @@
"description": "Disable Entitlement filtering in source package,which skips entitlements that are already in the target org",
"default": false
},
"permissionsetGroupStatusCheckInterval": {
"title": "Permission set group status check interval",
"type": "integer",
"description": "Interval in milliseconds between permission set group update status checks",
"default": 60000
},
"permissionsetGroupTimeout": {
"title": "Permission set group recalculation timeout",
"type": "integer",
"description": "Permission set group recalculation timeout",
"default": false
},
"disableTransitiveDependencyResolver": {
"title": "Disable Transitive Dependency Resolver",
"type": "boolean",
Expand Down Expand Up @@ -1183,4 +1201,4 @@
}
}
}
}
}
17 changes: 10 additions & 7 deletions src/core/package/packageInstallers/InstallPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export abstract class InstallPackage {
};
}
}

checkPackageDirectoryExists() {
let absPackageDirectory: string = path.join(this.sfpPackage.sourceDir, this.packageDirectory);
if (!fs.existsSync(absPackageDirectory)) {
Expand All @@ -107,11 +107,14 @@ export abstract class InstallPackage {
}

private async waitTillAllPermissionSetGroupIsUpdated() {
const projectConfig = ProjectConfig.getSFDXProjectConfig(this.sfpPackage.sourceDir);
try {
//Package Has Permission Set Group
let permissionSetGroupUpdateAwaiter: PermissionSetGroupUpdateAwaiter = new PermissionSetGroupUpdateAwaiter(
this.connection,
this.logger
this.logger,
projectConfig.plugins.sfp.permissionsetGroupStatusCheckInterval,
projectConfig.plugins.sfp.permissionsetGroupTimeout
);
await permissionSetGroupUpdateAwaiter.waitTillAllPermissionSetGroupIsUpdated();
} catch (error) {
Expand Down Expand Up @@ -222,15 +225,15 @@ export abstract class InstallPackage {
if (skipIfPackageInstalled) {
let installationStatus = await this.sfpOrg.isArtifactInstalledInOrg(this.logger, this.sfpPackage);
return !installationStatus.isInstalled;
} else if(this.sfpPackage.packageType == PackageType.Diff)
} else if(this.sfpPackage.packageType == PackageType.Diff)
{
// If diff package, check if there are any changes to be deployed, else skip
if(!this.sfpPackage.destructiveChanges && this.sfpPackage.metadataCount==0)
{
{
return false;
}
}

return true; // Always install packages if skipIfPackageInstalled is false
}

Expand Down Expand Up @@ -363,7 +366,7 @@ export abstract class InstallPackage {

let analyzers = AnalyzerRegistry.getAnalyzers();
for (const analyzer of analyzers) {
if(await analyzer.isEnabled(this.sfpPackage, this.logger))
if(await analyzer.isEnabled(this.sfpPackage, this.logger))
{
SFPLogger.log(`Executing ${COLOR_KEY_MESSAGE(analyzer.getName())}`, LoggerLevel.INFO, this.logger);
this.sfpPackage = await analyzer.analyze(this.sfpPackage,componentSet, this.logger);
Expand Down Expand Up @@ -489,7 +492,7 @@ export abstract class InstallPackage {
deploymentOptions.rollBackOnError = true;
return deploymentOptions;
}

private getAStringOfSpecificTestClasses(apexTestClassses: string[]) {
let specifedTests = apexTestClassses.join();
return specifedTests;
Expand Down
22 changes: 21 additions & 1 deletion src/core/permsets/PermissionSetGroupUpdateAwaiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@
const psGroupQuery = `SELECT Id,MasterLabel,Status FROM PermissionSetGroup WHERE Status IN ('Updating', 'Outdated')`;

export default class PermissionSetGroupUpdateAwaiter {
constructor(private connection: Connection, private logger: Logger, private intervalBetweenRepeats = 60000) {}
private startTime: number;

constructor(
private connection: Connection,

Check failure on line 12 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L12

'connection' is defined but never used.
private logger: Logger,

Check failure on line 13 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L13

'logger' is defined but never used.
private intervalBetweenRepeats = 60000,

Check failure on line 14 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L14

'intervalBetweenRepeats' is assigned a value but never used.
private timeoutInMs = 30 * 60 * 1000 // Default timeout of 30 minutes

Check failure on line 15 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L15

'timeoutInMs' is assigned a value but never used.
) {
this.startTime = Date.now();
}

async waitTillAllPermissionSetGroupIsUpdated() {
SFPLogger.log(
`Checking status of permission sets group..`,
LoggerLevel.INFO,
this.logger
);

while (true) {
try {
// Check if timeout has been reached
if (Date.now() - this.startTime >= this.timeoutInMs) {
SFPLogger.log(

Check warning on line 31 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codecov / codecov/patch

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L31

Added line #L31 was not covered by tests
`Timeout of ${this.timeoutInMs/1000} seconds reached. Proceeding with deployment regardless of PermissionSetGroup status`,
LoggerLevel.WARN,
this.logger
);
break;

Check warning on line 36 in src/core/permsets/PermissionSetGroupUpdateAwaiter.ts

View check run for this annotation

Codecov / codecov/patch

src/core/permsets/PermissionSetGroupUpdateAwaiter.ts#L36

Added line #L36 was not covered by tests
}

let records = await QueryHelper.query(psGroupQuery, this.connection, false);
if (records.length > 0) {
SFPLogger.log(
Expand Down
17 changes: 16 additions & 1 deletion tests/core/permsets/PermissionSetGroupUpdateAwaiter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AnyJson } from '@salesforce/ts-types';
const $$ = new TestContext();
import PermissionSetGroupUpdateAwaiter from '../../../src/core/permsets/PermissionSetGroupUpdateAwaiter';
import { expect } from '@jest/globals';
import ProjectConfig from '../../../src/core/project/ProjectConfig';

describe('Await till permissionsets groups are updated', () => {
it('should return if all permsets groups are updated', async () => {
Expand All @@ -14,6 +15,7 @@ describe('Await till permissionsets groups are updated', () => {
$$.setConfigStubContents('AuthInfoConfig', {
contents: await testData.getConfig(),
});
$$.stubAliases({});

let records: AnyJson = {
records: [],
Expand All @@ -26,9 +28,22 @@ describe('Await till permissionsets groups are updated', () => {
authInfo: await AuthInfo.create({ username: testData.username }),
});

// Stub the ProjectConfig.getSFDXProjectConfig method
const projectConfig = {
plugins: {
sfp: {
permissionsetGroupStatusCheckInterval: 6000,
permissionsetGroupTimeout: 60000
}
}
};
$$.SANDBOX.stub(ProjectConfig, 'getSFDXProjectConfig').returns(projectConfig);

let permissionSetGroupUpdateAwaiter: PermissionSetGroupUpdateAwaiter = new PermissionSetGroupUpdateAwaiter(
connection,
null
null,
projectConfig.plugins.sfp.permissionsetGroupStatusCheckInterval,
projectConfig.plugins.sfp.permissionsetGroupTimeout
);
await expect(permissionSetGroupUpdateAwaiter.waitTillAllPermissionSetGroupIsUpdated()).resolves.toBeUndefined();
});
Expand Down