Skip to content

Conversation

@timdeschryver
Copy link
Contributor

Fixes #1476.

Changes:

  • Added 0 check.
  • Changed the message if concurrency was set to an empty string, because the error message seemed a bit weird.
  • Introduced an extra check to validate if concurrency is an integer.
  • Changed default concurrency from 0 to 1 if no concurrency is given.

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tdeschryver. The error message fix is welcome, and I like the integer parsing stuff too.

I'm wondering though whether the warning when 0 is actually a good idea. We just landed a PR that makes AVA pick a concurrency based on the number of CPUs available. I can see a scenario where "concurrency" is configured in the package.json#ava section, but users may still want to run with the default on their own machines. Supporting --concurrency=0 would allow this.

What do you think?

lib/cli.js Outdated
throw new Error(colors.error(figures.cross) + ' The --concurrency and -c flags must be provided.');
}

if (cli.flags.concurrency && isNaN(parseInt(cli.flags.concurrency, 10))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be Number.isInteger(Number.parseFloat('cli.flags.concurrency')). That way even values like 9.5 are rejected, which parse to 9 with parseInt().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Didn't thought about this case.

lib/cli.js Outdated
projectDir,
timeout: conf.timeout,
concurrency: conf.concurrency ? parseInt(conf.concurrency, 10) : 0,
concurrency: conf.concurrency ? parseInt(conf.concurrency, 10) : 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should remain 0. This allows AVA to pick an optimal value for your machine, see https://github.com/avajs/ava/blob/465fcecc9ae0d3274d4d41d3baaca241d6a40130/api.js#L164:L167.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I assumed the default had to change, because you wouldn't be able to set it to 0.

@timdeschryver
Copy link
Contributor Author

@novemberborn seems fair to me. I'll remove the 0 check.

@timdeschryver
Copy link
Contributor Author

@novemberborn would a check on a negative input be useful here? 🤔

Copy link
Member

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fair to me. I'll remove the 0 check.

Cool.

would a check on a negative input be useful here? 🤔

Heh why not! 😄

lib/cli.js Outdated
throw new Error(colors.error(figures.cross) + ' The --concurrency and -c flags must be provided.');
}

if (cli.flags.concurrency && !Number.isInteger(Number.parseFloat(cli.flags.concurrency, 10))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseFloat doesn't take a radix.

lib/cli.js Outdated

if (cli.flags.concurrency &&
(!Number.isInteger(Number.parseFloat(cli.flags.concurrency)) || parseInt(cli.flags.concurrency, 10) < 0)) {
throw new Error(colors.error(figures.cross) + ' The --concurrency and -c flags must be a positive integer.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be nonnegative integer, since 0 is allowed. I feel a bit bad about this nitpick ☹️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! I should be the one saying sorry...

@novemberborn novemberborn changed the title Fail hard when --concurrency is set to 0 Fail hard when --concurrency is set to invalid values Aug 12, 2017
@novemberborn novemberborn merged commit b6eef5a into avajs:master Aug 12, 2017
@novemberborn
Copy link
Member

Thank you @tdeschryver!

@timdeschryver timdeschryver deleted the pr/concurrency-0 branch September 4, 2017 17:41
kevva pushed a commit that referenced this pull request Sep 13, 2017
* Update warning message when the flag is used without a value
* Detect non-integer or negative integer values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants