diff options
| author | HÃ¥vard Haugen <havard.haugen@gmail.com> | 2015-05-12 09:37:22 +0200 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2015-05-13 02:01:05 +0000 |
| commit | 6fe36b1731a93d7a2e092357415855e7e942d1c5 (patch) | |
| tree | 6d1c8c4cebdf5818ee43bce10fbba2f5bea805cb | |
| parent | 03efa21267702524f5855fc842515cc6216b5408 (diff) | |
| download | go-x-review-6fe36b1731a93d7a2e092357415855e7e942d1c5.tar.xz | |
git-codereview: deflake TestSyncRebase
In order to guarantee different hashes on "client" and "server" we need to generate different
commit histories.
Fixes golang/go#10048.
Updates golang/go#9602.
Change-Id: I511f517639230d7aca74b3d2ce3bfa6a2c299a5c
Reviewed-on: https://go-review.googlesource.com/9951
Reviewed-by: Andrew Gerrand <adg@golang.org>
| -rw-r--r-- | git-codereview/sync_test.go | 4 | ||||
| -rw-r--r-- | git-codereview/util_test.go | 41 |
2 files changed, 27 insertions, 18 deletions
diff --git a/git-codereview/sync_test.go b/git-codereview/sync_test.go index 2f7318d..88461b3 100644 --- a/git-codereview/sync_test.go +++ b/git-codereview/sync_test.go @@ -73,8 +73,10 @@ func TestSyncRebase(t *testing.T) { t.Fatalf("CL hashes changed during no-op sync") } - // submit first two CLs - gt.serverWork does same thing gt.work does, but on client + // submit first two CLs - gt.serverWork does same thing gt.work does, but on server + gt.serverWork(t) + gt.serverWorkUnrelated(t) // wedge in unrelated work to get different hashes gt.serverWork(t) testMain(t, "sync") diff --git a/git-codereview/util_test.go b/git-codereview/util_test.go index 034d052..8c0d924 100644 --- a/git-codereview/util_test.go +++ b/git-codereview/util_test.go @@ -26,6 +26,7 @@ type gitTest struct { client string // client repo root nwork int // number of calls to work method nworkServer int // number of calls to serverWork method + nworkOther int // number of calls to serverWorkUnrelated method } // resetReadOnlyFlagAll resets windows read-only flag @@ -61,6 +62,18 @@ func (gt *gitTest) done() { os.RemoveAll(gt.tmpdir) } +// doWork simulates commit 'n' touching 'file' in 'dir' +func doWork(t *testing.T, n int, dir, file, changeid string) { + write(t, dir+"/"+file, fmt.Sprintf("new content %d", n)) + trun(t, dir, "git", "add", file) + suffix := "" + if n > 1 { + suffix = fmt.Sprintf(" #%d", n) + } + msg := fmt.Sprintf("msg%s\n\nChange-Id: I%d%s\n", suffix, n, changeid) + trun(t, dir, "git", "commit", "-m", msg) +} + func (gt *gitTest) work(t *testing.T) { if gt.nwork == 0 { trun(t, gt.client, "git", "checkout", "-b", "work") @@ -70,29 +83,23 @@ func (gt *gitTest) work(t *testing.T) { // make local change on client gt.nwork++ - write(t, gt.client+"/file", fmt.Sprintf("new content %d", gt.nwork)) - trun(t, gt.client, "git", "add", "file") - suffix := "" - if gt.nwork > 1 { - suffix = fmt.Sprintf(" #%d", gt.nwork) - } - trun(t, gt.client, "git", "commit", "-m", fmt.Sprintf("msg%s\n\nChange-Id: I%d23456789\n", suffix, gt.nwork)) + doWork(t, gt.nwork, gt.client, "file", "23456789") } func (gt *gitTest) serverWork(t *testing.T) { // make change on server - // duplicating the changes of gt.work to simulate them - // having gone through Gerrit and submitted with - // different times and commit hashes but the same content. + // duplicating the sequence of changes in gt.work to simulate them + // having gone through Gerrit and submitted with possibly + // different commit hashes but the same content. gt.nworkServer++ - write(t, gt.server+"/file", fmt.Sprintf("new content %d", gt.nworkServer)) - trun(t, gt.server, "git", "add", "file") - suffix := "" - if gt.nworkServer > 1 { - suffix = fmt.Sprintf(" #%d", gt.nworkServer) - } - trun(t, gt.server, "git", "commit", "-m", fmt.Sprintf("msg%s\n\nChange-Id: I%d23456789\n", suffix, gt.nworkServer)) + doWork(t, gt.nworkServer, gt.server, "file", "23456789") +} +func (gt *gitTest) serverWorkUnrelated(t *testing.T) { + // make unrelated change on server + // this makes history different on client and server + gt.nworkOther++ + doWork(t, gt.nworkOther, gt.server, "otherfile", "9999") } func newGitTest(t *testing.T) (gt *gitTest) { |
