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

javascript: Nodejs tests batch support #18742

Merged
merged 6 commits into from May 1, 2023

Conversation

tobni
Copy link
Contributor

@tobni tobni commented Apr 13, 2023

Add support for running tests in batches via the nodejs package manager test runners.

Comment on lines +95 to +99
class JSTestBatchCompatibilityTagField(TestsBatchCompatibilityTagField):
help = help_text(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sort of think that setting default="default" here would be a sane default, but I also believe that there's value in keeping this as close to 1:1 as the python variant.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to matching Python's default behavior of no batching. That way we keep fine-grained caching by default.

@tobni tobni changed the title Nodejs test batch support javascruot: Nodejs tests batch support Apr 13, 2023
@tobni tobni changed the title javascruot: Nodejs tests batch support javascript: Nodejs tests batch support Apr 13, 2023
@benjyw benjyw requested a review from danxmoran April 15, 2023 20:49
Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

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

Looks sane to me.

@@ -332,3 +333,41 @@ def _get_sources_field_name(field_set_type: type[FieldSet]) -> str:
+ " Pants can't provide a default partitioner."
)
return sources_field_name


class TestsBatchCompatibilityTagField(StringField):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is the right place to define this. Some of our other recurring TestXYZ fields are defined in src/python/pants/core/goals/test.py (i.e. TestTimeoutField, TestExtraEnvVarsField). Could you move it there? And add metaclass=ABCMeta to it so it matches the others?

Comment on lines +95 to +99
class JSTestBatchCompatibilityTagField(TestsBatchCompatibilityTagField):
help = help_text(
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to matching Python's default behavior of no batching. That way we keep fine-grained caching by default.


@property
def description(self) -> str:
return f'{self.owning_package.ensure_owner()[NodePackageNameField].value} {self.compatibility_tag or ""}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's not showing in the UI, but it looks to me like owning_package is only ever used to invoke ensure_owner(). Could the output of ensure_owner() be the thing that's tracked as a field in the TestMetadata?

file: str,
working_directory: str,
) -> FilesystemCoverageReport:
# It is up to the user to configure the output coverage reports.
file_path = PurePath(file)
output_dir = nodejs_test.render_coverage_output_dir(dist_dir, address)
output_dir = nodejs_test.render_coverage_output_dir(dist_dir, addresses[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

In the Python impl we incorporate batch size into the names of any extra outputs: https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/goals/pytest_runner.py#L329

What do you think about doing the same here?

Copy link
Contributor Author

@tobni tobni Apr 17, 2023

Choose a reason for hiding this comment

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

Currently users name the output files and directories for coverage reports. I think your suggestion would require some sort of interpolation impl? Or do you mean incorporate it in the output directory name?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did mean interpolation, though maybe that's not appropriate (I'm not sure what the impl of render_coverage_output_dir currently does). If the address is somehow being incorporated into the outputs, I'd recommend having render_coverage_output_dir take all the addresses as args instead of picking an arbitrary one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the batch information to the rendered output path.

@stuhood
Copy link
Sponsor Member

stuhood commented Apr 18, 2023

Thanks a lot! Will bow out and let @danxmoran shipit, since he drove Python's test batching.

Copy link
Contributor

@danxmoran danxmoran left a comment

Choose a reason for hiding this comment

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

🎉

@danxmoran danxmoran merged commit 1b63d39 into pantsbuild:main May 1, 2023
17 checks passed
@tobni tobni deleted the add/js-test-batching branch May 16, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants