Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/queue/fact_stream_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ func TestRedisFactStream_StreamKeyLayout(t *testing.T) {

// TestRedisFactStream_TrimIsRateLimited pins the amortized trim: the first publish on a stream
// trims it, and a publish inside the same interval does not.
//
// Nothing is asserted about the opening publish's own entry. Its trim runs after its XADD, so with
// a 1 ms TTL a slow moment between the two ages that entry out.
func TestRedisFactStream_TrimIsRateLimited(t *testing.T) {
store, mr := newTestRedisStoreWithRedis(t)
stream := store.FactStream(RedisFactStreamConfig{TTL: time.Millisecond, TrimInterval: time.Hour})
key := factStreamTestKey("", "configmaps")
ctx := t.Context()

require.NoError(t, stream.PublishFacts(ctx, key, authorFacts("opening")))
require.NoError(t, stream.PublishFacts(ctx, key, authorFacts("first")))
time.Sleep(10 * time.Millisecond)
require.NoError(t, stream.PublishFacts(ctx, key, authorFacts("second")))
Expand All @@ -47,7 +51,10 @@ func TestRedisFactStream_TrimIsRateLimited(t *testing.T) {
// the TTL horizon is enforced only when the next trim comes due.
entries, err := mr.Stream(stream.streamKey(key))
require.NoError(t, err)
require.Len(t, entries, 2)
require.GreaterOrEqual(t, len(entries), 2)
recent := entries[len(entries)-2:]
require.Contains(t, recent[0].Values[1], `"author":"first"`)
require.Contains(t, recent[1].Values[1], `"author":"second"`)
}

// TestRedisFactStream_StreamExpiresWhenNobodyWritesToItAnyMore pins the counterpart to the
Expand Down
Loading