This reverts commit 66effde9f3f9796f9507cd80a85692f0e04e96f5. PR Close #36637
This commit is contained in:
parent
bfda7ca5bd
commit
2ed7146393
@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
|
||||||
* found in the LICENSE file at https://angular.io/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <reference types="node" />
|
|
||||||
|
|
||||||
import {ChildProcess} from 'child_process';
|
|
||||||
import * as cluster from 'cluster';
|
|
||||||
|
|
||||||
import {AbsoluteFsPath} from '../../../../src/ngtsc/file_system';
|
|
||||||
import {LockFileWithChildProcess} from '../../locking/lock_file_with_child_process';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A `LockFileWithChildProcess` that is `cluster`-aware and does not spawn unlocker processes from
|
|
||||||
* worker processes (only from the master process, which does the locking).
|
|
||||||
*/
|
|
||||||
export class ClusterLockFileWithChildProcess extends LockFileWithChildProcess {
|
|
||||||
write(): void {
|
|
||||||
if (!cluster.isMaster) {
|
|
||||||
// This is a worker process:
|
|
||||||
// This method should only be on the master process.
|
|
||||||
throw new Error('Tried to create a lock-file from a worker process.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected createUnlocker(path: AbsoluteFsPath): ChildProcess|null {
|
|
||||||
if (cluster.isMaster) {
|
|
||||||
// This is the master process:
|
|
||||||
// Create the unlocker.
|
|
||||||
return super.createUnlocker(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -78,7 +78,7 @@ export class LockFileWithChildProcess implements LockFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createUnlocker(path: AbsoluteFsPath): ChildProcess|null {
|
protected createUnlocker(path: AbsoluteFsPath): ChildProcess {
|
||||||
this.logger.debug('Forking unlocker child-process');
|
this.logger.debug('Forking unlocker child-process');
|
||||||
const logLevel =
|
const logLevel =
|
||||||
this.logger.level !== undefined ? this.logger.level.toString() : LogLevel.info.toString();
|
this.logger.level !== undefined ? this.logger.level.toString() : LogLevel.info.toString();
|
||||||
|
@ -27,7 +27,6 @@ import {EntryPointFinder} from './entry_point_finder/interface';
|
|||||||
import {TargetedEntryPointFinder} from './entry_point_finder/targeted_entry_point_finder';
|
import {TargetedEntryPointFinder} from './entry_point_finder/targeted_entry_point_finder';
|
||||||
import {AnalyzeEntryPointsFn, CreateCompileFn, Executor} from './execution/api';
|
import {AnalyzeEntryPointsFn, CreateCompileFn, Executor} from './execution/api';
|
||||||
import {ClusterExecutor} from './execution/cluster/executor';
|
import {ClusterExecutor} from './execution/cluster/executor';
|
||||||
import {ClusterLockFileWithChildProcess} from './execution/cluster/lock_file_with_child_process';
|
|
||||||
import {ClusterPackageJsonUpdater} from './execution/cluster/package_json_updater';
|
import {ClusterPackageJsonUpdater} from './execution/cluster/package_json_updater';
|
||||||
import {SingleProcessExecutorAsync, SingleProcessExecutorSync} from './execution/single_process_executor';
|
import {SingleProcessExecutorAsync, SingleProcessExecutorSync} from './execution/single_process_executor';
|
||||||
import {CreateTaskCompletedCallback, PartiallyOrderedTasks, Task, TaskProcessingOutcome, TaskQueue} from './execution/tasks/api';
|
import {CreateTaskCompletedCallback, PartiallyOrderedTasks, Task, TaskProcessingOutcome, TaskQueue} from './execution/tasks/api';
|
||||||
@ -429,8 +428,7 @@ function getCreateTaskCompletedCallback(
|
|||||||
function getExecutor(
|
function getExecutor(
|
||||||
async: boolean, inParallel: boolean, logger: Logger, pkgJsonUpdater: PackageJsonUpdater,
|
async: boolean, inParallel: boolean, logger: Logger, pkgJsonUpdater: PackageJsonUpdater,
|
||||||
fileSystem: FileSystem, createTaskCompletedCallback: CreateTaskCompletedCallback): Executor {
|
fileSystem: FileSystem, createTaskCompletedCallback: CreateTaskCompletedCallback): Executor {
|
||||||
const lockFile = inParallel ? new ClusterLockFileWithChildProcess(fileSystem, logger) :
|
const lockFile = new LockFileWithChildProcess(fileSystem, logger);
|
||||||
new LockFileWithChildProcess(fileSystem, logger);
|
|
||||||
if (async) {
|
if (async) {
|
||||||
// Execute asynchronously (either serially or in parallel)
|
// Execute asynchronously (either serially or in parallel)
|
||||||
const locker = new AsyncLocker(lockFile, logger, 500, 50);
|
const locker = new AsyncLocker(lockFile, logger, 500, 50);
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
|
||||||
* found in the LICENSE file at https://angular.io/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <reference types="node" />
|
|
||||||
|
|
||||||
import {ChildProcess} from 'child_process';
|
|
||||||
import * as cluster from 'cluster';
|
|
||||||
|
|
||||||
import {getFileSystem} from '../../../../src/ngtsc/file_system';
|
|
||||||
import {runInEachFileSystem} from '../../../../src/ngtsc/file_system/testing';
|
|
||||||
import {ClusterLockFileWithChildProcess} from '../../../src/execution/cluster/lock_file_with_child_process';
|
|
||||||
import {LockFileWithChildProcess} from '../../../src/locking/lock_file_with_child_process';
|
|
||||||
import {MockLogger} from '../../helpers/mock_logger';
|
|
||||||
import {mockProperty} from '../../helpers/spy_utils';
|
|
||||||
|
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
|
||||||
describe('ClusterLockFileWithChildProcess', () => {
|
|
||||||
const runAsClusterMaster = mockProperty(cluster, 'isMaster');
|
|
||||||
const mockUnlockerProcess = {} as ChildProcess;
|
|
||||||
let lockFileWithChildProcessSpies:
|
|
||||||
Record<'createUnlocker'|'read'|'remove'|'write', jasmine.Spy>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
lockFileWithChildProcessSpies = {
|
|
||||||
createUnlocker: spyOn(LockFileWithChildProcess.prototype as any, 'createUnlocker')
|
|
||||||
.and.returnValue(mockUnlockerProcess),
|
|
||||||
read: spyOn(LockFileWithChildProcess.prototype, 'read').and.returnValue('{unknown}'),
|
|
||||||
remove: spyOn(LockFileWithChildProcess.prototype, 'remove'),
|
|
||||||
write: spyOn(LockFileWithChildProcess.prototype, 'write'),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be an instance of `LockFileWithChildProcess`', () => {
|
|
||||||
const lockFile = new ClusterLockFileWithChildProcess(getFileSystem(), new MockLogger());
|
|
||||||
|
|
||||||
expect(lockFile).toEqual(jasmine.any(ClusterLockFileWithChildProcess));
|
|
||||||
expect(lockFile).toEqual(jasmine.any(LockFileWithChildProcess));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('write()', () => {
|
|
||||||
it('should create the lock-file when called on the cluster master', () => {
|
|
||||||
runAsClusterMaster(true);
|
|
||||||
const lockFile = new ClusterLockFileWithChildProcess(getFileSystem(), new MockLogger());
|
|
||||||
|
|
||||||
expect(lockFileWithChildProcessSpies.write).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
lockFile.write();
|
|
||||||
expect(lockFileWithChildProcessSpies.write).toHaveBeenCalledWith();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error when called on a cluster worker', () => {
|
|
||||||
runAsClusterMaster(false);
|
|
||||||
const lockFile = new ClusterLockFileWithChildProcess(getFileSystem(), new MockLogger());
|
|
||||||
|
|
||||||
expect(() => lockFile.write())
|
|
||||||
.toThrowError('Tried to create a lock-file from a worker process.');
|
|
||||||
expect(lockFileWithChildProcessSpies.write).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('createUnlocker()', () => {
|
|
||||||
it('should create the unlocker when called on the cluster master', () => {
|
|
||||||
runAsClusterMaster(true);
|
|
||||||
const lockFile = new ClusterLockFileWithChildProcess(getFileSystem(), new MockLogger());
|
|
||||||
|
|
||||||
lockFileWithChildProcessSpies.createUnlocker.calls.reset();
|
|
||||||
|
|
||||||
expect((lockFile as any).createUnlocker(lockFile.path)).toBe(mockUnlockerProcess);
|
|
||||||
expect(lockFileWithChildProcessSpies.createUnlocker).toHaveBeenCalledWith(lockFile.path);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not create the unlocker when called on a cluster worker', () => {
|
|
||||||
runAsClusterMaster(false);
|
|
||||||
const lockFile = new ClusterLockFileWithChildProcess(getFileSystem(), new MockLogger());
|
|
||||||
|
|
||||||
expect((lockFile as any).createUnlocker(lockFile.path)).toBeNull();
|
|
||||||
expect(lockFileWithChildProcessSpies.createUnlocker).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user