Skip to content

Commit

Permalink
fix: remove workaround for cli parameters being turned into string
Browse files Browse the repository at this point in the history
  • Loading branch information
Falx authored and joachimvh committed Jun 1, 2022
1 parent 3f817b1 commit a99db00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/init/cluster/ClusterManager.ts
Expand Up @@ -49,12 +49,8 @@ export class ClusterManager {
private readonly workers: number;
private readonly clusterMode: ClusterMode;

public constructor(workers: number | string) {
public constructor(workers: number) {
const cores = cpus().length;
// Workaround for https://github.com/CommunitySolidServer/CommunitySolidServer/issues/1182
if (typeof workers === 'string') {
workers = Number.parseInt(workers, 10);
}

if (workers <= -cores) {
throw new InternalServerError('Invalid workers value (should be in the interval ]-num_cores, +∞).');
Expand Down
18 changes: 9 additions & 9 deletions test/unit/init/cluster/ClusterManager.test.ts
Expand Up @@ -30,7 +30,7 @@ describe('A ClusterManager', (): void => {
});

it('can handle workers input as string.', (): void => {
const cm = new ClusterManager('4');
const cm = new ClusterManager(4);
expect(cm.isSingleThreaded()).toBeFalsy();
});

Expand All @@ -46,14 +46,14 @@ describe('A ClusterManager', (): void => {
});

it('errors on invalid workers amount.', (): void => {
expect((): ClusterManager => new ClusterManager('10')).toBeDefined();
expect((): ClusterManager => new ClusterManager('2')).toBeDefined();
expect((): ClusterManager => new ClusterManager('1')).toBeDefined();
expect((): ClusterManager => new ClusterManager('0')).toBeDefined();
expect((): ClusterManager => new ClusterManager('-1')).toBeDefined();
expect((): ClusterManager => new ClusterManager('-5')).toBeDefined();
expect((): ClusterManager => new ClusterManager('-6')).toThrow('Invalid workers value');
expect((): ClusterManager => new ClusterManager('-10')).toThrow('Invalid workers value');
expect((): ClusterManager => new ClusterManager(10)).toBeDefined();
expect((): ClusterManager => new ClusterManager(2)).toBeDefined();
expect((): ClusterManager => new ClusterManager(1)).toBeDefined();
expect((): ClusterManager => new ClusterManager(0)).toBeDefined();
expect((): ClusterManager => new ClusterManager(-1)).toBeDefined();
expect((): ClusterManager => new ClusterManager(-5)).toBeDefined();
expect((): ClusterManager => new ClusterManager(-6)).toThrow('Invalid workers value');
expect((): ClusterManager => new ClusterManager(-10)).toThrow('Invalid workers value');
});

it('has an isPrimary() that works.', (): void => {
Expand Down

0 comments on commit a99db00

Please sign in to comment.