MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / TestEventStop

Function TestEventStop

pkg/controller/rtctrl/event_test.go:124–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func TestEventStop(t *testing.T) {
125 rtMap := initRuntimeList(1)
126 list := rtMap.RuntimeList()
127 rt := list[0]
128
129 // success
130 rt.SetState(RuntimeStateWarm)
131 rt.updateLastAccessTime()
132 idleTime := time.Second
133 deadline := time.Now().Add(-idleTime)
134 err := rt.CAS(OpStop, &StopInput{Deadline: deadline})
135 expectedErr := &RuntimeMatchError{
136 Reason: "no need to stop",
137 }
138 if err.Error() != expectedErr.Error() {
139 t.Errorf("runtime state expected %s, but got %s", expectedErr, err)
140 }
141 <-time.NewTicker(idleTime + 1).C
142 deadline = time.Now().Add(idleTime)
143 err1 := rt.CAS(OpStop, &StopInput{Deadline: deadline})
144 if err1 != nil {
145 t.Errorf("stop runtime failed %s", err1)
146 return
147 }
148 if rt.State != RuntimeStateStopping {
149 t.Errorf("runtime state expected stopping, but got %s", rt.State)
150 return
151 }
152
153 // fail
154 rt.SetState(RuntimeStateClosed)
155 err2 := rt.CAS(OpStop, &StopInput{Deadline: deadline})
156 expectedErr2 := &RuntimeStateUnmatched{
157 RuntimeID: rt.RuntimeID,
158 CurrentState: RuntimeStateClosed,
159 ExpectedState: []string{RuntimeStateWarm},
160 }
161 if err2.Error() != expectedErr2.Error() {
162 t.Errorf("stop runtime expected %s, but got %s", expectedErr2, err2)
163 return
164 }
165}
166
167func TestRelease(t *testing.T) {
168 rtMap := initRuntimeList(1)

Callers

nothing calls this directly

Calls 10

ErrorMethod · 0.95
ErrorMethod · 0.95
initRuntimeListFunction · 0.85
SetStateMethod · 0.80
updateLastAccessTimeMethod · 0.80
CASMethod · 0.80
ErrorfMethod · 0.80
RuntimeListMethod · 0.65
AddMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected