MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestOneService

Function TestOneService

service/pool_test.go:33–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestOneService(t *testing.T) {
34 pool := service.NewPool(service.NewLifecycleFactory(), log.NewTestLogger(t))
35 poolLifecycle := service.NewLifecycle(pool)
36 poolStarted := make(chan bool)
37 poolStopped := make(chan bool)
38 var poolStates []service.State
39 var serviceStates []service.State
40 poolLifecycle.OnRunning(func(s service.Service, l service.Lifecycle) {
41 poolStarted <- true
42 })
43 poolLifecycle.OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) {
44 poolStates = append(poolStates, state)
45 })
46
47 s := newTestService("Test service")
48 pool.Add(s).OnStateChange(func(s service.Service, l service.Lifecycle, state service.State) {
49 serviceStates = append(serviceStates, state)
50 })
51
52 go func() {
53 err := poolLifecycle.Run()
54 if err != nil {
55 t.Fail()
56 }
57 poolStopped <- true
58 }()
59
60 <-poolStarted
61 poolLifecycle.Stop(context.Background())
62 assert.Equal(t, []service.State{
63 service.StateStarting,
64 service.StateRunning,
65 service.StateStopping,
66 service.StateStopped,
67 }, serviceStates)
68 assert.Equal(t, []service.State{
69 service.StateStarting,
70 service.StateRunning,
71 service.StateStopping,
72 service.StateStopped,
73 }, poolStates)
74}
75
76func TestOneServiceCrash(t *testing.T) {
77 testLock := &sync.Mutex{}

Callers

nothing calls this directly

Calls 11

OnRunningMethod · 0.95
OnStateChangeMethod · 0.95
AddMethod · 0.95
RunMethod · 0.95
StopMethod · 0.95
NewPoolFunction · 0.92
NewLifecycleFactoryFunction · 0.92
NewTestLoggerFunction · 0.92
NewLifecycleFunction · 0.92
newTestServiceFunction · 0.85
FailMethod · 0.80

Tested by

no test coverage detected