From cf285cde6063ab130cb4b9342346b437411e90a7 Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 31 Oct 2014 09:04:03 +1100 Subject: [PATCH] go.tools/dashboard/app: fix tests TBR=dvyukov R=dvyukov, bradfitz CC=golang-codereviews https://golang.org/cl/165740043 --- dashboard/app/build/build.go | 4 ++-- dashboard/app/build/handler.go | 6 ++++-- dashboard/app/build/test.go | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dashboard/app/build/build.go b/dashboard/app/build/build.go index d2488a33af6..bee00ada049 100644 --- a/dashboard/app/build/build.go +++ b/dashboard/app/build/build.go @@ -131,8 +131,8 @@ func putCommit(c appengine.Context, com *Commit) error { if err := com.Valid(); err != nil { return fmt.Errorf("putting Commit: %v", err) } - if com.Num == 0 { - return fmt.Errorf("putting Commit: com.Num == 0") + if com.Num == 0 && com.ParentHash != "0000" { // 0000 is used in tests + return fmt.Errorf("putting Commit: invalid Num (must be > 0)") } if _, err := datastore.Put(c, com.Key(c), com); err != nil { return fmt.Errorf("putting Commit: %v", err) diff --git a/dashboard/app/build/handler.go b/dashboard/app/build/handler.go index e58c188cb25..5d06815c064 100644 --- a/dashboard/app/build/handler.go +++ b/dashboard/app/build/handler.go @@ -172,7 +172,7 @@ func addCommit(c appengine.Context, com *Commit) error { } // if this isn't the first Commit test the parent commit exists. // The all zeros are returned by hg's p1node template for parentless commits. - if com.ParentHash != "" && com.ParentHash != "0000000000000000000000000000000000000000" { + if com.ParentHash != "" && com.ParentHash != "0000000000000000000000000000000000000000" && com.ParentHash != "0000" { n, err := datastore.NewQuery("Commit"). Filter("Hash =", com.ParentHash). Ancestor(p.Key(c)). @@ -609,7 +609,8 @@ func perfResultHandler(r *http.Request) (interface{}, error) { } // addPerfResult creates PerfResult and updates Commit, PerfTodo, -// PerfMetricRun and PerfConfig. Must be executed within a transaction. +// PerfMetricRun and PerfConfig. +// MUST be called from inside a transaction. func addPerfResult(c appengine.Context, r *http.Request, req *PerfRequest) error { // check Package exists p, err := GetPackage(c, "") @@ -676,6 +677,7 @@ func addPerfResult(c appengine.Context, r *http.Request, req *PerfRequest) error return nil } +// MUST be called from inside a transaction. func checkPerfChanges(c appengine.Context, r *http.Request, com *Commit, builder string, res *PerfResult) error { pc, err := GetPerfConfig(c, r) if err != nil { diff --git a/dashboard/app/build/test.go b/dashboard/app/build/test.go index b7a7cfabcb4..86b2197fe0c 100644 --- a/dashboard/app/build/test.go +++ b/dashboard/app/build/test.go @@ -75,7 +75,7 @@ var testRequests = []struct { {"/packages", url.Values{"kind": {"subrepo"}}, nil, []*Package{testPackage}}, // Go repo - {"/commit", nil, tCommit("0001", "", "", true), nil}, + {"/commit", nil, tCommit("0001", "0000", "", true), nil}, {"/commit", nil, tCommit("0002", "0001", "", false), nil}, {"/commit", nil, tCommit("0003", "0002", "", true), nil}, {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, @@ -119,7 +119,7 @@ var testRequests = []struct { {"/result", nil, &Result{Builder: "linux-386", Hash: "0003", OK: false, Log: "test"}, nil}, // non-Go repos - {"/commit", nil, tCommit("1001", "", testPkg, false), nil}, + {"/commit", nil, tCommit("1001", "0000", testPkg, false), nil}, {"/commit", nil, tCommit("1002", "1001", testPkg, false), nil}, {"/commit", nil, tCommit("1003", "1002", testPkg, false), nil}, {"/todo", url.Values{"kind": {"build-package"}, "builder": {"linux-386"}, "packagePath": {testPkg}, "goHash": {"0001"}}, nil, &Todo{Kind: "build-package", Data: &Commit{Hash: "1003"}}},