Example #1
0
func TestRunInterrupt(t *testing.T) {
	p := &program{}
	sc := &service.Config{
		Name: "go_service_test",
	}
	s, err := service.New(p, sc)
	if err != nil {
		t.Fatalf("New err: %s", err)
	}

	go func() {
		<-time.After(1 * time.Second)
		interruptProcess(t)
	}()

	go func() {
		for i := 0; i < 25 && p.numStopped == 0; i++ {
			<-time.After(200 * time.Millisecond)
		}
		if p.numStopped == 0 {
			t.Fatal("Run() hasn't been stopped")
		}
	}()

	if err = s.Run(); err != nil {
		t.Fatalf("Run() err: %s", err)
	}
}
Example #2
0
func runService() {
	p := &program{}
	sc := &service.Config{
		Name: "go_service_test",
	}
	s, err := service.New(p, sc)
	if err != nil {
		log.Fatal(err)
	}
	if err = s.Run(); err != nil {
		log.Fatal(err)
	}
}
Example #3
0
func mustNewRunAsService(
	t *testing.T,
	p *program,
	reportDir string,
) service.Service {
	sc := &service.Config{
		Name:      "go_service_test",
		Arguments: []string{"-test.v=true", runAsServiceArg, reportDir},
	}
	s, err := service.New(p, sc)
	if err != nil {
		t.Fatal(err)
	}
	return s
}