Trouble verifying build history deletion with mock Jobs

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
I'm working on an update to the enhanced-old-build-discarder plugin that allows for some greater configuration specificity in the discard logic. The plugin functions as expected in my local Jenkins instance, but I'm having trouble with the unit testing.


I must be doing something incorrectly with my mock Job data. I generate a build history suitable for my usage cases and use Mockito "when" to have this represent the build history of the mock Job. An instance of the plugin class is instantiated and this Job is passed to it as an argument. I'm then trying to verify that delete commands are either logged or not logged for the build histories as is appropriate to the usage case. No matter the circumstance builds are never verified to be deleted.

Does anyone have an idea what the issue is here? I expect it won't take much to fix but I'm puzzled by it.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Gavin Mogan
Mockito is weird and awesome at the same time. I'm still fuzzy on a lot of things.


when(jobHMS.getBuilds()).thenReturn(RunList.fromRuns(buildListHMS));

Mockito doesn't actually let you return the results of a function, you'll have to assign it to a local variable first.


That being said, its probably way easier and sustainable to use a jenkinsrule and not try and mock things.

On Sun, Jul 7, 2019 at 7:33 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I'm working on an update to the enhanced-old-build-discarder plugin that allows for some greater configuration specificity in the discard logic. The plugin functions as expected in my local Jenkins instance, but I'm having trouble with the unit testing.


I must be doing something incorrectly with my mock Job data. I generate a build history suitable for my usage cases and use Mockito "when" to have this represent the build history of the mock Job. An instance of the plugin class is instantiated and this Job is passed to it as an argument. I'm then trying to verify that delete commands are either logged or not logged for the build histories as is appropriate to the usage case. No matter the circumstance builds are never verified to be deleted.

Does anyone have an idea what the issue is here? I expect it won't take much to fix but I'm puzzled by it.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DutmLXe3aR5PMNOi1UhXeciJy5WcRhaFhYbxsK1YuQhzEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
Thanks for the advice here, I will investigate this further. :)

On Monday, July 8, 2019 at 12:53:52 AM UTC-4, Gavin Mogan wrote:
Mockito is weird and awesome at the same time. I'm still fuzzy on a lot of things.

