mirror of
https://github.com/golang/go
synced 2024-11-18 15:34:53 -07:00
cmd/godoc: don't run indexer test in -short mode
It takes too long for the builders. Also remove GOPATH from the environment when indexing. Change-Id: I9a3f2628f248bdbf9dce97119c2fbb7cbd63f3fe Reviewed-on: https://go-review.googlesource.com/12917 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
20d85c34f3
commit
d1eaf38956
@ -134,30 +134,39 @@ func serverAddress(t *testing.T) string {
|
|||||||
return ln.Addr().String()
|
return ln.Addr().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
func waitForServerReady(t *testing.T, addr string) {
|
||||||
startTimeout = 5 * time.Minute
|
waitForServer(t,
|
||||||
pollInterval = 200 * time.Millisecond
|
fmt.Sprintf("http://%v/", addr),
|
||||||
)
|
"The Go Programming Language",
|
||||||
|
5*time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
var indexingMsg = []byte("Indexing in progress: result may be inaccurate")
|
func waitForSearchReady(t *testing.T, addr string) {
|
||||||
|
waitForServer(t,
|
||||||
|
fmt.Sprintf("http://%v/search?q=FALLTHROUGH", addr),
|
||||||
|
"The list of tokens.",
|
||||||
|
2*time.Minute)
|
||||||
|
}
|
||||||
|
|
||||||
func waitForServer(t *testing.T, address string) {
|
const pollInterval = 200 * time.Millisecond
|
||||||
|
|
||||||
|
func waitForServer(t *testing.T, url, match string, timeout time.Duration) {
|
||||||
// "health check" duplicated from x/tools/cmd/tipgodoc/tip.go
|
// "health check" duplicated from x/tools/cmd/tipgodoc/tip.go
|
||||||
deadline := time.Now().Add(startTimeout)
|
deadline := time.Now().Add(timeout)
|
||||||
for time.Now().Before(deadline) {
|
for time.Now().Before(deadline) {
|
||||||
time.Sleep(pollInterval)
|
time.Sleep(pollInterval)
|
||||||
res, err := http.Get(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", address))
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rbody, err := ioutil.ReadAll(res.Body)
|
rbody, err := ioutil.ReadAll(res.Body)
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
if err == nil && res.StatusCode == http.StatusOK &&
|
if err == nil && res.StatusCode == http.StatusOK &&
|
||||||
!bytes.Contains(rbody, indexingMsg) {
|
bytes.Contains(rbody, []byte(match)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Fatalf("Server %q failed to respond in %v", address, startTimeout)
|
t.Fatalf("Server failed to respond in %v", timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func killAndWait(cmd *exec.Cmd) {
|
func killAndWait(cmd *exec.Cmd) {
|
||||||
@ -167,22 +176,47 @@ func killAndWait(cmd *exec.Cmd) {
|
|||||||
|
|
||||||
// Basic integration test for godoc HTTP interface.
|
// Basic integration test for godoc HTTP interface.
|
||||||
func TestWeb(t *testing.T) {
|
func TestWeb(t *testing.T) {
|
||||||
|
testWeb(t, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic integration test for godoc HTTP interface.
|
||||||
|
func TestWebIndex(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("skipping test in -short mode")
|
||||||
|
}
|
||||||
|
testWeb(t, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic integration test for godoc HTTP interface.
|
||||||
|
func testWeb(t *testing.T, withIndex bool) {
|
||||||
bin, cleanup := buildGodoc(t)
|
bin, cleanup := buildGodoc(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
addr := serverAddress(t)
|
addr := serverAddress(t)
|
||||||
cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-index", "-index_interval=-1s")
|
args := []string{fmt.Sprintf("-http=%s", addr)}
|
||||||
|
if withIndex {
|
||||||
|
args = append(args, "-index", "-index_interval=-1s")
|
||||||
|
}
|
||||||
|
cmd := exec.Command(bin, args...)
|
||||||
cmd.Stdout = os.Stderr
|
cmd.Stdout = os.Stderr
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Args[0] = "godoc"
|
cmd.Args[0] = "godoc"
|
||||||
|
cmd.Env = godocEnv()
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
t.Fatalf("failed to start godoc: %s", err)
|
t.Fatalf("failed to start godoc: %s", err)
|
||||||
}
|
}
|
||||||
defer killAndWait(cmd)
|
defer killAndWait(cmd)
|
||||||
waitForServer(t, addr)
|
|
||||||
|
if withIndex {
|
||||||
|
waitForSearchReady(t, addr)
|
||||||
|
} else {
|
||||||
|
waitForServerReady(t, addr)
|
||||||
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
path string
|
path string
|
||||||
match []string
|
match []string
|
||||||
dontmatch []string
|
dontmatch []string
|
||||||
|
needIndex bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
@ -230,9 +264,13 @@ func TestWeb(t *testing.T) {
|
|||||||
dontmatch: []string{
|
dontmatch: []string{
|
||||||
"/pkg/bootstrap",
|
"/pkg/bootstrap",
|
||||||
},
|
},
|
||||||
|
needIndex: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
if test.needIndex && !withIndex {
|
||||||
|
continue
|
||||||
|
}
|
||||||
url := fmt.Sprintf("http://%s%s", addr, test.path)
|
url := fmt.Sprintf("http://%s%s", addr, test.path)
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -317,7 +355,7 @@ func main() { print(lib.V) }
|
|||||||
t.Fatalf("failed to start godoc: %s", err)
|
t.Fatalf("failed to start godoc: %s", err)
|
||||||
}
|
}
|
||||||
defer killAndWait(cmd)
|
defer killAndWait(cmd)
|
||||||
waitForServer(t, addr)
|
waitForServerReady(t, addr)
|
||||||
|
|
||||||
// Wait for type analysis to complete.
|
// Wait for type analysis to complete.
|
||||||
reader := bufio.NewReader(stderr)
|
reader := bufio.NewReader(stderr)
|
||||||
@ -384,3 +422,15 @@ tryagain:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// godocEnv returns the process environment without the GOPATH variable.
|
||||||
|
// (We don't want the indexer looking at the local workspace during tests.)
|
||||||
|
func godocEnv() (env []string) {
|
||||||
|
for _, v := range os.Environ() {
|
||||||
|
if strings.HasPrefix(v, "GOPATH=") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
env = append(env, v)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user