MCPcopy Index your code
hub / github.com/coder/coder / TestCleanStalePIDFile

Function TestCleanStalePIDFile

scripts/develop/dbrecovery_test.go:15–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestCleanStalePIDFile(t *testing.T) {
16 t.Parallel()
17
18 t.Run("NoPIDFile", func(t *testing.T) {
19 t.Parallel()
20 cleanStalePIDFile(t.TempDir())
21 })
22
23 t.Run("StalePID", func(t *testing.T) {
24 t.Parallel()
25 dir := t.TempDir()
26 pidFile := filepath.Join(dir, "postmaster.pid")
27 require.NoError(t, os.WriteFile(pidFile, []byte("999999999\n"), 0o600))
28
29 cleanStalePIDFile(dir)
30
31 _, err := os.Stat(pidFile)
32 assert.True(t, os.IsNotExist(err))
33 })
34
35 t.Run("RunningPID", func(t *testing.T) {
36 t.Parallel()
37 dir := t.TempDir()
38 pidFile := filepath.Join(dir, "postmaster.pid")
39 require.NoError(t, os.WriteFile(pidFile,
40 []byte(strconv.Itoa(os.Getpid())+"\n"), 0o600))
41
42 cleanStalePIDFile(dir)
43
44 _, err := os.Stat(pidFile)
45 assert.NoError(t, err, "should not remove PID file for running process")
46 })
47}

Callers

nothing calls this directly

Calls 4

cleanStalePIDFileFunction · 0.85
RunMethod · 0.65
TempDirMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected