package monitor_daemon import ( "os" "strings" "syscall" "testing" "linkfog.com/public/lib/l" ) /* Run方法: 通用部分: l.Info("======monitor_daemon start======") cmdline := strings.Replace(strings.Join(append(os.Args, "-enable-monitor-daemon=false"), " "), "-D", "", -1) opts := []monitor_daemon.MonitorDaemonOpt{ monitor_daemon.WithForwardSignalType(monitor_daemon.ForwardSignalChildGroup), } monitorDaemon, err := monitor_daemon.New(cmdline, opts...) if err != nil { l.Error("monitor_daemon new error", cmdline) os.Exit(1) } Run示例1: go func() { monitorDaemon.Run() l.Info("======monitor_daemon stop======") }() return nil Run示例2: monitorDaemon.Run(syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL) l.Info("======monitor_daemon stop======") os.Exit(1) */ func TestMonitorDaemonRun(t *testing.T) { l.Info("======monitor_daemon start======") cmdline := strings.Replace(strings.Join(append(os.Args, "-enable-monitor-daemon=false"), " "), "-D", "", -1) opts := []MonitorDaemonOpt{ WithForwardSignalType(ForwardSignalChildGroup), } monitorDaemon, err := New(cmdline, opts...) if err != nil { l.Error("monitor_daemon new error", cmdline) os.Exit(1) } //Run示例1: go func() { monitorDaemon.Run() l.Info("======monitor_daemon stop======") }() return } func TestMonitorDaemonRunSignal(t *testing.T) { l.Info("======monitor_daemon start======") cmdline := strings.Replace(strings.Join(append(os.Args, "-enable-monitor-daemon=false"), " "), "-D", "", -1) opts := []MonitorDaemonOpt{ WithForwardSignalType(ForwardSignalChildGroup), } monitorDaemon, err := New(cmdline, opts...) if err != nil { l.Error("monitor_daemon new error", cmdline) os.Exit(1) } monitorDaemon.Run(syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL) l.Info("======monitor_daemon stop======") os.Exit(1) }