Skip to content

Commit

Permalink
working expiration test, skipped for now
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Jan 2, 2024
1 parent acc9b50 commit e9564c9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions presence_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,69 @@ func TestRedisPresenceManagerWithUserMapping(t *testing.T) {
}
}

func TestRedisPresenceManagerWithUserMappingExpire(t *testing.T) {
t.Skip()
t.Parallel()
for _, tt := range redisPresenceTests {
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
node := testNode(t)
pm := newTestRedisPresenceManager(t, node, tt.UseCluster, true)
pm.config.PresenceTTL = 2 * time.Second
defer func() { _ = node.Shutdown(context.Background()) }()
defer stopRedisPresenceManager(pm)

// adding presence for the first time.
require.NoError(t, pm.AddPresence("channel", "uid", &ClientInfo{
ClientID: "uid",
UserID: "1",
}))
// same user, different conn
require.NoError(t, pm.AddPresence("channel", "uid-2", &ClientInfo{
ClientID: "uid-2",
UserID: "1",
}))
// different user, different conn
require.NoError(t, pm.AddPresence("channel", "uid-3", &ClientInfo{
ClientID: "uid-3",
UserID: "2",
}))

stats, err := pm.PresenceStats("channel")
require.NoError(t, err)
require.Equal(t, 3, stats.NumClients)
require.Equal(t, 2, stats.NumUsers)

timer := time.NewTimer(2 * time.Second)
LOOP:
for {
select {
case <-timer.C:
break LOOP
case <-time.After(500 * time.Millisecond):
// keep one entry.
require.NoError(t, pm.AddPresence("channel", "uid-2", &ClientInfo{
ClientID: "uid-2",
UserID: "1",
}))
}
}

stats, err = pm.PresenceStats("channel")
require.NoError(t, err)
require.Equal(t, 1, stats.NumClients)
require.Equal(t, 1, stats.NumUsers)

time.Sleep(2 * time.Second)

stats, err = pm.PresenceStats("channel")
require.NoError(t, err)
require.Equal(t, 0, stats.NumClients)
require.Equal(t, 0, stats.NumUsers)
})
}
}

func BenchmarkRedisAddPresence_1Ch(b *testing.B) {
for _, tt := range benchRedisTests {
b.Run(tt.Name, func(b *testing.B) {
Expand Down

0 comments on commit e9564c9

Please sign in to comment.