feat(ngcc): allow async locking timeouts to be configured (#36838)

The commit adds support to the ngcc.config.js file for setting the
`retryAttempts` and `retryDelay` options for the `AsyncLocker`.

An integration test adds a new check for a timeout and actually uses the
ngcc.config.js to reduce the timeout time to prevent the test from taking
too long to complete.

PR Close #36838
This commit is contained in:
Pete Bacon Darwin
2020-04-28 15:32:05 +01:00
committed by Alex Rickabaugh
parent 98931bf9b5
commit 38f805cd06
6 changed files with 272 additions and 264 deletions

View File

@ -10,7 +10,7 @@ import {createHash} from 'crypto';
import {absoluteFrom, FileSystem, getFileSystem} from '../../../src/ngtsc/file_system';
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
import {loadTestFiles} from '../../../test/helpers';
import {DEFAULT_NGCC_CONFIG, NgccConfiguration} from '../../src/packages/configuration';
import {DEFAULT_NGCC_CONFIG, NgccConfiguration, ProcessLockingConfiguration} from '../../src/packages/configuration';
runInEachFileSystem(() => {
@ -51,7 +51,7 @@ runInEachFileSystem(() => {
}]);
const project1Conf = new NgccConfiguration(fs, project1);
const expectedProject1Config = `{"packages":{"${project1Package1}":[{"entryPoints":{"${
project1Package1EntryPoint1}":{}},"versionRange":"*"}]}}`;
project1Package1EntryPoint1}":{}},"versionRange":"*"}]},"locking":{}}`;
expect(project1Conf.hash)
.toEqual(createHash('md5').update(expectedProject1Config).digest('hex'));
@ -72,7 +72,7 @@ runInEachFileSystem(() => {
}]);
const project2Conf = new NgccConfiguration(fs, project2);
const expectedProject2Config = `{"packages":{"${project2Package1}":[{"entryPoints":{"${
project2Package1EntryPoint1}":{"ignore":true}},"versionRange":"*"}]}}`;
project2Package1EntryPoint1}":{"ignore":true}},"versionRange":"*"}]},"locking":{}}`;
expect(project2Conf.hash)
.toEqual(createHash('md5').update(expectedProject2Config).digest('hex'));
});
@ -80,7 +80,10 @@ runInEachFileSystem(() => {
it('should compute a hash even if there is no project configuration', () => {
loadTestFiles([{name: _Abs('/project-1/empty.js'), contents: ``}]);
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
expect(configuration.hash).toEqual('87c535c3ce0eac2a54c246892e0e21a1');
expect(configuration.hash)
.toEqual(createHash('md5')
.update(JSON.stringify({packages: {}, locking: {}}))
.digest('hex'));
});
});
@ -589,6 +592,61 @@ runInEachFileSystem(() => {
});
});
});
describe('getLockingConfig()', () => {
let originalDefaultConfig: ProcessLockingConfiguration|undefined;
beforeEach(() => {
originalDefaultConfig = DEFAULT_NGCC_CONFIG.locking;
DEFAULT_NGCC_CONFIG.locking = {retryAttempts: 17, retryDelay: 400};
});
afterEach(() => DEFAULT_NGCC_CONFIG.locking = originalDefaultConfig);
it('should return configuration for locking found in a project level file', () => {
loadTestFiles([{
name: _Abs('/project-1/ngcc.config.js'),
contents: `
module.exports = {
locking: {
retryAttempts: 4,
retryDelay: 56,
},
};`
}]);
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
const config = configuration.getLockingConfig();
expect(config).toEqual({
retryAttempts: 4,
retryDelay: 56,
});
});
it('should return configuration for locking partially found in a project level file', () => {
loadTestFiles([{
name: _Abs('/project-1/ngcc.config.js'),
contents: `
module.exports = {
locking: {
retryAttempts: 4,
},
};`
}]);
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
const config = configuration.getLockingConfig();
expect(config).toEqual({
retryAttempts: 4,
retryDelay: 400,
});
});
it('should return default configuration for locking if no project level file', () => {
const configuration = new NgccConfiguration(fs, _Abs('/project-1'));
const config = configuration.getLockingConfig();
expect(config).toEqual({
retryAttempts: 17,
retryDelay: 400,
});
});
});
});
function packageWithConfigFiles(