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

Dev tool profiler #7249

Merged
merged 6 commits into from
Jun 3, 2019
Merged

Dev tool profiler #7249

merged 6 commits into from
Jun 3, 2019

Conversation

dratler
Copy link
Contributor

@dratler dratler commented May 29, 2019

Hi I have Added PR for DevTools Profiler .
this tools can add better info on script behavior and Test coverage,

Shay Dratler added 3 commits May 29, 2019 22:07
Major :
+ Adding to DevTools Profiler
Minor :
+ Adding extractLong and extractInstant to JsonInputConverter
+ Remove JsonInputConverter with JsonInput Methods
+ Add nextInstant at JsonInput
+ Fix some Merge issues
+ Fix Test + Test imports
@dratler
Copy link
Contributor Author

dratler commented May 29, 2019

This PR is related to #6667.
@shs96c please share if something is missing

Copy link
Member

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

This is a great start. Rather than adding loads of comments, I thought it best to outline some general points:

  • Prefer immutable classes --- fields should be final, and there should be no setters as a rule of thumb.
  • Check class invariants in the constructor --- generally this means "make sure all non-optional args are not null"
  • It's best to implement hashCode and equals rather than just one or the other.

Once those changes are made, I think this is ready to land in the tree. :)

Copy link
Member

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, and responding so quickly to the comments! This is now ready to merge.

We can tidy up the remaining comments in a follow up review: the code works, and they're mostly just style things to bear in mind.

while (input.hasNext()) {
switch (input.nextName()) {
case "location":
location = Location.fromJson(input);
Copy link
Member

Choose a reason for hiding this comment

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

input.read(Location.class) will work. Please add a TODO, since we can tidy this up once the code has landed.

Copy link
Member

Choose a reason for hiding this comment

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

One of the nice features of selenium's json library is that if a class has any fromJson method, it'll try and do the Right Thing.

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 will do it for next time

/**
* Whether coverage data for this function has block granularity.
*/
private final Boolean isBlockCoverage;
Copy link
Member

Choose a reason for hiding this comment

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

boolean perhaps? JS would default this to undefined which is a falsey value.

functionName = input.nextString();
break;
case "ranges":
ranges = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

input.read(new TypeToken<List<CoverageRange>>(){}.getType())

public boolean equals(Object obj) {
Objects.requireNonNull(obj, "obj is mandatory for equals method");

return this.getLine() == ((PositionTickInfo) obj).getLine()
Copy link
Member

Choose a reason for hiding this comment

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

This will throw a ClassCastException if obj is not a PositionTickInfo. Prefer:

if (!(obj instanceof PositionTickInfo)) {
  return false;
}

This handles the null case (and it's always legal to pass in null to equals), as well as the case where obj isn't the right type.


@Override
public boolean equals(Object obj) {
Objects.requireNonNull(obj, "obj is mandatory for equals method");
Copy link
Member

Choose a reason for hiding this comment

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

The contract for equals allows null to be passed in.

endTime = input.nextInstant();
break;
case "samples":
samples = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

samples = input.read(new TypeToken<List<Integer>>(){}.getType()) is more idiomatic.

}

private void validateProfile(Profile profiler) {
Assert.assertNotNull(profiler);
Copy link
Member

Choose a reason for hiding this comment

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

Typically junit tests use static imports for Assert (and the assertion methods from assertj)

@shs96c shs96c merged commit a7887c9 into SeleniumHQ:master Jun 3, 2019
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.

3 participants