A very very quick pass I think its line 44 (<a href="https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java#L44" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java%23L44\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHclok05UXgD6danziKaLov1XVnog&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java%23L44\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHclok05UXgD6danziKaLov1XVnog&#39;;return true;">https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java#L44)

when(jobHMS.getBuilds()).thenReturn(RunList.fromRuns(buildListHMS));

Mockito doesn't actually let you return the results of a function, you'll have to assign it to a local variable first.

Its related to <a href="https://github.com/mockito/mockito/wiki/FAQ#can-i-thenreturn-an-inlined-mock-" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmockito%2Fmockito%2Fwiki%2FFAQ%23can-i-thenreturn-an-inlined-mock-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFJNOjCfjXeoo_T-K8J2ZJDzVtJBQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmockito%2Fmockito%2Fwiki%2FFAQ%23can-i-thenreturn-an-inlined-mock-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFJNOjCfjXeoo_T-K8J2ZJDzVtJBQ&#39;;return true;">https://github.com/mockito/mockito/wiki/FAQ#can-i-thenreturn-an-inlined-mock- I think.

That being said, its probably way easier and sustainable to use a jenkinsrule and not try and mock things.

On Sun, Jul 7, 2019 at 7:33 PM 'Benjamin Beggs' via Jenkins Developers <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="uS1G0ZNiCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com> wrote:
I'm working on an update to the enhanced-old-build-discarder plugin that allows for some greater configuration specificity in the discard logic. The plugin functions as expected in my local Jenkins instance, but I'm having trouble with the unit testing.

The relevant pull request is here: <a href="https://github.com/jenkinsci/enhanced-old-build-discarder/pull/2" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fpull%2F2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGBEyt-kgRzbSt7sgc9TrhV114QsA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fpull%2F2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGBEyt-kgRzbSt7sgc9TrhV114QsA&#39;;return true;">https://github.com/jenkinsci/enhanced-old-build-discarder/pull/2.
The relevant test file is here: <a href="https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGeIcdKG-ANDc7CDlbeHzTQMZEGgw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGeIcdKG-ANDc7CDlbeHzTQMZEGgw&#39;;return true;">https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java.

I must be doing something incorrectly with my mock Job data. I generate a build history suitable for my usage cases and use Mockito "when" to have this represent the build history of the mock Job. An instance of the plugin class is instantiated and this Job is passed to it as an argument. I'm then trying to verify that delete commands are either logged or not logged for the build histories as is appropriate to the usage case. No matter the circumstance builds are never verified to be deleted.

Does anyone have an idea what the issue is here? I expect it won't take much to fix but I'm puzzled by it.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="uS1G0ZNiCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/33aedc7c-4c05-4e45-bdd7-957d5168e57e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
In reply to this post by Gavin Mogan
Reviewing this over I'm not totally sure if line 44 is the issue....the when then statement I run does attribute the build history to jobHMS. I can run List<? extends Run<?,?>> builds = jobHMS.getBuilds(); and check builds.size() and I get 11 entries as expected....still puzzled by this.

Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

On Monday, July 8, 2019 at 12:53:52 AM UTC-4, Gavin Mogan wrote:
Mockito is weird and awesome at the same time. I'm still fuzzy on a lot of things.

A very very quick pass I think its line 44 (<a href="https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java#L44" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java%23L44\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHclok05UXgD6danziKaLov1XVnog&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java%23L44\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHclok05UXgD6danziKaLov1XVnog&#39;;return true;">https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java#L44)

when(jobHMS.getBuilds()).thenReturn(RunList.fromRuns(buildListHMS));

Mockito doesn't actually let you return the results of a function, you'll have to assign it to a local variable first.

Its related to <a href="https://github.com/mockito/mockito/wiki/FAQ#can-i-thenreturn-an-inlined-mock-" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmockito%2Fmockito%2Fwiki%2FFAQ%23can-i-thenreturn-an-inlined-mock-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFJNOjCfjXeoo_T-K8J2ZJDzVtJBQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmockito%2Fmockito%2Fwiki%2FFAQ%23can-i-thenreturn-an-inlined-mock-\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFJNOjCfjXeoo_T-K8J2ZJDzVtJBQ&#39;;return true;">https://github.com/mockito/mockito/wiki/FAQ#can-i-thenreturn-an-inlined-mock- I think.

That being said, its probably way easier and sustainable to use a jenkinsrule and not try and mock things.

On Sun, Jul 7, 2019 at 7:33 PM 'Benjamin Beggs' via Jenkins Developers <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="uS1G0ZNiCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com> wrote:
I'm working on an update to the enhanced-old-build-discarder plugin that allows for some greater configuration specificity in the discard logic. The plugin functions as expected in my local Jenkins instance, but I'm having trouble with the unit testing.

The relevant pull request is here: <a href="https://github.com/jenkinsci/enhanced-old-build-discarder/pull/2" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fpull%2F2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGBEyt-kgRzbSt7sgc9TrhV114QsA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fpull%2F2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGBEyt-kgRzbSt7sgc9TrhV114QsA&#39;;return true;">https://github.com/jenkinsci/enhanced-old-build-discarder/pull/2.
The relevant test file is here: <a href="https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGeIcdKG-ANDc7CDlbeHzTQMZEGgw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fenhanced-old-build-discarder%2Fblob%2F47b97f9bf76f644bde91b4fda71f99572cbeda22%2Fsrc%2Ftest%2Fjava%2Forg%2Fjenkinsci%2Fplugins%2Fenhancedoldbuilddiscarder%2FEnhancedOldBuildDiscarderTest.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGeIcdKG-ANDc7CDlbeHzTQMZEGgw&#39;;return true;">https://github.com/jenkinsci/enhanced-old-build-discarder/blob/47b97f9bf76f644bde91b4fda71f99572cbeda22/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java.

I must be doing something incorrectly with my mock Job data. I generate a build history suitable for my usage cases and use Mockito "when" to have this represent the build history of the mock Job. An instance of the plugin class is instantiated and this Job is passed to it as an argument. I'm then trying to verify that delete commands are either logged or not logged for the build histories as is appropriate to the usage case. No matter the circumstance builds are never verified to be deleted.

Does anyone have an idea what the issue is here? I expect it won't take much to fix but I'm puzzled by it.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="uS1G0ZNiCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/1a92e9c4-f6b0-487f-a866-56a01b0aacb8%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/f54346b4-8d85-4a94-aab9-f3c0f0d733f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Jesse Glick-4
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr06q%2BSpXqkW1DfSKHw%3D5-3K1pCk%3DfHe6vLvO_oAdNVGag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="u5xypBONCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

<a href="https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;">https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/992cd951-6e94-4ca5-933b-7c8e85418ded%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

<a href="https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;">https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Gavin Mogan
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DusEatx84S_rYmUYw3QkC7FWGEy2X75dZZmOC9BNEyZTiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GbS2QwqbCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

<a href="https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;">https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="GbS2QwqbCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Gavin Mogan
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DutVDx0HPSKfW4Az11svUjUPTvT0X1Er0_RhCVd6godD9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
I almost had this working with Mockito but hit a wall...it's possible PowerMock will solve the issue. I'll give this a go!

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Ukc1X8edCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

<a href="https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;">https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Ukc1X8edCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1dd9d470-5c0a-4ff3-bc3e-78610c593b28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Ulli Hafner
BTW: mockito can stub final methods as well: https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#unmockable

Which method did you try to stub that is final? Maybe you can change that part in your code by using a facade or adapter...

Am 09.07.2019 um 03:34 schrieb 'Benjamin Beggs' via Jenkins Developers <[hidden email]>:

I almost had this working with Mockito but hit a wall...it's possible PowerMock will solve the issue. I'll give this a go!

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <jenkin...@googlegroups.com> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1dd9d470-5c0a-4ff3-bc3e-78610c593b28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/761DC01E-FF74-4A6D-9EFC-0764243AE27C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-2
isKeepLog() wasn't stubbing properly for me. Additionally I need to produce a mock logic for getNextBuild() if I use a Mockito implementation for this. The mock framework doesn't cycle through builds properly with getNextBuild() in its current state.

On Tue, Jul 9, 2019 at 3:03 AM Ullrich Hafner <[hidden email]> wrote:
BTW: mockito can stub final methods as well: <a href="https://github.com/mockito/mockito/wiki/What&#39;s-new-in-Mockito-2#unmockable" target="_blank">https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#unmockable

Which method did you try to stub that is final? Maybe you can change that part in your code by using a facade or adapter...

Am 09.07.2019 um 03:34 schrieb 'Benjamin Beggs' via Jenkins Developers <[hidden email]>:

I almost had this working with Mockito but hit a wall...it's possible PowerMock will solve the issue. I'll give this a go!

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/1dd9d470-5c0a-4ff3-bc3e-78610c593b28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/_kNEe9ggaW0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/761DC01E-FF74-4A6D-9EFC-0764243AE27C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAMSuSKTR9bbQCWM_2b3L9oGBSsQAqrj59t7O2-pd7ppSTXZpdA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
In reply to this post by Gavin Mogan
I've rewritten the test using JenkinsRule. The result is here: https://github.com/jenkinsci/enhanced-old-build-discarder/blob/839210ca60694be6ad9b2152e671d39f82174ee5/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java.

This is a much cleaner, less finicky implementation. However, my attempt to mock the time stamps for the builds isn't working. Does anyone have an idea for why this is?

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Ukc1X8edCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

<a href="https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fjenkins%2Fblob%2Fa6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795%2Ftest%2Fsrc%2Ftest%2Fjava%2Fhudson%2Ftasks%2FLogRotatorTest.java%23L67-L82\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWCItkT2aWUK_5oLOriypcwHrqHw&#39;;return true;">https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Ukc1X8edCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e8303bf9-4523-4fc2-96cd-45affddef1d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Gavin Mogan-2
So I'd personally try stubbing out calendar, and let jenkins take care of the rest. Purely pseudo code, untested by me.


@PrepareForTest({Class1.class, Class2.class})
class YourClassHere {

yourFunctionHere() {

PowerMockito.mockStatic(Calendar);
mockCalendarInstance = mock(Calendar.class);
PowerMockIto.when(Calendar.getInstance()).thenReturn(mockCalendarInstance);

FreeStyleProject testProject = jRule.createFreeStyleProject("test"))

foreach timestamps {
mockCalendarInstance.setTime....
jRule.assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get()));
}


On Tue, Jul 9, 2019 at 10:38 AM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I've rewritten the test using JenkinsRule. The result is here: https://github.com/jenkinsci/enhanced-old-build-discarder/blob/839210ca60694be6ad9b2152e671d39f82174ee5/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java.

This is a much cleaner, less finicky implementation. However, my attempt to mock the time stamps for the builds isn't working. Does anyone have an idea for why this is?

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e8303bf9-4523-4fc2-96cd-45affddef1d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAAgr96%2Brwq8tgn8LhgXAH_V3%2BPhk8OJWFnQioFtuNp2zZptmpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Ulli Hafner
This topic reminds me of one of my architecture guidelines I’m presenting students in my testing lecture:
An application should always provide a way to change (or inject) the current date (time). Seems that this is not only relevant in business applications ;-)

