Skip to content
Permalink
Browse files
test reproducing issue JENKINS-33219.
  • Loading branch information
Lucie Votypkova committed Sep 11, 2017
1 parent 9284626 commit 04b3ea252810b413d324587ccb791a22b3aa7fef
@@ -13,6 +13,7 @@
import hudson.model.TopLevelItem;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
@@ -4,15 +4,28 @@
*/
package hudson.plugins.disk_usage.integration;

import hudson.EnvVars;
import hudson.model.FreeStyleBuild;
import hudson.model.Items;
import hudson.model.listeners.RunListener;
import hudson.plugins.disk_usage.BuildDiskUsageAction;
import hudson.plugins.disk_usage.DiskUsageBuildListener;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.tasks.Shell;
import java.io.File;
import java.io.IOException;

import hudson.FilePath;
import hudson.plugins.disk_usage.DiskUsageProperty;
import hudson.model.AbstractProject;
import org.junit.Test;
import jenkins.model.lazy.BuildReference;
import org.junit.*;
import hudson.model.FreeStyleProject;
import org.jvnet.hudson.reactor.ReactorException;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.junit.Rule;
import org.jvnet.hudson.test.recipes.LocalData;

import static org.junit.Assert.*;

/**
@@ -23,6 +36,15 @@

@Rule
public JenkinsRule j = new JenkinsRule();

@BeforeClass
public static void setEnvironmentVariables() throws IOException {
System.setProperty("jenkins.model.lazy.BuildReference.MODE", "weak");

System.setProperty("jenkins.test.timeout","10000");
System.setProperty("maven.surefire.debug","10000");
// j.jenkins.getGlobalNodeProperties().add(prop);
}

@Test
public void testOnDeleted() throws Exception{
@@ -39,6 +61,7 @@ public void testOnDeleted() throws Exception{

@Test
public void testOnCompleted() throws Exception{
j.timeout = 10000;
FreeStyleProject project = j.createFreeStyleProject();
project.getBuildersList().add(new Shell("echo ahoj > log.log"));
j.buildAndAssertSuccess(project);
@@ -47,4 +70,91 @@ public void testOnCompleted() throws Exception{
assertTrue("Build disk usage should be counted.", property.getDiskUsageOfBuild(1)>0);
assertTrue("Workspace of build should be counted.", property.getAllWorkspaceSize()>0);
}


@Issue("JENKINS-33219")
@Test(timeout = 10000000L)
@LocalData
public void testOnLoadCauseDeadLock() throws Exception {
j.timeout = 10000;
BuildReference.DefaultHolderFactory f = new BuildReference.DefaultHolderFactory();

FreeStyleProject p = (FreeStyleProject) j.jenkins.getItem("job");
final File file = p.getConfigFile().getFile().getParentFile();


System.err.println(p.getConfigFile().getFile().exists() + " " + p.getConfigFile().getFile().getAbsolutePath());
// j.buildAndAssertSuccess(project);
p.removeProperty(DiskUsageProperty.class);
final FreeStyleBuild build = p.getLastBuild();
System.err.println("holder " + f.make(build).getClass() + " builds is " + p.getBuilds().toArray().length);

p = (FreeStyleProject) j.jenkins.getItem("job");
System.err.println("loaded builds " + p._getRuns().getLoadedBuilds());
final DiskUsageBuildListener listener = RunListener.all().get(DiskUsageBuildListener.class);
Thread onLoad = new Thread(){

public void run(){
FreeStyleProject project = (FreeStyleProject) j.jenkins.getItem("job");
int count = 0;
while(count<50){
count++;
project = (FreeStyleProject) j.jenkins.getItem("job");
BuildDiskUsageAction action = new BuildDiskUsageAction(project.getBuildByNumber(106));
System.err.println("loadedBuilds " + project._getRuns().getLoadedBuilds());
try {


project = (FreeStyleProject) Items.load(j.jenkins, file);
synchronized(j.jenkins) {
j.jenkins.remove(project);
j.jenkins.putItem(project);
}
project.getProperty(DiskUsageProperty.class).getDiskUsage().getConfigFile().delete();
project.removeProperty(DiskUsageProperty.class);
} catch (Exception e) {
e.printStackTrace();
}

System.err.println("thread onLoad done, cycle left " + count + " loaded builds " + project._getRuns().getLoadedBuilds());


}


}
};
Thread nextBuildNumber = new Thread(){

public void run(){

int count = 0;
FreeStyleProject project = (FreeStyleProject) j.jenkins.getItem("job");
while(count<50) {
count++;
try {
project = (FreeStyleProject) j.jenkins.getItem("job");
project.updateNextBuildNumber(107 + count);
project = (FreeStyleProject) Items.load(j.jenkins, file);
synchronized (j.jenkins) {
j.jenkins.remove(project);
j.jenkins.putItem(project);
}
project.getProperty(DiskUsageProperty.class).getDiskUsage().getConfigFile().delete();
project.removeProperty(DiskUsageProperty.class);
} catch (Exception e) {
e.printStackTrace();
}
System.err.println("loadedBuilds2 " + project._getRuns().getLoadedBuilds());

System.err.println("thread nextBuildNumber done, cycle left " + count + " loaded builds " + project._getRuns().getLoadedBuilds());
}

}
};
onLoad.start();
nextBuildNumber.start();
onLoad.join();
nextBuildNumber.join();
}
}

0 comments on commit 04b3ea2

Please sign in to comment.