diff options
| author | HÃ¥vard Haugen <havard.haugen@gmail.com> | 2015-04-23 23:59:36 +0200 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2015-05-11 04:19:29 +0000 |
| commit | dd3919343ed6ab8cad672c16b8c2a514615d9c4e (patch) | |
| tree | 5f706b432597f279fd3eb9acd0173e4fd016b9e8 | |
| parent | af3758ca538112730b99a2ebb005eefba171b9a8 (diff) | |
| download | go-x-review-dd3919343ed6ab8cad672c16b8c2a514615d9c4e.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: I42a50dc890598dd3a3b6c626c6db70ffe06c14d3
Reviewed-on: https://go-review.googlesource.com/9256
Reviewed-by: Andrew Gerrand <adg@golang.org>
| -rw-r--r-- | git-codereview/sync_test.go | 4 | ||||
| -rw-r--r-- | git-codereview/util_test.go | 42 |
2 files changed, 28 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..ea7cf8f 100644 --- a/git-codereview/util_test.go +++ b/git-codereview/util_test.go @@ -6,6 +6,7 @@ package main import ( "bytes" + "encoding/hex" "fmt" "io/ioutil" "net" @@ -26,6 +27,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 +63,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 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) + } + changeid := hex.EncodeToString([]byte(file)) + trun(t, dir, "git", "commit", "-m", fmt.Sprintf("msg%s\n\nChange-Id: I%d%s\n", suffix, n, changeid)) +} + func (gt *gitTest) work(t *testing.T) { if gt.nwork == 0 { trun(t, gt.client, "git", "checkout", "-b", "work") @@ -70,29 +84,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") } 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") +} +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") } func newGitTest(t *testing.T) (gt *gitTest) { |
