diff --git a/cmd/godoc/appinit.go b/cmd/godoc/appinit.go index ad95b213..3d6a9210 100644 --- a/cmd/godoc/appinit.go +++ b/cmd/godoc/appinit.go @@ -50,6 +50,7 @@ func init() { if err := corpus.Init(); err != nil { log.Fatal(err) } + corpus.IndexDirectory = indexDirectoryDefault go corpus.RunIndexer() pres = godoc.NewPresentation(corpus) diff --git a/cmd/godoc/godoc_test.go b/cmd/godoc/godoc_test.go index feaad2f5..365a236f 100644 --- a/cmd/godoc/godoc_test.go +++ b/cmd/godoc/godoc_test.go @@ -131,18 +131,30 @@ func serverAddress(t *testing.T) string { return ln.Addr().String() } +const ( + startTimeout = 5 * time.Minute + pollInterval = 200 * time.Millisecond +) + +var indexingMsg = []byte("Indexing in progress: result may be inaccurate") + func waitForServer(t *testing.T, address string) { - // Poll every 50ms for a total of 5s. - for i := 0; i < 100; i++ { - time.Sleep(50 * time.Millisecond) - conn, err := net.Dial("tcp", address) + // "health check" duplicated from x/tools/cmd/tipgodoc/tip.go + deadline := time.Now().Add(startTimeout) + for time.Now().Before(deadline) { + time.Sleep(pollInterval) + res, err := http.Get(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", address)) if err != nil { continue } - conn.Close() - return + rbody, err := ioutil.ReadAll(res.Body) + res.Body.Close() + if err == nil && res.StatusCode == http.StatusOK && + !bytes.Contains(rbody, indexingMsg) { + return + } } - t.Fatalf("Server %q failed to respond in 5 seconds", address) + t.Fatalf("Server %q failed to respond in %v", address, startTimeout) } func killAndWait(cmd *exec.Cmd) { @@ -155,7 +167,7 @@ func TestWeb(t *testing.T) { bin, cleanup := buildGodoc(t) defer cleanup() addr := serverAddress(t) - cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr)) + cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-index", "-index_interval=-1s") cmd.Stdout = os.Stderr cmd.Stderr = os.Stderr cmd.Args[0] = "godoc" @@ -207,6 +219,15 @@ func TestWeb(t *testing.T) { "cmd/gc", }, }, + { + path: "/search?q=notwithstanding", + match: []string{ + "/src", + }, + dontmatch: []string{ + "/pkg/bootstrap", + }, + }, } for _, test := range tests { url := fmt.Sprintf("http://%s%s", addr, test.path) diff --git a/cmd/godoc/index.go b/cmd/godoc/index.go new file mode 100644 index 00000000..f84b29a2 --- /dev/null +++ b/cmd/godoc/index.go @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import "strings" + +func indexDirectoryDefault(dir string) bool { + return dir != "/pkg" && !strings.HasPrefix(dir, "/pkg/") +} diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index 42e95ab1..3496013c 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -219,6 +219,7 @@ func main() { corpus.IndexFullText = false } corpus.IndexFiles = *indexFiles + corpus.IndexDirectory = indexDirectoryDefault corpus.IndexThrottle = *indexThrottle corpus.IndexInterval = *indexInterval if *writeIndex {