mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
[JENKINS-15156] Add regression test
This commit is contained in:
1 parent
41fc8a10bb
commit
dbd6b530e7
1 file changed
+46
@@ -47,6 +47,9 @@ import org.jvnet.hudson.test.recipes.PresetData.DataSet;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -280,4 +283,47 @@ public class AbstractProjectTest extends HudsonTestCase {
|
||||
assertSymlinkForBuild(lastSuccessful, 1);
|
||||
assertSymlinkForBuild(lastStable, 1);
|
||||
}
|
||||
|
||||
// Force garbage collection of ref's referent. Taken from NetBeans code.
|
||||
public static void forceGc(final Reference<?> ref) {
|
||||
ArrayList<byte[]> alloc = new ArrayList<byte[]>();
|
||||
int size = 100000;
|
||||
System.out.print("forcing garbage collection...");
|
||||
for (int i = 0; i < 50; i++) {
|
||||
if (ref.get() == null) {
|
||||
System.out.println("succeeded");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
} catch (OutOfMemoryError error) {
|
||||
// OK
|
||||
}
|
||||
try {
|
||||
alloc.add(new byte[size]);
|
||||
size = (int)(((double)size) * 1.3);
|
||||
} catch (OutOfMemoryError error) {
|
||||
size = size / 2;
|
||||
}
|
||||
try {
|
||||
if (i % 3 == 0) {
|
||||
Thread.sleep(321);
|
||||
}
|
||||
} catch (InterruptedException t) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
System.out.println("failed");
|
||||
}
|
||||
|
||||
@Bug(15156)
|
||||
public void testGetBuildAfterGc() throws Exception {
|
||||
FreeStyleProject job = createFreeStyleProject();
|
||||
job.scheduleBuild2(0, new Cause.UserCause()).get();
|
||||
// If this fails to garbage-collect, the test run will not have any value, but it will
|
||||
// at least not fail.
|
||||
forceGc(new WeakReference(job.getLastBuild()));
|
||||
assertTrue(job.getLastBuild() != null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user