MCPcopy Create free account
hub / github.com/daodst/chat / TestSessionCleanUp

Function TestSessionCleanUp

clientapi/routing/register_test.go:213–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

211}
212
213func TestSessionCleanUp(t *testing.T) {
214 s := newSessionsDict()
215
216 t.Run("session is cleaned up after a while", func(t *testing.T) {
217 // t.Parallel()
218 dummySession := "helloWorld"
219 // manually added, as s.addParams() would start the timer with the default timeout
220 s.params[dummySession] = registerRequest{Username: "Testing"}
221 s.startTimer(time.Millisecond, dummySession)
222 time.Sleep(time.Millisecond * 50)
223 if data, ok := s.getParams(dummySession); ok {
224 t.Errorf("expected session to be deleted: %+v", data)
225 }
226 })
227
228 t.Run("session is deleted, once the registration completed", func(t *testing.T) {
229 // t.Parallel()
230 dummySession := "helloWorld2"
231 s.startTimer(time.Minute, dummySession)
232 s.deleteSession(dummySession)
233 if data, ok := s.getParams(dummySession); ok {
234 t.Errorf("expected session to be deleted: %+v", data)
235 }
236 })
237
238 t.Run("session timer is restarted after second call", func(t *testing.T) {
239 // t.Parallel()
240 dummySession := "helloWorld3"
241 // the following will start a timer with the default timeout of 5min
242 s.addParams(dummySession, registerRequest{Username: "Testing"})
243 s.addCompletedSessionStage(dummySession, authtypes.LoginTypeRecaptcha)
244 s.addCompletedSessionStage(dummySession, authtypes.LoginTypeDummy)
245 s.addDeviceToDelete(dummySession, "dummyDevice")
246 s.getCompletedStages(dummySession)
247 // reset the timer with a lower timeout
248 s.startTimer(time.Millisecond, dummySession)
249 time.Sleep(time.Millisecond * 50)
250 if data, ok := s.getParams(dummySession); ok {
251 t.Errorf("expected session to be deleted: %+v", data)
252 }
253 if _, ok := s.timer[dummySession]; ok {
254 t.Error("expected timer to be delete")
255 }
256 if _, ok := s.sessions[dummySession]; ok {
257 t.Error("expected session to be delete")
258 }
259 if _, ok := s.getDeviceToDelete(dummySession); ok {
260 t.Error("expected session to device to be delete")
261 }
262 })
263}

Callers

nothing calls this directly

Calls 11

newSessionsDictFunction · 0.85
RunMethod · 0.80
startTimerMethod · 0.80
getParamsMethod · 0.80
deleteSessionMethod · 0.80
addParamsMethod · 0.80
addDeviceToDeleteMethod · 0.80
getCompletedStagesMethod · 0.80
getDeviceToDeleteMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected