git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH] Fixed the test testUpdateRefLockFailureLocked broken on the Windows platform

From
CPConstantine Plotnikov <constantine.plotnikov@gmail.com>
Date
Jun 23, 2009, 12:01 UTC
Message-ID
<1245758495-2212-1-git-send-email-constantine.plotnikov@gmail.com>

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.

Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
 .../tst/org/spearce/jgit/lib/RefUpdateTest.java    |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java
index 6b1975a..b14f19a 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java
@@ -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();
+		}
 	}
 
 	/**
-- 
1.6.1.2
Message 1 of 1 in “Fixed the test testUpdateRefLockFailureLocked broken on the Windows platform”
  1. Fixed the test testUpdateRefLockFailureLocked broken on the Windows platformConstantine Plotnikov, Jun 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.