I also faced a similar problem when trying to test the time series of the warnings charts (several builds over several days). I solved the problem by wrapping each build into an own object that has a time instance that can be changed in tests.

Your code creates a lot of freestyle build spy instances that are actually never used. The EnhancedOldBuildDiscarder  
gets the builds using Jenkins API. So your spy is never used in the test. You need to replace the builds in the job with your spy instances.

Am 09.07.2019 um 21:33 schrieb Gavin Mogan <[hidden email]>:

So I'd personally try stubbing out calendar, and let jenkins take care of the rest. Purely pseudo code, untested by me.


@PrepareForTest({Class1.class, Class2.class})
class YourClassHere {

yourFunctionHere() {

PowerMockito.mockStatic(Calendar);
mockCalendarInstance = mock(Calendar.class);
PowerMockIto.when(Calendar.getInstance()).thenReturn(mockCalendarInstance);

FreeStyleProject testProject = jRule.createFreeStyleProject("test"))

foreach timestamps {
mockCalendarInstance.setTime....
jRule.assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get()));
}


On Tue, Jul 9, 2019 at 10:38 AM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I've rewritten the test using JenkinsRule. The result is here: https://github.com/jenkinsci/enhanced-old-build-discarder/blob/839210ca60694be6ad9b2152e671d39f82174ee5/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java.

