package output import ( "context" "testing" "time" ) func TestFrameQueuePushPop(t *testing.T) { q := NewFrameQueue(2) ctx := context.Background() frame := &CompositeFrame{Sequence: 1} if err := q.Push(ctx, frame); err != nil { t.Fatalf("push failed: %v", err) } if got := q.Depth(); got != 1 { t.Fatalf("expected depth 1, got %d", got) } if got := q.FillLevel(); got <= 0 || got >= 1 { t.Fatalf("unexpected fill level: %f", got) } popped, err := q.Pop(ctx) if err != nil { t.Fatalf("pop failed: %v", err) } if popped != frame { t.Fatal("popped frame differs from pushed frame") } if q.Depth() != 0 { t.Fatalf("expected depth 0 after pop, got %d", q.Depth()) } stats := q.Stats() if stats.HighWaterMark == 0 { t.Fatal("expected high water mark to track push") } if stats.LowWaterMark != 0 { t.Fatalf("expected low water mark 0, got %d", stats.LowWaterMark) } } func TestFrameQueuePushTimeout(t *testing.T) { q := NewFrameQueue(1) ctx := context.Background() frame := &CompositeFrame{Sequence: 42} if err := q.Push(ctx, frame); err != nil { t.Fatalf("initial push: %v", err) } shortCtx, cancel := context.WithTimeout(ctx, 5*time.Millisecond) defer cancel() if err := q.Push(shortCtx, frame); err == nil { t.Fatalf("expected timeout when pushing into full queue") } stats := q.Stats() if stats.PushTimeouts == 0 { t.Fatalf("expected push timeout counter to increment, got %d", stats.PushTimeouts) } _, _ = q.Pop(ctx) } func TestFrameQueueCounters(t *testing.T) { q := NewFrameQueue(1) q.RecordDrop() q.RecordRepeat() q.RecordMute() stats := q.Stats() if stats.DroppedFrames != 1 { t.Fatalf("expected 1 drop, got %d", stats.DroppedFrames) } if stats.RepeatedFrames != 1 { t.Fatalf("expected 1 repeat, got %d", stats.RepeatedFrames) } if stats.MutedFrames != 1 { t.Fatalf("expected 1 mute, got %d", stats.MutedFrames) } }