Skip to contentSkip to conversation

Fixed the test testUpdateRefLockFailureLocked broken on the Windows platform

PATCH New Constantine Plotnikov 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixed the test testUpdateRefLockFailureLocked broken on the Windows platform

On Windows the lock is aquired in the test testUpdateRefLockFailureLocked (RefUpdateTest) for the file but it never released. This causes test failure during resource cleanup, since locked file could not be deleted on Windows. This commits adds unlock operation in the finally block, so there is no more cleanup problem.

---
 .../tst/org/spearce/jgit/lib/RefUpdateTest.java    |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java +10 -6
index 6b1975a..b14f19a 100644
@@ -255,12 +255,16 @@ public void testUpdateRefLockFailureLocked() throws IOException {
 		RefUpdate updateRef = db.updateRef("refs/heads/master");
 		updateRef.setNewObjectId(pid);
 		LockFile lockFile1 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
-		assertTrue(lockFile1.lock()); // precondition to test
-		Result update = updateRef.update();
-		assertEquals(Result.LOCK_FAILURE, update);
-		assertEquals(opid, db.resolve("refs/heads/master"));
-		LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
-		assertFalse(lockFile2.lock()); // was locked, still is
+		try {
+			assertTrue(lockFile1.lock()); // precondition to test
+			Result update = updateRef.update();
+			assertEquals(Result.LOCK_FAILURE, update);
+			assertEquals(opid, db.resolve("refs/heads/master"));
+			LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
+			assertFalse(lockFile2.lock()); // was locked, still is
+		} finally {
+			lockFile1.unlock();
+		}
 	}
 
 	/**
Signature · 1 line
1.6.1.2