MCPcopy
hub / github.com/livekit/livekit / TestMigrationDataCache_Add

Function TestMigrationDataCache_Add

pkg/rtc/migrationdatacache_test.go:12–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestMigrationDataCache_Add(t *testing.T) {
13 expiredAt := time.Now().Add(100 * time.Millisecond)
14 cache := NewMigrationDataCache(10, expiredAt)
15
16 pkt1 := &livekit.DataPacket{Sequence: 9}
17 state := cache.Add(pkt1)
18 require.Equal(t, MigrationDataCacheStateWaiting, state)
19 require.Empty(t, cache.Get())
20
21 pkt2 := &livekit.DataPacket{Sequence: 11}
22 state = cache.Add(pkt2)
23 require.Equal(t, MigrationDataCacheStateDone, state)
24 require.Empty(t, cache.Get())
25
26 pkt3 := &livekit.DataPacket{Sequence: 12}
27 state = cache.Add(pkt3)
28 require.Equal(t, MigrationDataCacheStateDone, state)
29 require.Empty(t, cache.Get())
30
31 cache2 := NewMigrationDataCache(20, time.Now().Add(10*time.Millisecond))
32 pkt4 := &livekit.DataPacket{Sequence: 22}
33 time.Sleep(20 * time.Millisecond)
34 state = cache2.Add(pkt4)
35 require.Equal(t, MigrationDataCacheStateTimeout, state)
36 require.Len(t, cache2.Get(), 1)
37 require.Equal(t, uint32(22), cache2.Get()[0].Sequence)
38}

Callers

nothing calls this directly

Calls 5

AddMethod · 0.95
GetMethod · 0.95
NewMigrationDataCacheFunction · 0.85
EmptyMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected