forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the pidfile after the server has exited
- Loading branch information
1 parent
1e419cf
commit 6caca36
Showing
3 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package run_test | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"text/template" | ||
"time" | ||
|
||
"fmt" | ||
|
||
"github.com/influxdata/kapacitor/cmd/kapacitord/run" | ||
) | ||
|
||
func TestCommand_PIDFile(t *testing.T) { | ||
tmpdir, err := ioutil.TempDir(os.TempDir(), "kapacitord-test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpdir) | ||
|
||
// Write out a config file that does not attempt to connect to influxdb. | ||
configFile := filepath.Join(tmpdir, "kapacitor.conf") | ||
configTemplate := template.Must(template.New("config_file").Parse(`data_dir = "{{.TempDir}}/data" | ||
[[influxdb]] | ||
enabled = false | ||
[replay] | ||
dir = "{{.TempDir}}/replay" | ||
[storage] | ||
boltdb = "{{.TempDir}}/kapacitor.db" | ||
[task] | ||
dir = "{{.TempDir}}/tasks" | ||
[load] | ||
dir = "{{.TempDir}}/load" | ||
`)) | ||
var buf bytes.Buffer | ||
if err := configTemplate.Execute(&buf, map[string]string{"TempDir": tmpdir}); err != nil { | ||
t.Fatalf("unable to generate config file: %s", err) | ||
} | ||
fmt.Println(buf.String()) | ||
if err := ioutil.WriteFile(configFile, buf.Bytes(), 0600); err != nil { | ||
t.Fatalf("unable to write %s: %s", configFile, err) | ||
} | ||
|
||
pidFile := filepath.Join(tmpdir, "kapacitor.pid") | ||
|
||
cmd := run.NewCommand() | ||
if err := cmd.Run("-config", configFile, "-pidfile", pidFile); err != nil { | ||
t.Fatalf("unexpected error: %s", err) | ||
} | ||
|
||
if _, err := os.Stat(pidFile); err != nil { | ||
t.Fatalf("could not stat pid file: %s", err) | ||
} | ||
go cmd.Close() | ||
|
||
timeout := time.NewTimer(5 * time.Second) | ||
select { | ||
case <-timeout.C: | ||
t.Fatal("unexpected timeout") | ||
case <-cmd.Closed: | ||
timeout.Stop() | ||
} | ||
|
||
if _, err := os.Stat(pidFile); err == nil { | ||
t.Fatal("expected pid file to be removed") | ||
} | ||
} |