From a160d803d7944e4c5a0f79836c20b78a94a807d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Sur=C3=A1nyi?= Date: Sun, 8 Mar 2015 07:25:49 +0900 Subject: [PATCH] cmd/tipgodoc: enable indexing Run godoc indexing just once on startup. Wait for indexing to complete before switching to new side. Increase startup timeout to accommodate for indexing. Updates golang/go#9996. Change-Id: I1e746a68b7d787e6d7f180c2617ea75f0d3291f8 Reviewed-on: https://go-review.googlesource.com/7120 Reviewed-by: Andrew Gerrand --- cmd/tipgodoc/Dockerfile | 2 +- cmd/tipgodoc/tip.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/tipgodoc/Dockerfile b/cmd/tipgodoc/Dockerfile index ac958192..760ca0bb 100644 --- a/cmd/tipgodoc/Dockerfile +++ b/cmd/tipgodoc/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.4.1 +FROM golang:1.4.2 RUN apt-get update && apt-get install --no-install-recommends -y -q build-essential git diff --git a/cmd/tipgodoc/tip.go b/cmd/tipgodoc/tip.go index 4a92a5c1..dbd7f1f3 100644 --- a/cmd/tipgodoc/tip.go +++ b/cmd/tipgodoc/tip.go @@ -8,6 +8,7 @@ package main import ( "bufio" + "bytes" "encoding/json" "fmt" "io" @@ -28,6 +29,8 @@ const ( metaURL = "https://go.googlesource.com/?b=master&format=JSON" ) +var indexingMsg = []byte("Indexing in progress: result may be inaccurate") + func main() { p := new(Proxy) go p.run() @@ -165,7 +168,7 @@ func initSide(side, goHash, toolsHash string) (godoc *exec.Cmd, hostport string, if side == "b" { hostport = "localhost:8082" } - godoc = exec.Command(godocBin, "-http="+hostport) + godoc = exec.Command(godocBin, "-http="+hostport, "-index", "-index_interval=-1s") godoc.Env = []string{"GOROOT=" + goDir} // TODO(adg): log this somewhere useful godoc.Stdout = os.Stdout @@ -180,18 +183,21 @@ func initSide(side, goHash, toolsHash string) (godoc *exec.Cmd, hostport string, } }() - for i := 0; i < 15; i++ { + for i := 0; i < 120; i++ { time.Sleep(time.Second) var res *http.Response - res, err = http.Get(fmt.Sprintf("http://%v/", hostport)) + res, err = http.Get(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", hostport)) if err != nil { continue } + rbody, err := ioutil.ReadAll(res.Body) res.Body.Close() - if res.StatusCode == http.StatusOK { + if err == nil && res.StatusCode == http.StatusOK && + !bytes.Contains(rbody, indexingMsg) { return godoc, hostport, nil } } + godoc.Process.Kill() return nil, "", fmt.Errorf("timed out waiting for side %v at %v (%v)", side, hostport, err) }