TUN-5956: Add timeout to session manager APIs

This commit is contained in:
cthuang
2022-03-28 10:06:28 +01:00
committed by Chung Ting Huang
parent c5d1662244
commit c0f85ab85b
2 changed files with 34 additions and 1 deletions

View File

@@ -120,6 +120,28 @@ func TestManagerServe(t *testing.T) {
<-serveDone
}
func TestTimeout(t *testing.T) {
const (
testTimeout = time.Millisecond * 50
)
log := zerolog.Nop()
transport := &mockQUICTransport{
reqChan: newDatagramChannel(1),
respChan: newDatagramChannel(1),
}
mg := NewManager(transport, &log)
mg.timeout = testTimeout
ctx := context.Background()
sessionID := uuid.New()
// session manager is not running, so event loop is not running and therefore calling the APIs should timeout
session, err := mg.RegisterSession(ctx, sessionID, nil)
require.ErrorIs(t, err, context.DeadlineExceeded)
require.Nil(t, session)
err = mg.UnregisterSession(ctx, sessionID, "session gone", true)
require.ErrorIs(t, err, context.DeadlineExceeded)
}
type mockOrigin struct {
expectMsgCount int
expectedMsg []byte