-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
f58a194
commit 2005a8c
Showing
3 changed files
with
58 additions
and
2 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,45 @@ | ||
package run_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"path/filepath" | ||
|
||
"time" | ||
|
||
"github.com/influxdata/influxdb/cmd/influxd/run" | ||
) | ||
|
||
func TestPIDFile(t *testing.T) { | ||
tmpdir, err := ioutil.TempDir(os.TempDir(), "influxd-test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpdir) | ||
|
||
pidFile := filepath.Join(tmpdir, "influxdb.pid") | ||
|
||
cmd := run.NewCommand() | ||
if err := cmd.Run("-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(100 * time.Millisecond) | ||
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") | ||
} | ||
} |