This is a much cleaner, less finicky implementation. However, my attempt to mock the time stamps for the builds isn't working. Does anyone have an idea for why this is?

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e8303bf9-4523-4fc2-96cd-45affddef1d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAAgr96%2Brwq8tgn8LhgXAH_V3%2BPhk8OJWFnQioFtuNp2zZptmpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/D2D18CD8-C489-47F5-A015-3768431752D2%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-2
Thanks for the ideas here. There are indeed a set of redundant spy instances in the file sent. I will clean those up. I think I'm close to getting this worked out...

On Tue, Jul 9, 2019 at 4:47 PM Ullrich Hafner <[hidden email]> wrote:
This topic reminds me of one of my architecture guidelines I’m presenting students in my testing lecture:
An application should always provide a way to change (or inject) the current date (time). Seems that this is not only relevant in business applications ;-)

I also faced a similar problem when trying to test the time series of the warnings charts (several builds over several days). I solved the problem by wrapping each build into an own object that has a time instance that can be changed in tests.

Your code creates a lot of freestyle build spy instances that are actually never used. The EnhancedOldBuildDiscarder  
gets the builds using Jenkins API. So your spy is never used in the test. You need to replace the builds in the job with your spy instances.

Am 09.07.2019 um 21:33 schrieb Gavin Mogan <[hidden email]>:

So I'd personally try stubbing out calendar, and let jenkins take care of the rest. Purely pseudo code, untested by me.


