MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestCrash

Function TestCrash

service/lifecycle_test.go:51–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestCrash(t *testing.T) {
52 s := newTestService("Test service")
53 l := service.NewLifecycle(s)
54 starting := make(chan bool)
55 running := make(chan bool)
56 crashed := make(chan bool, 1)
57 l.OnStarting(func(s service.Service, l service.Lifecycle) {
58 starting <- true
59 })
60 l.OnRunning(func(s service.Service, l service.Lifecycle) {
61 running <- true
62 })
63 l.OnCrashed(func(s service.Service, l service.Lifecycle, err error) {
64 crashed <- true
65 })
66 l.OnStopped(func(s service.Service, l service.Lifecycle) {
67 t.Fail()
68 })
69 l.OnStopping(func(s service.Service, l service.Lifecycle, shutdownContext context.Context) {
70 t.Fail()
71 })
72 go func() {
73 if err := l.Run(); err == nil {
74 assert.Fail(t, "service did not crash")
75 }
76 }()
77 <-starting
78 <-running
79 s.Crash()
80 <-crashed
81}

Callers

nothing calls this directly

Calls 10

OnStartingMethod · 0.95
OnRunningMethod · 0.95
OnCrashedMethod · 0.95
OnStoppedMethod · 0.95
OnStoppingMethod · 0.95
RunMethod · 0.95
NewLifecycleFunction · 0.92
newTestServiceFunction · 0.85
FailMethod · 0.80
CrashMethod · 0.80

Tested by

no test coverage detected