diff options
author | Nail Samatov <sanail@yandex.ru> | 2021-09-15 21:00:59 +0300 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-01-30 17:16:02 -0500 |
commit | 2b01ac3389c11be88ec875048d6a2cc4ed6903f1 (patch) | |
tree | 9891d1d9df4bb21a6646bebc79dad27caff37960 /org.eclipse.jgit.test/tst/org/eclipse/jgit/transport | |
parent | 8633ea4f07cbe10706a9edd1301f13aebe5be942 (diff) | |
download | jgit-2b01ac3389c11be88ec875048d6a2cc4ed6903f1.tar.gz jgit-2b01ac3389c11be88ec875048d6a2cc4ed6903f1.zip |
[test] Fix closing of test repositories
Fix tests failing on Windows because Repository instance is created but
not closed on tear down.
Fix repositories closed twice, except in tests that test this behavior
explicitly.
Name the temporary directories the tests run in after the test method;
that makes it easier to figure out in which tests repositories are
closed twice if it should occur again in the future.
Bug: 550111
Change-Id: I9398b58f0f36d2c29236d2a9a8599117d9083980
Signed-off-by: Nail Samatov <sanail@yandex.ru>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/transport')
3 files changed, 20 insertions, 9 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index 054eb9c5ad..bb62a0d892 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -80,6 +80,7 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase { // Then we clone a new repo from that bundle and do a simple test. This // makes sure we could read the bundle we created. Repository newRepo = createBareRepository(); + addRepoToClose(newRepo); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Ref advertisedRef = fetchResult .getAdvertisedRef("refs/heads/firstcommit"); @@ -116,6 +117,7 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase { // makes sure // we could read the bundle we created. Repository newRepo = createBareRepository(); + addRepoToClose(newRepo); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Ref advertisedRef = fetchResult.getAdvertisedRef("refs/heads/aa"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java index 60b8098b31..93bedb3c97 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java @@ -110,6 +110,7 @@ public class PackParserTest extends RepositoryTestCase { public void testTinyThinPack() throws Exception { RevBlob a; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); a = d.blob("a"); } @@ -132,6 +133,7 @@ public class PackParserTest extends RepositoryTestCase { public void testPackWithDuplicateBlob() throws Exception { final byte[] data = Constants.encode("0123456789abcdefg"); try (TestRepository<Repository> d = new TestRepository<>(db)) { + db.incrementOpen(); assertTrue(db.getObjectDatabase().has(d.blob(data))); } @@ -151,6 +153,7 @@ public class PackParserTest extends RepositoryTestCase { public void testPackWithTrailingGarbage() throws Exception { RevBlob a; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); a = d.blob("a"); } @@ -180,6 +183,7 @@ public class PackParserTest extends RepositoryTestCase { public void testMaxObjectSizeFullBlob() throws Exception { final byte[] data = Constants.encode("0123456789"); try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); d.blob(data); } @@ -213,6 +217,7 @@ public class PackParserTest extends RepositoryTestCase { public void testMaxObjectSizeDeltaBlock() throws Exception { RevBlob a; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); a = d.blob("a"); } @@ -246,6 +251,7 @@ public class PackParserTest extends RepositoryTestCase { public void testMaxObjectSizeDeltaResultSize() throws Exception { RevBlob a; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); a = d.blob("0123456789"); } @@ -278,6 +284,7 @@ public class PackParserTest extends RepositoryTestCase { public void testNonMarkingInputStream() throws Exception { RevBlob a; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); a = d.blob("a"); } @@ -318,6 +325,7 @@ public class PackParserTest extends RepositoryTestCase { public void testDataAfterPackFooterSingleRead() throws Exception { RevBlob a; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); a = d.blob("a"); } @@ -379,6 +387,7 @@ public class PackParserTest extends RepositoryTestCase { final byte[] data = Constants.encode("a"); RevBlob b; try (TestRepository d = new TestRepository<Repository>(db)) { + db.incrementOpen(); b = d.blob(data); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java index d1e5446827..a91bc95c8d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java @@ -73,11 +73,14 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas super.setUp(); src = createBareRepository(); + addRepoToClose(src); dst = createBareRepository(); + addRepoToClose(dst); // Fill dst with a some common history. // try (TestRepository<Repository> d = new TestRepository<>(dst)) { + dst.incrementOpen(); a = d.blob("a"); A = d.commit(d.tree(d.file("a", a))); B = d.commit().parent(A).create(); @@ -106,9 +109,6 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas dst.getDirectory()) { @Override ReceivePack createReceivePack(Repository db) { - db.close(); - dst.incrementOpen(); - final ReceivePack rp = super.createReceivePack(dst); rp.setAdvertiseRefsHook(new HidePrivateHook()); return rp; @@ -136,8 +136,6 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas dst.getDirectory()) { @Override ReceivePack createReceivePack(Repository db) { - dst.incrementOpen(); - ReceivePack rp = super.createReceivePack(dst); rp.setAdvertiseRefsHook(new AdvertiseRefsHook() { @Override @@ -173,9 +171,6 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas return new TransportLocal(src, uriOf(dst), dst.getDirectory()) { @Override ReceivePack createReceivePack(Repository db) { - db.close(); - dst.incrementOpen(); - final ReceivePack rp = super.createReceivePack(dst); rp.setCheckReceivedObjects(true); rp.setCheckReferencedObjectsAreReachable(true); @@ -211,6 +206,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas // Now use b but in a different commit than what is hidden. // try (TestRepository<Repository> s = new TestRepository<>(src)) { + src.incrementOpen(); RevCommit N = s.commit().parent(B).add("q", b).create(); s.update(R_MASTER, N); @@ -228,7 +224,6 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas try (TransportLocal t = newTransportLocalWithStrictValidation()) { t.setPushThin(true); r = t.push(PM, Collections.singleton(u)); - dst.close(); } assertNotNull("have result", r); @@ -290,6 +285,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas public void testUsingHiddenDeltaBaseFails() throws Exception { byte[] delta = { 0x1, 0x1, 0x1, 'c' }; try (TestRepository<Repository> s = new TestRepository<>(src)) { + src.incrementOpen(); RevCommit N = s.commit().parent(B) .add("q", s.blob(BinaryDelta.apply( @@ -348,6 +344,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas // Try to use the 'b' blob that is hidden. // try (TestRepository<Repository> s = new TestRepository<>(src)) { + src.incrementOpen(); RevCommit N = s.commit().parent(B).add("q", s.blob("b")).create(); // But don't include it in the pack. @@ -401,6 +398,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas // Try to use the 'n' blob that is not on the server. // try (TestRepository<Repository> s = new TestRepository<>(src)) { + src.incrementOpen(); RevBlob n = s.blob("n"); RevCommit N = s.commit().parent(B).add("q", n).create(); @@ -491,6 +489,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas .toString(); try (TestRepository<Repository> s = new TestRepository<>(src)) { + src.incrementOpen(); RevBlob blob = s.blob(fakeGitmodules); RevCommit N = s.commit().parent(B).add(".gitmodules", blob) .create(); @@ -517,6 +516,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas @Test public void testUsingUnknownTreeFails() throws Exception { try (TestRepository<Repository> s = new TestRepository<>(src)) { + src.incrementOpen(); RevCommit N = s.commit().parent(B).add("q", s.blob("a")).create(); RevTree t = s.parseBody(N).getTree(); |