RxGo icon indicating copy to clipboard operation
RxGo copied to clipboard

BufferWithTimeOrCount can exceed buffer size

Open cc-stjm opened this issue 5 years ago • 1 comments

Describe the bug Calling BufferWithTimeOrCount can result in larger buffers being emitted.

To Reproduce The following test always seems to fail

func TestBufferWithTimeOrCountDoesNotExceedBufferSize(t *testing.T){
	observable := rxgo.Just(1,2,3)()
	buffers := observable.BufferWithTimeOrCount(rxgo.WithDuration(time.Second), 1)
	rxgo.Assert(context.Background(), t, buffers, rxgo.HasItems([]interface{}{1}, []interface{}{2}, []interface{}{3}))
}

The following test will intermittently fail. On my machine, I find a fail occurs on most runs if I run with go test -count 10000


func TestBufferWithTimeOrCountDoesNotExceedBufferSizeOf2(t *testing.T){
	observable := rxgo.Just(1,2,3,4,5)()
	buffers := observable.BufferWithTimeOrCount(rxgo.WithDuration(time.Second), 2)
	rxgo.Assert(context.Background(), t, buffers, rxgo.HasItems([]interface{}{1,2}, []interface{}{3,4}, []interface{}{5}))
}

Expected behavior Buffer sizes should never exceed the count passed

Additional context

cc-stjm avatar Nov 13 '20 10:11 cc-stjm

Fixed in PR https://github.com/ReactiveX/RxGo/pull/289

maguro avatar Mar 22 '21 05:03 maguro