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

[JGIT PATCH] Fixed RefUpdateTest.tryRenameWhenLocked() family of tests

From
CPConstantine Plotnikov <constantine.plotnikov@gmail.com>
Date
Jun 25, 2009, 13:38 UTC
Message-ID
<1245937087-5144-1-git-send-email-constantine.plotnikov@gmail.com>

If file is left locked after the test, the cleanup does not work on Windows since locked files cannot be deleted. The patch adds unlock for the aquired lock, so the cleanup now works.

Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
This is a second time the problem occurs. Please release all locks
that are being acquired, otherwise the tests will fail on Windows.
 
 .../tst/org/spearce/jgit/lib/RefUpdateTest.java    |   51 +++++++++++---------
 1 files changed, 28 insertions(+), 23 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 83eb4ed..ec00fac 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
@@ -463,29 +463,34 @@ assertTrue("internal check, we have a log", new File(db.getDirectory(),
 				"logs/" + fromName).exists());
 
 		// "someone" has branch X locked
-		assertTrue(new LockFile(new File(db.getDirectory(), toLock)).lock());
-
-		// Now this is our test
-		RefRename renameRef = db.renameRef(fromName, toName);
-		Result result = renameRef.rename();
-		assertEquals(Result.LOCK_FAILURE, result);
-
-		// Check that the involved refs are the same despite the failure
-		assertExists(false, toName);
-		if (!toLock.equals(toName))
-			assertExists(false, toName + ".lock");
-		assertExists(true, toLock + ".lock");
-		if (!toLock.equals(fromName))
-			assertExists(false, "logs/" + fromName + ".lock");
-		assertExists(false, "logs/" + toName + ".lock");
-		assertEquals(oldHeadId, db.resolve(Constants.HEAD));
-		assertEquals(oldfromId, db.resolve(fromName));
-		assertNull(db.resolve(toName));
-		assertEquals(oldFromLog.toString(), db.getReflogReader(fromName)
-				.getReverseEntries().toString());
-		if (oldHeadId != null)
-			assertEquals(oldHeadLog, db.getReflogReader(Constants.HEAD)
-					.getReverseEntries());
+		LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));
+		try {
+			assertTrue(lockFile.lock());
+
+			// Now this is our test
+			RefRename renameRef = db.renameRef(fromName, toName);
+			Result result = renameRef.rename();
+			assertEquals(Result.LOCK_FAILURE, result);
+	
+			// Check that the involved refs are the same despite the failure
+			assertExists(false, toName);
+			if (!toLock.equals(toName))
+				assertExists(false, toName + ".lock");
+			assertExists(true, toLock + ".lock");
+			if (!toLock.equals(fromName))
+				assertExists(false, "logs/" + fromName + ".lock");
+			assertExists(false, "logs/" + toName + ".lock");
+			assertEquals(oldHeadId, db.resolve(Constants.HEAD));
+			assertEquals(oldfromId, db.resolve(fromName));
+			assertNull(db.resolve(toName));
+			assertEquals(oldFromLog.toString(), db.getReflogReader(fromName)
+					.getReverseEntries().toString());
+			if (oldHeadId != null)
+				assertEquals(oldHeadLog, db.getReflogReader(Constants.HEAD)
+						.getReverseEntries());
+		} finally {
+			lockFile.unlock();
+		}
 	}
 
 	private void assertExists(boolean positive, String toName) {
-- 
1.6.1.2
Message 1 of 1 in “Fixed RefUpdateTest.tryRenameWhenLocked() family of tests”
  1. Fixed RefUpdateTest.tryRenameWhenLocked() family of testsConstantine Plotnikov, Jun 25, 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.