diff test/org/tmatesoft/hg/test/TestCommit.java @ 623:fedc54356091

Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 May 2013 18:35:13 +0200
parents 99ad1e3a4e4d
children 507602cb4fb3
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestCommit.java	Mon May 20 16:56:40 2013 +0200
+++ b/test/org/tmatesoft/hg/test/TestCommit.java	Mon May 20 18:35:13 2013 +0200
@@ -380,7 +380,19 @@
 	
 	@Test
 	public void testRollback() throws Exception {
-		File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-rollback", false);
+		// Important: copy, not a clone of a repo to ensure old timestamps
+		// on repository files. Otherwise, there're chances transacition.rollback()
+		// would happen the very second (when fs timestamp granularity is second)
+		// repository got cloned, and RevlogChangeMonitor won't notice the file change
+		// (timestamp is the same, file size increased (CommitFacility) and decreased
+		// on rollback back to memorized value), and subsequent hgRepo access would fail
+		// trying to read more (due to Revlog#revisionAdded) revisions than there are in 
+		// the store file. 
+		// With copy and original timestamps we pretend commit happens to an existing repository
+		// in a regular manner (it's unlikely to have commits within the same second in a real life)
+		// XXX Note, once we have more robust method to detect file changes (e.g. Java7), this
+		// approach shall be abandoned.
+		File repoLoc = RepoUtils.copyRepoToTempLocation("log-1", "test-commit-rollback");
 		final Path newFilePath = Path.create("xx");
 		final File newFile = new File(repoLoc, newFilePath.toString());
 		RepoUtils.createFile(newFile, "xyz");
@@ -411,11 +423,6 @@
 		cf.branch("another-branch");
 		Transaction tr = newTransaction(hgRepo);
 		Nodeid commitRev = cf.commit("Commit to fail",  tr);
-		// with 1 second timestamp granularity, HgChangelog doesn't 
-		// recognize the fact the underlying file got changed twice within
-		// a second, doesn't discard new revision obtained via revisionAdded,
-		// and eventually fails trying to read more revisions than there're in the file
-		Thread.sleep(1000); // FIXME this is a hack to make test pass
 		tr.rollback();
 		//
 		errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision());