Skip to content
Permalink
Browse files
[JENKINS-48037] Use initial claim date for sticky/propagated claims
  • Loading branch information
Greybird committed Jan 6, 2018
1 parent 88160fc commit 4b7cbd2cf21d21b977103c0707336b773b864303
@@ -124,7 +124,7 @@ public final void doClaim(StaplerRequest req, StaplerResponse resp)
if (StringUtils.isEmpty(reasonProvided)) {
reasonProvided = null;
}
claim(claimedUser, reasonProvided, currentUser, sticky, propagated, true);
claim(claimedUser, reasonProvided, currentUser, new Date(), sticky, propagated, true);
this.getOwner().save();
evalGroovyScript();
resp.forwardToPreviousPage(req);
@@ -136,11 +136,11 @@ public final void doClaim(StaplerRequest req, StaplerResponse resp)
* @param providedReason reason for the claim
* @param assignedByUser name of the assigned user
* @param isSticky true if the claim has to be kept until resolution
* @deprecated use {@link #claim(String, String, String, boolean, boolean, boolean)}
* @deprecated use {@link #claim(String, String, String, Date, boolean, boolean, boolean)}
*/
@Deprecated
public final void claim(String claimedByUser, String providedReason, String assignedByUser, boolean isSticky) {
claim(claimedByUser, providedReason, assignedByUser, isSticky,
claim(claimedByUser, providedReason, assignedByUser, new Date(), isSticky,
ClaimConfig.get().isPropagateToFollowingBuildsByDefault(), false);
}

@@ -149,13 +149,14 @@ public final void claim(String claimedByUser, String providedReason, String assi
* @param claimedByUser name of the claiming user
* @param providedReason reason for the claim
* @param assignedByUser name of the assigner user
* @param date date of the claim
* @param isSticky true if the claim has to be kept until resolution
* @param isPropagated true if the claim has to be propagated to following builds
* @param notify true if notifications have to be sent
*/
public final void claim(String claimedByUser, String providedReason, String assignedByUser, boolean isSticky,
boolean isPropagated, boolean notify) {
applyClaim(claimedByUser, providedReason, assignedByUser, isSticky, isPropagated);
public final void claim(String claimedByUser, String providedReason, String assignedByUser, Date date,
boolean isSticky, boolean isPropagated, boolean notify) {
applyClaim(claimedByUser, providedReason, assignedByUser, date, isSticky, isPropagated);
if (notify) {
try {
ClaimEmailer.sendEmailIfConfigured(
@@ -177,21 +178,22 @@ public final void claim(String claimedByUser, String providedReason, String assi
* @param claimedByUser name of the claiming user
* @param providedReason reason for the claim
* @param assignedByUser name of the assigner user
* @param date date of the claim
* @param isSticky true if the claim has to be kept until resolution
* @param isPropagated true if the claim has to be propagated to following builds
*/
protected void applyClaim(String claimedByUser, String providedReason, String assignedByUser, boolean isSticky,
boolean isPropagated) {
protected void applyClaim(String claimedByUser, String providedReason, String assignedByUser, Date date,
boolean isSticky, boolean isPropagated) {
this.claimed = true;
this.claimedBy = claimedByUser;
this.reason = providedReason;
this.transientClaim = !isSticky;
this.claimDate = new Date();
this.claimDate = date;
this.assignedBy = assignedByUser;
if (isPropagated) {
getNextAction().ifPresent(action -> {
if (!action.isClaimed()) {
action.applyClaim(claimedByUser, providedReason, assignedByUser, isSticky, true);
action.applyClaim(claimedByUser, providedReason, assignedByUser, date, isSticky, true);
try {
action.getOwner().save();
} catch (IOException e) {
@@ -298,7 +300,7 @@ public final boolean isClaimed() {
* @param other the source data
*/
protected void copyTo(AbstractClaimBuildAction<T> other) {
other.applyClaim(getClaimedBy(), getReason(), getAssignedBy(), isSticky(), false);
other.applyClaim(getClaimedBy(), getReason(), getAssignedBy(), getClaimDate(), isSticky(), false);
}

public final boolean isClaimedByMe() {
@@ -5,6 +5,7 @@
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.test.TestResult;

import java.util.Date;
import java.util.Optional;

public final class ClaimTestAction extends AbstractClaimBuildAction<Run> {
@@ -22,10 +23,10 @@ public String getDisplayName() {
}

@Override
protected void applyClaim(String claimedByUser, String providedReason, String assignedByUser, boolean isSticky,
boolean isPropagated) {
protected void applyClaim(String claimedByUser, String providedReason, String assignedByUser, Date date,
boolean isSticky, boolean isPropagated) {
data.addClaim(testObjectId, this);
super.applyClaim(claimedByUser, providedReason, assignedByUser, isSticky, isPropagated);
super.applyClaim(claimedByUser, providedReason, assignedByUser, date, isSticky, isPropagated);
}

@Override
@@ -46,6 +46,8 @@
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;

import java.util.Date;

public class ClaimTest {

@Rule
@@ -141,17 +143,21 @@ public void claimCanBeReassigned() throws Exception {

@Test
public void stickyClaimPropagatesToNextBuild() throws Exception {
final int waitTime = 2_000;
// Given:
givenBuildClaimedByCurrentUser(firstBuild);
// When:
Thread.sleep(waitTime);
Build<?, ?> nextBuild = project.scheduleBuild2(0).get();
// Then:
ClaimBuildAction action = firstBuild.getAction(ClaimBuildAction.class);
ClaimBuildAction action2 = nextBuild.getAction(ClaimBuildAction.class);
assertThat(action2.isClaimed(), is(true));
assertThat(action2.getClaimedBy(), is("user1"));
assertThat(action2.getReason(), is("reason"));
assertThat(action2.isSticky(), is(true));
assertThat(action2.getAssignedBy(), is("user1"));
assertThat(action2.getClaimDate(), is(action.getClaimDate()));
}

@Test
@@ -161,7 +167,7 @@ public void stickyClaimOnPreviousBuildPropagatesToFollowingFailedBuilds() throw
Build<?, ?> thirdBuild = project.scheduleBuild2(0).get();
Build<?, ?> fourthBuild = project.scheduleBuild2(0).get();
// When:
whenAssigningBuildByClicking(firstBuild, "claim", true);
ClaimBuildAction firstAction = whenAssigningBuildByClicking(firstBuild, "claim", true);
// Then:
ClaimBuildAction[] actions = new ClaimBuildAction[] {
secondBuild.getAction(ClaimBuildAction.class),
@@ -174,6 +180,7 @@ public void stickyClaimOnPreviousBuildPropagatesToFollowingFailedBuilds() throw
assertThat(action.getReason(), is(claimText));
assertThat(action.isSticky(), is(true));
assertThat(action.getAssignedBy(), is("user1"));
assertThat(action.getClaimDate(), is(firstAction.getClaimDate()));
}
}

@@ -186,7 +193,7 @@ public void stickyClaimOnPreviousBuildPropagatesToFollowingFailedBuildsUntilBuil
givenProjectIsFailing();
Build<?, ?> fourthBuild = project.scheduleBuild2(0).get();
// When:
whenAssigningBuildByClicking(firstBuild, "claim", true);
ClaimBuildAction action1 = whenAssigningBuildByClicking(firstBuild, "claim", true);
// Then:
ClaimBuildAction action2 = secondBuild.getAction(ClaimBuildAction.class);
ClaimBuildAction action3 = thirdBuild.getAction(ClaimBuildAction.class);
@@ -196,26 +203,31 @@ public void stickyClaimOnPreviousBuildPropagatesToFollowingFailedBuildsUntilBuil
assertThat(action2.getReason(), is(claimText));
assertThat(action2.isSticky(), is(true));
assertThat(action2.getAssignedBy(), is("user1"));
assertThat(action2.getClaimDate(), is(action1.getClaimDate()));
assertThat(action3, nullValue());
assertThat(action4.isClaimed(), is(false));
}

@Test
public void stickyClaimOnPreviousBuildPropagatesToFollowingFailedBuildsUntilBuildIsClaimed() throws Exception {
final int waitTime = 2_000;
// Given:
Build<?, ?> secondBuild = project.scheduleBuild2(0).get();
Build<?, ?> thirdBuild = project.scheduleBuild2(0).get();
Thread.sleep(waitTime);
whenClaimingBuildByClicking(thirdBuild, "claim");
// When:
whenAssigningBuildByClicking(firstBuild, "claim", true);
Thread.sleep(waitTime);
ClaimBuildAction action1 = whenAssigningBuildByClicking(firstBuild, "claim", true);
// Then:
ClaimBuildAction action2 = secondBuild.getAction(ClaimBuildAction.class);
ClaimBuildAction action3 = thirdBuild.getAction(ClaimBuildAction.class);
assertThat(action2.isClaimed(), is(true));
assertThat(action2.isClaimed(), is(true));
assertThat(action2.getClaimedBy(), is("user2"));
assertThat(action2.getReason(), is(claimText));
assertThat(action2.isSticky(), is(true));
assertThat(action2.getAssignedBy(), is("user1"));
assertThat(action2.getClaimDate(), is(action1.getClaimDate()));
assertThat(action3.isClaimed(), is(true));
assertThat(action3.getClaimedBy(), is("user1"));
assertThat(action3.getReason(), is(claimText));
@@ -246,13 +258,15 @@ public void nonStickyClaimDoesNotPropagateToNextBuild() throws Exception {

private ClaimBuildAction givenBuildClaimedByOtherUser(Build<?, ?> build) {
ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
action.claim("user2", "reason", "user1", true);
action.claim("user2", "reason", "user1", new Date(), true,
false, false);
return action;
}

private ClaimBuildAction givenBuildClaimedByCurrentUser(Build<?, ?> build) {
ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
action.claim("user1", "reason", "user1", true);
action.claim("user1", "reason", "user1", new Date(), true,
false, false);
return action;
}

0 comments on commit 4b7cbd2

Please sign in to comment.