@PrepareForTest({Class1.class, Class2.class})
class YourClassHere {

yourFunctionHere() {

PowerMockito.mockStatic(Calendar);
mockCalendarInstance = mock(Calendar.class);
PowerMockIto.when(Calendar.getInstance()).thenReturn(mockCalendarInstance);

FreeStyleProject testProject = jRule.createFreeStyleProject("test"))

foreach timestamps {
mockCalendarInstance.setTime....
jRule.assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get()));
}


On Tue, Jul 9, 2019 at 10:38 AM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I've rewritten the test using JenkinsRule. The result is here: https://github.com/jenkinsci/enhanced-old-build-discarder/blob/839210ca60694be6ad9b2152e671d39f82174ee5/src/test/java/org/jenkinsci/plugins/enhancedoldbuilddiscarder/EnhancedOldBuildDiscarderTest.java.

This is a much cleaner, less finicky implementation. However, my attempt to mock the time stamps for the builds isn't working. Does anyone have an idea for why this is?

On Monday, July 8, 2019 at 6:58:44 PM UTC-4, Gavin Mogan wrote:
You can probably use powermock to override the static Calendar.getInstance()

But I don't easily know if that function is used to generate the internal build time, but you can probably track it down with a breakpoint in build.class

On Mon, Jul 8, 2019 at 3:36 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
I think a full implementation with Mockito is untenable. It seems I would need to mock an excessive amount of function returns and the result may still be inflexible and finnicky.

I'll follow the JenkinsRule method you're talking about...I expect I can still mock the date data. Thanks for the help here. :)

On Monday, July 8, 2019 at 6:08:33 PM UTC-4, Gavin Mogan wrote:
That shouldn't be the case if you use JenkinsRule, actually create the project, and run a quick echo pipeline a few times.

I know from working on the java 11 stuff, that mockito has trouble mocking functions that are final, it'll silently not do so. Its going to save you a ton of headaches to use JenkinsRule.

@Rule
public JenkinsRule j = new JenkinsRule()

p = j.createFreeStyleProject("name");
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 1
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 2
jenkins.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // build 3

but i see you are messing with dates, so that might be trickier, i'm not sure.

You can try subclassing FreeStyleProject, and overriding the function to return the value you want.
If that works fine, then its how the function matching/overriding works in mockito, if it doesn't work, then its the weird final/static stuff that mockito has trouble with. You might need to also use powermock and prepare for test.

On Mon, Jul 8, 2019 at 12:40 PM 'Benjamin Beggs' via Jenkins Developers <[hidden email]> wrote:
The issue here is with my build history instantiation. All build retrieve calls return null regardless of method (getFirstBuild, getLastBuild, getBuildByNumber, etc).

On Monday, July 8, 2019 at 3:24:47 PM UTC-4, Benjamin Beggs wrote:
I will investigate this further, thanks for pointing this implementation out to me.

On Monday, July 8, 2019 at 1:52:40 PM UTC-4, Jesse Glick wrote:
On Mon, Jul 8, 2019 at 1:39 PM 'Benjamin Beggs' via Jenkins Developers
<[hidden email]> wrote:
> Do you have an example of a similar implementation for unit testing using jenkinsrule? I may try just porting the tests over to this.

I would definitely advise using `JenkinsRule` over mocking frameworks.
Slower, but much more realistic (and much more likely to continue
running after internal refactorings). Example:

https://github.com/jenkinsci/jenkins/blob/a6f5b2b1288d15cd2ea5c2fd9b8916e6397bf795/test/src/test/java/hudson/tasks/LogRotatorTest.java#L67-L82

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/610d3de0-c377-4c4c-bd2d-db00c84b6f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/529dd72d-c30c-44df-83b5-e4ffacfa7694%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e8303bf9-4523-4fc2-96cd-45affddef1d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAAgr96%2Brwq8tgn8LhgXAH_V3%2BPhk8OJWFnQioFtuNp2zZptmpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/_kNEe9ggaW0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/D2D18CD8-C489-47F5-A015-3768431752D2%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAMSuSKTBd4gfyTF09E2dsXVW0%2B4h%3DXGHdBr_MkazMFj4Yq5j_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Jesse Glick-4
In reply to this post by Ulli Hafner
On Tue, Jul 9, 2019 at 4:47 PM Ullrich Hafner <[hidden email]> wrote:
> This topic reminds me of one of my architecture guidelines I’m presenting students in my testing lecture:
> An application should always provide a way to change (or inject) […]

