(t *testing.T)
| 116 | } |
| 117 | |
| 118 | func 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 | |
| 168 | func TestEgressStore(t *testing.T) { |
| 169 | ctx := context.Background() |
nothing calls this directly
no test coverage detected