MCPcopy
hub / github.com/livekit/livekit / TestRoomLock

Function TestRoomLock

pkg/service/redisstore_test.go:118–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestRoomLock(t *testing.T) {
119 ctx := context.Background()
120 rs := redisStore(t)
121 lockInterval := 5 * time.Millisecond
122 roomName := livekit.RoomName("myroom")
123
124 t.Run("normal locking", func(t *testing.T) {
125 token, err := rs.LockRoom(ctx, roomName, lockInterval)
126 require.NoError(t, err)
127 require.NotEmpty(t, token)
128 require.NoError(t, rs.UnlockRoom(ctx, roomName, token))
129 })
130
131 t.Run("waits before acquiring lock", func(t *testing.T) {
132 token, err := rs.LockRoom(ctx, roomName, lockInterval)
133 require.NoError(t, err)
134 require.NotEmpty(t, token)
135 unlocked := atomic.NewUint32(0)
136 wg := sync.WaitGroup{}
137
138 wg.Add(1)
139 go func() {
140 // attempt to lock again
141 defer wg.Done()
142 token2, err := rs.LockRoom(ctx, roomName, lockInterval)
143 require.NoError(t, err)
144 defer rs.UnlockRoom(ctx, roomName, token2)
145 require.Equal(t, uint32(1), unlocked.Load())
146 }()
147
148 // release after 2 ms
149 time.Sleep(2 * time.Millisecond)
150 unlocked.Store(1)
151 _ = rs.UnlockRoom(ctx, roomName, token)
152
153 wg.Wait()
154 })
155
156 t.Run("lock expires", func(t *testing.T) {
157 token, err := rs.LockRoom(ctx, roomName, lockInterval)
158 require.NoError(t, err)
159 defer rs.UnlockRoom(ctx, roomName, token)
160
161 time.Sleep(lockInterval + time.Millisecond)
162 token2, err := rs.LockRoom(ctx, roomName, lockInterval)
163 require.NoError(t, err)
164 _ = rs.UnlockRoom(ctx, roomName, token2)
165 })
166}
167
168func TestEgressStore(t *testing.T) {
169 ctx := context.Background()

Callers

nothing calls this directly

Calls 8

redisStoreFunction · 0.85
DoneMethod · 0.80
StoreMethod · 0.80
LockRoomMethod · 0.65
UnlockRoomMethod · 0.65
LoadMethod · 0.65
RunMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected