MCPcopy
hub / github.com/cloudflare/tableflip / TestReadyWritesPIDFile

Function TestReadyWritesPIDFile

upgrader_test.go:441–474  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

439}
440
441func TestReadyWritesPIDFile(t *testing.T) {
442 t.Parallel()
443
444 dir, err := ioutil.TempDir("", "tableflip")
445 if err != nil {
446 t.Fatal(err)
447 }
448 defer os.RemoveAll(dir)
449
450 file := dir + "/pid"
451 u := newTestUpgrader(Options{
452 PIDFile: file,
453 })
454 defer u.Stop()
455
456 if err := u.Ready(); err != nil {
457 t.Fatal("Ready returned error:", err)
458 }
459
460 fh, err := os.Open(file)
461 if err != nil {
462 t.Fatal("PID file doesn't exist:", err)
463 }
464 defer fh.Close()
465
466 var pid int
467 if _, err := fmt.Fscan(fh, &pid); err != nil {
468 t.Fatal("Can't read PID:", err)
469 }
470
471 if pid != os.Getpid() {
472 t.Error("PID doesn't match")
473 }
474}
475
476func TestWritePidFileWithoutPath(t *testing.T) {
477 pidFile := "tableflip-test.pid"

Callers

nothing calls this directly

Calls 3

newTestUpgraderFunction · 0.85
StopMethod · 0.65
ReadyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…