From b291307dde5a28f3746431a00d640b16ce807d13 Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Wed, 15 Mar 2017 14:30:01 -0500 Subject: [PATCH] add plugins path arg to server also fix an issue where tests would hang if an invalid config file was given --- cmd/server.go | 1 + cmd/server_test.go | 17 ++++++++++------- server/server.go | 8 +++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 92b776c5c..911bdc3e6 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -80,6 +80,7 @@ on the configured port.`, flags.IntVarP(&Serve.Config.Cluster.ReplicaN, "cluster.replicas", "", 1, "Number hosts each piece of data should be stored on.") flags.StringSliceVarP(&Serve.Config.Cluster.Nodes, "cluster.hosts", "", []string{}, "Comma separated list of hosts in cluster.") flags.DurationVarP((*time.Duration)(&Serve.Config.Cluster.PollingInterval), "cluster.poll-interval", "", time.Minute, "Polling interval for cluster.") // TODO what actually is this? + flags.StringVarP(&Serve.Config.Plugins.Path, "plugins.path", "", "", "Path to plugin directory.") flags.StringVarP(&Serve.CPUProfile, "cpu-profile", "", "", "Where to store CPU profile.") flags.DurationVarP(&Serve.CPUTime, "cpu-time", "", 30*time.Second, "CPU profile duration.") diff --git a/cmd/server_test.go b/cmd/server_test.go index 1da8d6140..b4a1429de 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "reflect" "strings" - "sync" "testing" "time" @@ -83,10 +82,13 @@ bind = "localhost:0" hosts = [ "localhost:19444", ] +[plugins] + path = "/var/sloth" `, validation: func() error { v := validator{} v.Check(cmd.Serve.Config.Cluster.Nodes, []string{"example.com:1110", "example.com:1111"}) + v.Check(cmd.Serve.Config.Plugins.Path, "/var/sloth") return v.Error() }, }, @@ -113,18 +115,19 @@ bind = "localhost:0" for i, test := range tests { com := test.setupCommand(t) - wait := sync.Mutex{} - wait.Lock() + executed := make(chan struct{}) var execErr error go func() { execErr = com.Execute() - wait.Unlock() + close(executed) }() - // Serve.Close automatically waits for Serve.Run() to finish starting - // the server. + select { + case <-cmd.Serve.Started: + case <-executed: + } err := cmd.Serve.Close() failErr(t, err, "closing pilosa server command") - wait.Lock() // make sure com.Execute finishes + <-executed failErr(t, execErr, "executing command") if err := test.validation(); err != nil { diff --git a/server/server.go b/server/server.go index 1feb6c41b..b31719df9 100644 --- a/server/server.go +++ b/server/server.go @@ -40,7 +40,7 @@ type Command struct { Stderr io.Writer // running will be closed once Command.Run is finished. - running chan struct{} + Started chan struct{} // Done will be closed when Command.Close() is called Done chan struct{} } @@ -55,14 +55,14 @@ func NewCommand() *Command { Stdout: os.Stdout, Stderr: os.Stderr, - running: make(chan struct{}), + Started: make(chan struct{}), Done: make(chan struct{}), } } // Run executes the pilosa server. func (m *Command) Run(args ...string) error { - defer close(m.running) + defer close(m.Started) prefix := "~" + string(filepath.Separator) if strings.HasPrefix(m.Config.DataDir, prefix) { HomeDir := os.Getenv("HOME") @@ -97,8 +97,6 @@ func (m *Command) Run(args ...string) error { // Close shuts down the server. func (m *Command) Close() error { - // must be running before it can be closed - <-m.running err := m.Server.Close() close(m.Done) return err