-
Notifications
You must be signed in to change notification settings - Fork 125
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
Creating JenkinsLocationConfiguration
when the instance is ready
#464
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @joseblas, thank you for your contribution to the open-source Jenkins test harness. I do not doubt you are facing a legitimate problem, and I would love to see a solution integrated. However, the problem you are facing is not clear to me, even after reading BEE-16540. It is also important to note that other members of the open-source Jenkins community do not have access to this issue tracker, so it may be better for you to file an issue in this repository's issue tracking system as well as to avoid using CloudBees-specific terminology in your code comments. At any rate, I seem to vaguely recall having some issues relating to JenkinsLocationConfiguration
testing open-source Jenkins plugins in the past, so I am curious to hear more about your problem to see if it jogs my memory. Once we have a clear understanding of the problem you are facing, we can evaluate the design and implementation of possible solutions, including the one you have proposed.
Hi @basil, first of all, apologies. That slipped bc my day to day work. My problem is when starting a Jenkins instance using RealJenkinsRule This change, as mentioned in test This proposal writes that file just after the port is available when using |
Thanks @joseblas, I think we need to understand a few more things:
|
Sure @basil
|
It's created in the setupwizard or with jcasc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if has been addresses by
JenkinsRule
as this use case needs RealJenkinsRule bc of the external process.
The implication was that you should do some research to find out, since the answer to this question is important context to have in mind when evaluating the design of this proposed fix. Had you done this research, you would have seen that not only does JenkinsRule
create this file in https://github.com/jenkinsci/jenkins-test-harness/blob/0038ef9b8a0bb2fec2ef4be67d1124f51db53076/src/main/java/org/jvnet/hudson/test/JenkinsRule.java#L438= but also that it creates it in a less fragile way than writing out a string of hard-coded XML to disk (rather, it uses XStream to serialize the Java object to disk).
And in fact, so does RealJenkinsRule
in https://github.com/jenkinsci/jenkins-test-harness/blob/0038ef9b8a0bb2fec2ef4be67d1124f51db53076/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java#L807= And putting a breakpoint on that line and running RealJenkinsRuleTest#smokes
clearly does create jenkins.model.JenkinsLocationConfiguration.xml
. But running your new RealJenkinsRuleTest#testJenkinsLocationConfiguration
test in a debugger, we do not hit the same breakpoint. This points to the proximate cause of your problem: somehow, your new RealJenkinsRuleTest#testJenkinsLocationConfiguration
(and presumably your actual use case) which only calls RealJenkinsRule#startJenkins
is unexpectedly not executing https://github.com/jenkinsci/jenkins-test-harness/blob/0038ef9b8a0bb2fec2ef4be67d1124f51db53076/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java#L807= but RealJenkinsRuleTest#smokes
(and presumably not your actual use case) which calls RealJenkinsRule#then
is expectedly executing https://github.com/jenkinsci/jenkins-test-harness/blob/0038ef9b8a0bb2fec2ef4be67d1124f51db53076/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java#L807=.
The next step from here is to answer the question: "Why?" I would suggest going through both code paths in the debugger and examining what is the key difference between the two execution scenarioes that results in the expected behavior in one and unexpected behavior in the other. When doing this exercise, think about what the expected calling convention (e.g., #then
, #startJenkins
, etc) is and what the expected behavior is for each calling convention. Then observe what actually happens with regard to hitting https://github.com/jenkinsci/jenkins-test-harness/blob/0038ef9b8a0bb2fec2ef4be67d1124f51db53076/src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java#L807=. You may discover that #then
(which calls #startJenkins
, #runRemotely
, and #stopJenkins
) is creating jenkins.model.JenkinsLocationConfiguration.xml
in the #runRemotely
method. That might motivate you to change your code to conform to the expected calling convention (e.g., using #then
or adding a #runRemotely
call between your #startJenkins
and #stopJenkins
calls), or it might motivate changing the semantics of the existing methods to match your expectations (e.g., moving the creation of jenkins.model.JenkinsLocationConfiguration.xml
from #runRemotely
to #startJenkins
).
You requested a second review from me without addressing the feedback about CloudBees-specific terminology that I provided in my first review and without doing the research (key to understanding the nature of the problem) that I suggested in my first review. That is no big deal, but I would ask that in the future you go through my review feedback systematically before requesting subsequent reviews. In particular, before requesting a third review I would ask that you go through the exercise I described above to take the proximate cause of the problem to a root cause, describing the two code paths (preferably with stack traces) and explaining in writing the reason why one code path results in the expected result and the other code path results in the unexpected result. Once this root cause analysis has been provided, I would be happy to review this PR a third time.
hi @basil, Apologies for not creating the issue here, already done, I did not take that as wanted. Again, apologies.
|
Seems perfectly readable to me. I suggest spending more time stepping through the code in a debugger, as mentioned in my previous post.
No, I meant these code comments in your PR which refer to concepts that do not exist in open-source Jenkins:
The comments in my previous post about root-cause analysis still apply. |
Hi @basil, thanks for the feedback. I've already changed the comments. I've spent time with debugger and code analysis and, to be honest, I think using startJenkins should have the same functionality as In my particular case I have three instances running with class inheritance which makes the hardly readably, but that could be unrelevant, but I think is important to have the same functionality with both |
JenkinsLocationConfiguration
when the instance is ready
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also unclear on what problem is being solved here. #467 says something about port assignment (#348 I presume) but that should be transparent to tests. Is there something which worked before which broke—what? And what is the relationship to JCasC exactly? Is it really reading $JENKINS_HOME/jenkins.model.JenkinsLocationConfiguration.xml
directly rather than going through the normal API methods? If not, then you should be able to demonstrate the actual problem you have in a minimal, self-contained way, perhaps with the help of a mock plugin that does something earlier in startup than a runRemotely
block would capture.
rr.startJenkins(); | ||
String[] jenkinsLocations = rr.getHome().list( | ||
(dir, name) -> name.equalsIgnoreCase("jenkins.model.JenkinsLocationConfiguration.xml")); | ||
assertThat(jenkinsLocations, IsArrayWithSize.arrayWithSize(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the Matchers
import. Anyway I think you would want to assert the actual XML content.
I am not even sure what code is being discussed here. One common way to demonstrate concretely why an API or other change is desirable, even if not strictly necessary, is to first write a passing test using a supposedly awkward workaround, commit it, then introduce the proposed change in a commit alongside a simplification to the test case. |
That seems plausible but I would want to better understand the use case for not using
I suspect the author of this PR may be referring to the code in |
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
Let me try to explain all history behind this. A few weeks I started developing some testing classes for Jenkins, involving several instances. As a matter of fact, three instances which two of them had to get a connection file from the other one. As the testing is complex, I did not use So I tried to get a workaround for this. As JCasC was involved in my testing and before 2.339 you could get the port before starting Jenkins I could pass it through JCasC,
After upgrading to +2.339 this stopped working as the port is not available beforehand. So I start to check again why. The reason was the same: JLC file is not created. So I try another way of creating a JLC file. After So it had to stay within I've added three tests, with a new method in RealJenkinsRule: createJenkinsLocationConfigurationFileWhenStartingRealJenkinsRule() which is a boolean to create the JLC file (or not) when stating Jenkins. First one:
This test shows that the JLC file is not created when starting Jenkins with RealJenkinsRule. Then the second one for showing that JLC file is indeed created when using
note: with
and run remotely calls a remote method for execution
and CustomJenkinsRule constructor is:
And also is created when using the new feature added:
|
After some digging I think is not possible to use If one instance is created at top level (as @rule or @ClassRule), then the second one has to be started. And that This, doesn't work bc you cannot create a RealJenkinsRule within
Throws a NPE here,
|
Of course not; the What none of the above discussion, nor the new test coverage, actually explains is the purpose of all this. Why do you expect a file named My impression is that this is somehow related to CloudBees proprietary code (not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As previously discussed, and looks like this is currently in a draft condition anyway.
@@ -186,6 +186,7 @@ public final class RealJenkinsRule implements TestRule { | |||
private static final Pattern SNAPSHOT_INDEX_JELLY = Pattern.compile("(file:/.+/target)/classes/index.jelly"); | |||
private transient boolean supportsPortFileName; | |||
|
|||
private boolean createJenkinsLocationConfigurationFileWhenStartingRealJenkinsRule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently unused.
try { | ||
URL status = endpoint("status"); | ||
HttpURLConnection conn = (HttpURLConnection) status.openConnection(); | ||
|
||
String checkResult = checkResult(conn); | ||
if (checkResult == null) { | ||
runRemotely(jr -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not pass a lambda or anonymous inner class to runRemotely
.
Closing this PR bc what this wanted to solve was not a real need. |
No description provided.