diff --git a/main_test.go b/main_test.go index 7849aa98d..8b5c168dc 100644 --- a/main_test.go +++ b/main_test.go @@ -136,12 +136,6 @@ func TestCreateAndRemovePidFile(t *testing.T) { t.Errorf("pid file should be created but, %s", err) } - if runtime.GOOS != "windows" { - if err := pidfile.Create(fpath); err == nil || !strings.HasPrefix(err.Error(), "pidfile found, try stopping another running mackerel-agent or delete") { - t.Errorf("creating pid file should be failed when the running process exists, %s", err) - } - } - pidfile.Remove(fpath) if err := pidfile.Create(fpath); err != nil { t.Errorf("pid file should be created but, %s", err) diff --git a/pidfile/pidfile_test.go b/pidfile/pidfile_test.go index 91953c8ab..660e27b47 100644 --- a/pidfile/pidfile_test.go +++ b/pidfile/pidfile_test.go @@ -3,6 +3,7 @@ package pidfile import ( + "fmt" "io/ioutil" "os" "path/filepath" @@ -31,7 +32,16 @@ func TestCreate(t *testing.T) { if pid != os.Getpid() { t.Errorf("contents of pidfile does not match pid. content: %d, pid: %d", pid, os.Getpid()) } +} +func TestCreate_mutex(t *testing.T) { + dir, err := ioutil.TempDir("", "") + if err != nil { + t.Fatalf("failed to create tempdir") + } + defer os.RemoveAll(dir) + pidfile := filepath.Join(dir, "pidfile") + ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d", os.Getppid())), 0644) err = Create(pidfile) if err == nil { t.Errorf("Successfully overwriting the pidfile unintentionally")