{"thread":{"id":"19928","subject":"[JGIT PATCH] Fixed RefUpdateTest.tryRenameWhenLocked() family of tests","startedAt":"2009-06-25T13:38:07Z","lastAt":"2009-06-25T13:38:07Z","messageCount":1,"participants":["Constantine Plotnikov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"116935","messageId":"1245937087-5144-1-git-send-email-constantine.plotnikov@gmail.com","threadId":"19928","inReplyTo":null,"subject":"[JGIT PATCH] Fixed RefUpdateTest.tryRenameWhenLocked() family of tests","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-06-25T13:38:07Z","receivedAt":"2009-06-25T13:38:07Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"If file is left locked after the test, the cleanup does\nnot work on Windows since locked files cannot be deleted. \nThe patch adds unlock for the aquired lock, so the cleanup \nnow works.\n\nSigned-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n---\nThis is a second time the problem occurs. Please release all locks\nthat are being acquired, otherwise the tests will fail on Windows.\n \n .../tst/org/spearce/jgit/lib/RefUpdateTest.java    |   51 +++++++++++---------\n 1 files changed, 28 insertions(+), 23 deletions(-)\n\ndiff --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\nindex 83eb4ed..ec00fac 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java\n@@ -463,29 +463,34 @@ assertTrue(\"internal check, we have a log\", new File(db.getDirectory(),\n \t\t\t\t\"logs/\" + fromName).exists());\n \n \t\t// \"someone\" has branch X locked\n-\t\tassertTrue(new LockFile(new File(db.getDirectory(), toLock)).lock());\n-\n-\t\t// Now this is our test\n-\t\tRefRename renameRef = db.renameRef(fromName, toName);\n-\t\tResult result = renameRef.rename();\n-\t\tassertEquals(Result.LOCK_FAILURE, result);\n-\n-\t\t// Check that the involved refs are the same despite the failure\n-\t\tassertExists(false, toName);\n-\t\tif (!toLock.equals(toName))\n-\t\t\tassertExists(false, toName + \".lock\");\n-\t\tassertExists(true, toLock + \".lock\");\n-\t\tif (!toLock.equals(fromName))\n-\t\t\tassertExists(false, \"logs/\" + fromName + \".lock\");\n-\t\tassertExists(false, \"logs/\" + toName + \".lock\");\n-\t\tassertEquals(oldHeadId, db.resolve(Constants.HEAD));\n-\t\tassertEquals(oldfromId, db.resolve(fromName));\n-\t\tassertNull(db.resolve(toName));\n-\t\tassertEquals(oldFromLog.toString(), db.getReflogReader(fromName)\n-\t\t\t\t.getReverseEntries().toString());\n-\t\tif (oldHeadId != null)\n-\t\t\tassertEquals(oldHeadLog, db.getReflogReader(Constants.HEAD)\n-\t\t\t\t\t.getReverseEntries());\n+\t\tLockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));\n+\t\ttry {\n+\t\t\tassertTrue(lockFile.lock());\n+\n+\t\t\t// Now this is our test\n+\t\t\tRefRename renameRef = db.renameRef(fromName, toName);\n+\t\t\tResult result = renameRef.rename();\n+\t\t\tassertEquals(Result.LOCK_FAILURE, result);\n+\t\n+\t\t\t// Check that the involved refs are the same despite the failure\n+\t\t\tassertExists(false, toName);\n+\t\t\tif (!toLock.equals(toName))\n+\t\t\t\tassertExists(false, toName + \".lock\");\n+\t\t\tassertExists(true, toLock + \".lock\");\n+\t\t\tif (!toLock.equals(fromName))\n+\t\t\t\tassertExists(false, \"logs/\" + fromName + \".lock\");\n+\t\t\tassertExists(false, \"logs/\" + toName + \".lock\");\n+\t\t\tassertEquals(oldHeadId, db.resolve(Constants.HEAD));\n+\t\t\tassertEquals(oldfromId, db.resolve(fromName));\n+\t\t\tassertNull(db.resolve(toName));\n+\t\t\tassertEquals(oldFromLog.toString(), db.getReflogReader(fromName)\n+\t\t\t\t\t.getReverseEntries().toString());\n+\t\t\tif (oldHeadId != null)\n+\t\t\t\tassertEquals(oldHeadLog, db.getReflogReader(Constants.HEAD)\n+\t\t\t\t\t\t.getReverseEntries());\n+\t\t} finally {\n+\t\t\tlockFile.unlock();\n+\t\t}\n \t}\n \n \tprivate void assertExists(boolean positive, String toName) {\n-- \n1.6.1.2\n"}]}