diff options
author | Dave Borowitz <dborowitz@google.com> | 2015-12-07 15:50:12 -0500 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2016-06-24 09:54:07 +0900 |
commit | f8d957ea634cd05522bbb47c0a8a4049949dc8cb (patch) | |
tree | 244431c51cfccea3761e364d165becb16e123c32 | |
parent | bd5fdc3d29038058c04b1242f53f68c9f8846fe3 (diff) |
CreateChangeIT: Fix flaky test
This test was occasionally failing with "Not found" on the new change.
After the previous commit, it became clear that this was multiple
changes with the same Change-Id (as opposed to a Lucene indexing
race, which would have been harder to track down):
FAILURE com.google.gerrit.acceptance.rest.change.CreateChangeIT createNewChange: Multiple changes found for I456d43543ea95b7b39ea3ebc5150db2493efc943
com.google.gerrit.extensions.restapi.ResourceNotFoundException: Multiple changes found for I456d43543ea95b7b39ea3ebc5150db2493efc943
at com.google.gerrit.server.change.ChangesCollection.parse(ChangesCollection.java:99)
at com.google.gerrit.server.api.changes.ChangesImpl.create(ChangesImpl.java:96)
at com.google.gerrit.acceptance.rest.change.CreateChangeIT.assertCreateSucceeds(CreateChangeIT.java:94)
at com.google.gerrit.acceptance.rest.change.CreateChangeIT.createNewChange(CreateChangeIT.java:66)
The reason for this is that the computed Change-Id in CreateChange
only takes into account the current branch tip, subject, and author.
In CreateChangeIT, the branch tip is the same (nonexistent) and the
subject is a constant, meaning if the tests run fast enough, the
timestamp is the same as well.
Fix this by setting the current millis provider as in some other
tests.
Change-Id: Ifc6d478f8bd633a1996c8352869ffb670ca32325
-rw-r--r-- | gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java index d0bcfd96b4..9edf9b2d27 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/CreateChangeIT.java @@ -16,6 +16,7 @@ package com.google.gerrit.acceptance.rest.change; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.TruthJUnit.assume; +import static java.util.concurrent.TimeUnit.SECONDS; import com.google.common.collect.Iterables; import com.google.gerrit.acceptance.AbstractDaemonTest; @@ -26,8 +27,11 @@ import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.MethodNotAllowedException; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.testutil.ConfigSuite; +import com.google.gerrit.testutil.TestTimeUtil; import org.eclipse.jgit.lib.Config; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; @NoHttpd @@ -37,6 +41,17 @@ public class CreateChangeIT extends AbstractDaemonTest { return allowDraftsDisabledConfig(); } + @BeforeClass + public static void setTimeForTesting() { + TestTimeUtil.resetWithClockStep(1, SECONDS); + } + + @AfterClass + public static void restoreTime() { + TestTimeUtil.useSystemTime(); + } + + @Test public void createEmptyChange_MissingBranch() throws Exception { ChangeInfo ci = new ChangeInfo(); |