Skip to content

Commit

Permalink
test(throttle): should not leak ChildSubscriptions (ReactiveX#2355)
Browse files Browse the repository at this point in the history
  • Loading branch information
johncvrs committed Feb 10, 2017
1 parent 3a926b9 commit 763a078
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/operators/throttle-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,25 @@ describe('Observable.prototype.throttle', () => {
}
);
});

it('should not leak when child completes before next source emit', () => {
const oStream = new Rx.Subject<number>();
let iStream: Rx.Subject<number>;
const aStream = oStream.throttle(() => {
return (iStream = new Rx.Subject<number>());
});
const result = [];
let sub = aStream.subscribe((x: number) => result.push(x));

[0, 1, 2, 3, 4].forEach((n) => {
oStream.next(n); // creates inner
iStream.complete(); // throttle will unsubscribe iStream here.
});
expect(result).to.deep.equal([0, 1, 2, 3, 4]);
// Expect one child of switch(): The oStream
expect(
(<any>sub)._subscriptions[0]._innerSub._subscriptions.length
).to.equal(1);
sub.unsubscribe();
});
});

0 comments on commit 763a078

Please sign in to comment.