Skip to content

Commit

Permalink
[JENKINS-26718] Allow runs to be discarded even if their project can'…
Browse files Browse the repository at this point in the history
…t be found by its fullname

(cherry picked from commit 327f778)
  • Loading branch information
recampbell authored and olivergondza committed Mar 30, 2015
1 parent dc68946 commit 5ed111f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/hudson/diagnosis/OldDataMonitor.java
Expand Up @@ -355,10 +355,12 @@ private interface SaveableReference {

private static SaveableReference referTo(Saveable s) {
if (s instanceof Run) {
return new RunSaveableReference((Run) s);
} else {
return new SimpleSaveableReference(s);
Job parent = ((Run) s).getParent();
if (Jenkins.getInstance().getItemByFullName(parent.getFullName()) == parent) {
return new RunSaveableReference((Run) s);
}
}
return new SimpleSaveableReference(s);
}

private static final class SimpleSaveableReference implements SaveableReference {
Expand Down
22 changes: 22 additions & 0 deletions test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java
Expand Up @@ -41,11 +41,16 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import jenkins.model.Jenkins;
import jenkins.model.lazy.BuildReference;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -56,6 +61,8 @@
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.Stapler;

import javax.annotation.Nonnull;

public class OldDataMonitorTest {

static {
Expand Down Expand Up @@ -149,6 +156,21 @@ public Void call() throws Exception {

}

@Issue("JENKINS-26718")
@Test public void unlocatableRun() throws Exception {
OldDataMonitor odm = OldDataMonitor.get(r.jenkins);
FreeStyleProject p = mock(FreeStyleProject.class);
when(p.getParent()).thenReturn(Jenkins.getInstance());
when(p.getFullName()).thenReturn("notfound");
FreeStyleBuild build = new FreeStyleBuild(p);
odm.report(build, (String) null);

assertEquals(Collections.singleton(build), odm.getData().keySet());
odm.doDiscard(null, null);
assertEquals(Collections.emptySet(), odm.getData().keySet());

}

public static final class BadAction extends InvisibleAction {
private Object writeReplace() {
throw new IllegalStateException("broken");
Expand Down

0 comments on commit 5ed111f

Please sign in to comment.