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

Improve InboundAgentRule #493

Merged
merged 3 commits into from
Oct 5, 2022
Merged

Improve InboundAgentRule #493

merged 3 commits into from
Oct 5, 2022

Conversation

basil
Copy link
Member

@basil basil commented Sep 29, 2022

Various improvements to InboundAgentRule:

  • Support WebSocket
  • Support secrets
  • Support skipping agent start
  • Improve determinism by waiting for SlaveComputer#_connect to finish after adding the agent but before starting it
  • Add work directory options
  • Use thread-safe data structures

The motivation behind this is to enable most tests in Jenkins core to be converted to this rule. That way flakiness fixes can be implemented in one place and apply to all tests, which isn't possible with the copypasta we have today.

Once I get an incremental I'll post a core PR demonstrating how this is used.

@basil
Copy link
Member Author

basil commented Sep 30, 2022

So far this has passed a regular Jenkins core test run as well as running all InboundAgentRule tests in a loop for 5 hours with no flakes. I'll keep on running the latter tests in a loop, but this PR looks promising so far.

@basil basil marked this pull request as ready for review September 30, 2022 08:06
public static class Options {
// TODO Java 14+ use records

@CheckForNull private String name;
Copy link
Member

Choose a reason for hiding this comment

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

personal preference would be to move the annotation above it, it looks strange to me as it's in the same grouping of variables and feels mis-aligned. (feel free to ignore)

Suggested change
@CheckForNull private String name;
@CheckForNull
private String name;

Copy link
Member Author

Choose a reason for hiding this comment

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

google-java-format puts them on the same line if the whole line would be within the margin, and I have seen another argument that they should be on the same line because type annotations should be close to their corresponding type. I do not care much either way.

* <p>Instances of {@link Builder} are created by calling {@link
* InboundAgentRule.Options#newBuilder}.
*/
public interface Builder {
Copy link
Member

Choose a reason for hiding this comment

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

would you be able to explain why you went for an interface for a builder? It's not a pattern I'm familiar with (of course there's many slightly different ways to do builders).

Copy link
Member Author

Choose a reason for hiding this comment

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

Just being paranoid about not exposing internal implementation details to consumers I suppose.

Copy link
Member

Choose a reason for hiding this comment

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

I also struggled to understand this (looking into #514 (comment)). Conventionally builders would be concrete final classes. AFAICT the only implementation is in fact BuilderImpl?

Copy link
Member

Choose a reason for hiding this comment

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

Something else I found confusing is that Options has setters as well as a builder; conventionally only a builder would have mutable state, and the built class would use final fields. Is there some reason these would be called after BuilderImpl.build has returned?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you do not like it, then change it.

start(r, name);
// SlaveComputer#_connect runs asynchronously. Wait for it to finish for a more deterministic test.
while (s.toComputer().getOfflineCause() == null) {
Thread.sleep(100);
Copy link
Member

Choose a reason for hiding this comment

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

is there a chance this never happens and we end up with an infinite loop? I guess the test timeout would kick in eventually.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, just like in a half-dozen other methods in JenkinsRule.

@basil basil merged commit 943040a into jenkinsci:master Oct 5, 2022
@basil basil deleted the InboundAgentRule branch October 5, 2022 18:33
basil added a commit to basil/jenkins that referenced this pull request Oct 5, 2022
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