shithub: hugo

Download patch

ref: 9c782d5147bfea0dd85cf3374f598f0176f204eb
parent: 14c35c8a56c4dc9a1ee0053e9ff976be7715ba99
author: Bjørn Erik Pedersen <[email protected]>
date: Thu Apr 12 05:31:53 EDT 2018

commands: Fix failing Travis server test

--- a/commands/server.go
+++ b/commands/server.go
@@ -41,8 +41,6 @@
 type serverCmd struct {
 	// Can be used to stop the server. Useful in tests
 	stop <-chan bool
-	// Can be used to receive notification about when the server is started. Useful in tests.
-	started chan<- bool
 
 	disableLiveReload bool
 	navigateToChanged bool
@@ -60,11 +58,11 @@
 }
 
 func newServerCmd() *serverCmd {
-	return newServerCmdSignaled(nil, nil)
+	return newServerCmdSignaled(nil)
 }
 
-func newServerCmdSignaled(stop <-chan bool, started chan<- bool) *serverCmd {
-	cc := &serverCmd{stop: stop, started: started}
+func newServerCmdSignaled(stop <-chan bool) *serverCmd {
+	cc := &serverCmd{stop: stop}
 
 	cc.baseBuilderCmd = newBuilderCmd(&cobra.Command{
 		Use:     "server",
@@ -398,10 +396,6 @@
 				os.Exit(1)
 			}
 		}()
-	}
-
-	if s.started != nil {
-		s.started <- true
 	}
 
 	jww.FEEDBACK.Println("Press Ctrl+C to stop")
--- a/commands/server_test.go
+++ b/commands/server_test.go
@@ -38,9 +38,9 @@
 		os.RemoveAll(dir)
 	}()
 
-	stop, started := make(chan bool), make(chan bool)
+	stop := make(chan bool)
 
-	scmd := newServerCmdSignaled(stop, started)
+	scmd := newServerCmdSignaled(stop)
 
 	cmd := scmd.getCommand()
 	cmd.SetArgs([]string{"-s=" + dir, fmt.Sprintf("-p=%d", port)})
@@ -50,11 +50,10 @@
 		assert.NoError(err)
 	}()
 
-	select {
-	case <-started:
-	case <-time.After(2 * time.Second):
-		t.Fatal("server start took too long")
-	}
+	// There is no way to know exactly when the server is ready for connections.
+	// We could improve by something like https://golang.org/pkg/net/http/httptest/#Server
+	// But for now, let us sleep and pray!
+	time.Sleep(2 * time.Second)
 
 	resp, err := http.Get("http://localhost:1331/")
 	assert.NoError(err)