Browse Source

Fixed instability in some GC tests.

Some GC tests were sporadically failing. The reason was that they used
the setExpireAgeMillis method to define object expiration before
invoking the prune method. Depending on the CPU load during the test
run, the prune method may reach an object (which is considered
non-expired by the test) too late and actually prune it.

To make the test stable we now use the setExpire(Date expire) method and
define a time instant before which objects are considered to be expired.
This way the outcome of the prune method doesn't depend on the CPU load.

Change-Id: Ifc3323ca55ae56dbccdbc90a282ec3cf18ad7297
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
stable-2.2
Sasa Zivkov 12 years ago
parent
commit
87346556d3
  1. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/GCTest.java

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/GCTest.java

@ -51,6 +51,7 @@ import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -66,6 +67,7 @@ import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder; import org.eclipse.jgit.junit.TestRepository.BranchBuilder;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.junit.TestRepository.CommitBuilder; import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.EmptyProgressMonitor; import org.eclipse.jgit.lib.EmptyProgressMonitor;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
@ -291,12 +293,8 @@ public class GCTest extends LocalDiskRepositoryTestCase {
@Test @Test
public void nonReferencedNonExpiredObject_notPruned() throws Exception { public void nonReferencedNonExpiredObject_notPruned() throws Exception {
long start = now();
fsTick();
RevBlob a = tr.blob("a"); RevBlob a = tr.blob("a");
long delta = now() - start; gc.setExpire(new Date(lastModified(a)));
gc.setExpireAgeMillis(delta);
gc.prune(Collections.<ObjectId> emptySet()); gc.prune(Collections.<ObjectId> emptySet());
assertTrue(repo.hasObject(a)); assertTrue(repo.hasObject(a));
} }
@ -322,13 +320,11 @@ public class GCTest extends LocalDiskRepositoryTestCase {
@Test @Test
public void nonReferencedObjects_onlyExpiredPruned() throws Exception { public void nonReferencedObjects_onlyExpiredPruned() throws Exception {
RevBlob a = tr.blob("a"); RevBlob a = tr.blob("a");
gc.setExpire(new Date(lastModified(a) + 1));
fsTick();
long start = now();
fsTick(); fsTick();
RevBlob b = tr.blob("b"); RevBlob b = tr.blob("b");
gc.setExpireAgeMillis(now() - start);
gc.prune(Collections.<ObjectId> emptySet()); gc.prune(Collections.<ObjectId> emptySet());
assertFalse(repo.hasObject(a)); assertFalse(repo.hasObject(a));
assertTrue(repo.hasObject(b)); assertTrue(repo.hasObject(b));
@ -700,8 +696,8 @@ public class GCTest extends LocalDiskRepositoryTestCase {
return tip; return tip;
} }
private static long now() { private long lastModified(AnyObjectId objectId) {
return System.currentTimeMillis(); return repo.getObjectDatabase().fileFor(objectId).lastModified();
} }
private static void fsTick() throws InterruptedException, IOException { private static void fsTick() throws InterruptedException, IOException {

Loading…
Cancel
Save