Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bufferTime): add maxBufferSize optional argument #1556

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
81 changes: 69 additions & 12 deletions spec/operators/bufferTime-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Observable.prototype.bufferTime', () => {
z: []
};

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
Expand All @@ -34,11 +34,47 @@ describe('Observable.prototype.bufferTime', () => {
z: []
};

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});

it('should emit buffers at intervals or when the buffer is full', () => {
const e1 = hot('---a---b---c---d---e---f---g-----|');
const subs = '^ !';
const t = time( '----------|');
const expected = '-------w-------x-------y---------(z|)';
const values = {
w: ['a', 'b'],
x: ['c', 'd'],
y: ['e', 'f'],
z: ['g']
};

const result = e1.bufferTime(t, null, 2, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});

it('should emit buffers at intervals or when the buffer is full test 2', () => {
const e1 = hot('---a---b---c---d---e---f---g-----|');
const subs = '^ !';
const t = time( '----------|');
const expected = '----------w--------x---------y---(z|)';
const values = {
w: ['a', 'b'],
x: ['c', 'd', 'e'],
y: ['f', 'g'],
z: []
};

const result = e1.bufferTime(t, null, 3, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});

it('should emit buffers that have been created at intervals and close after the specified delay', () => {
const e1 = hot('---a---b---c----d----e----f----g----h----i----(k|)');
// --------------------*--------------------*---- start interval
Expand All @@ -54,7 +90,28 @@ describe('Observable.prototype.bufferTime', () => {
z: ['i', 'k']
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});

it('should emit buffers that have been created at intervals and close after the specified delay ' +
'or when the buffer is full', () => {
const e1 = hot('---a---b---c----d----e----f----g----h----i----(k|)');
// --------------------*--------------------*---- start interval
// ---------------------| timespans
// ---------------------|
// -----|
const t = time( '---------------------|');
const interval = time( '--------------------|');
const expected = '----------------x-------------------y---------(z|)';
const values = {
x: ['a', 'b', 'c', 'd'],
y: ['e', 'f', 'g', 'h'],
z: ['i', 'k']
};

const result = e1.bufferTime(t, interval, 4, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});
Expand All @@ -81,7 +138,7 @@ describe('Observable.prototype.bufferTime', () => {
f: []
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -107,7 +164,7 @@ describe('Observable.prototype.bufferTime', () => {
e: []
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});
Expand All @@ -127,7 +184,7 @@ describe('Observable.prototype.bufferTime', () => {
a: ['2', '3', '4']
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
Expand All @@ -150,7 +207,7 @@ describe('Observable.prototype.bufferTime', () => {

const result = e1
.mergeMap((x: any) => Observable.of(x))
.bufferTime(t, interval, rxTestScheduler)
.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler)
.mergeMap((x: any) => Observable.of(x));

expectObservable(result, unsub).toBe(expected, values);
Expand All @@ -164,7 +221,7 @@ describe('Observable.prototype.bufferTime', () => {
const values = { b: [] };
const t = time('----------|');

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -176,7 +233,7 @@ describe('Observable.prototype.bufferTime', () => {
const t = time( '----------|');
const expected = '----------a---------a---------a---------a----';

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result, unsub).toBe(expected, { a: [] });
});
Expand All @@ -186,7 +243,7 @@ describe('Observable.prototype.bufferTime', () => {
const expected = '#';
const t = time('----------|');

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, undefined, new Error('haha'));
});
Expand All @@ -200,7 +257,7 @@ describe('Observable.prototype.bufferTime', () => {
w: ['a', 'b']
};

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -222,7 +279,7 @@ describe('Observable.prototype.bufferTime', () => {
y: ['e', 'f', 'g', 'h', 'i']
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand Down
Loading