If you are enumerating design flaws in Jenkins APIs which hurt
testability, you are going to have a very full syllabus. :-)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0duRR8fK%2B-6yLGyNifCEr-%3DvT_HqX8kZ2WzHLOG9cRzw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Gavin Mogan
I'm just going to keep throwing out ideas. timestamp seems to be a protected item in Run, so subclass!:

class MyFreeStyleBuild extends FreeStyleBuild {
    void setTimestamp(long timestamp) {
      this.timestamp = timestamp;
    }
}

class MyFreeStyleProject extends FreeStyleProject {
    @Override
    protected Class<FreeStyleBuild> getBuildClass() {                                                                                                                                                                                                        
        return MyFreeStyleBuild.class;
    }
}

j.createProject(MyFreeStyleProject.class, "test");
((MyFreeStyleBuild) jRule.assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get()))).setTimestamp(whatever you want);
...



On Tue, Jul 9, 2019 at 3:20 PM Jesse Glick <[hidden email]> wrote:
On Tue, Jul 9, 2019 at 4:47 PM Ullrich Hafner <[hidden email]> wrote:
> This topic reminds me of one of my architecture guidelines I’m presenting students in my testing lecture:
> An application should always provide a way to change (or inject) […]

If you are enumerating design flaws in Jenkins APIs which hurt
testability, you are going to have a very full syllabus. :-)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0duRR8fK%2B-6yLGyNifCEr-%3DvT_HqX8kZ2WzHLOG9cRzw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DusCGhpys0ctX%2BXKHJQ-wOpB4w-ypOhqzwAL%3DZ4TCOLb1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trouble verifying build history deletion with mock Jobs

Benjamin Beggs-3
Thanks again, this advice is a great help!

On Tuesday, July 9, 2019 at 6:45:00 PM UTC-4, Gavin Mogan wrote:
I'm just going to keep throwing out ideas. timestamp seems to be a protected item in Run, so subclass!:

class MyFreeStyleBuild extends FreeStyleBuild {
    void setTimestamp(long timestamp) {
      this.timestamp = timestamp;
    }
}

class MyFreeStyleProject extends FreeStyleProject {
    @Override
    protected Class<FreeStyleBuild> getBuildClass() {                                                                                                                                                                                                        
        return MyFreeStyleBuild.class;
    }
}

j.createProject(MyFreeStyleProject.class, "test");
((MyFreeStyleBuild) jRule.assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get()))).setTimestamp(whatever you want);
...



On Tue, Jul 9, 2019 at 3:20 PM Jesse Glick <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OappC5zrCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jgl...@...> wrote:
On Tue, Jul 9, 2019 at 4:47 PM Ullrich Hafner <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OappC5zrCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ullric...@...> wrote:
> This topic reminds me of one of my architecture guidelines I’m presenting students in my testing lecture:
> An application should always provide a way to change (or inject) […]

If you are enumerating design flaws in Jenkins APIs which hurt
testability, you are going to have a very full syllabus. :-)

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OappC5zrCwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkin...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0duRR8fK%2B-6yLGyNifCEr-%3DvT_HqX8kZ2WzHLOG9cRzw%40mail.gmail.com" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0duRR8fK%2B-6yLGyNifCEr-%3DvT_HqX8kZ2WzHLOG9cRzw%40mail.gmail.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0duRR8fK%2B-6yLGyNifCEr-%3DvT_HqX8kZ2WzHLOG9cRzw%40mail.gmail.com&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0duRR8fK%2B-6yLGyNifCEr-%3DvT_HqX8kZ2WzHLOG9cRzw%40mail.gmail.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/0db82c23-2b9c-4a6e-842d-7961c2ac2d4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
12