Skip to content

Commit 821058d

Browse files
committed
chore: improve test coverage
1 parent 12a5e00 commit 821058d

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

asynciterator.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,9 +1753,11 @@ export class UnionIterator<T> extends AsyncIterator<T> {
17531753
while (this._size < this._maxParallelIterators && (iterator = _sources.read()) !== null) {
17541754
// TODO - it would be nice to skip adding sources if it is a single or no
17551755
// element iterator.
1756-
this._addSource(iterator);
1757-
if ((item = iterator.read()) !== null)
1758-
return item;
1756+
// if (!iterator.done) {
1757+
this._addSource(iterator);
1758+
if ((item = iterator.read()) !== null)
1759+
return item;
1760+
// }
17591761
}
17601762

17611763
if (this._size === 0 && this._sources.done)
@@ -1798,7 +1800,10 @@ function destinationRemoveEmptySources<T>(this: InternalSource<T>) {
17981800

17991801
// else if (destination._size < destination._maxParallelIterators && destination._sources.readable) {
18001802
// TODO: Add a test case for this
1801-
this.readable = true;
1803+
if (this.readable)
1804+
this.emit('readable')
1805+
else
1806+
this.readable = true;
18021807
// TODO: Future performance improvement - continue re-filling the circular linked list
18031808
// }
18041809
}

test/UnionIterator-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ describe('UnionIterator', () => {
6868
(await toArray(iterator)).sort().should.eql([0, 1, 2]);
6969
});
7070

71+
it('should include all data from 0 sources - with maxParallelIterators: 1', async () => {
72+
const iterator = new UnionIterator([
73+
], { maxParallelIterators: 1 });
74+
(await toArray(iterator)).sort().should.eql([]);
75+
});
76+
77+
it('should include all data from 1 non-empty source - with maxParallelIterators: 1', async () => {
78+
const iterator = new UnionIterator([
79+
range(0, 2),
80+
], { maxParallelIterators: 1 });
81+
(await toArray(iterator)).sort().should.eql([0, 1, 2]);
82+
});
83+
84+
it('should include all data from 2 non-empty sources - with maxParallelIterators: 1', async () => {
85+
const iterator = new UnionIterator([
86+
range(0, 2),
87+
range(3, 4),
88+
], { maxParallelIterators: 1 });
89+
(await toArray(iterator)).sort().should.eql([0, 1, 2, 3, 4]);
90+
});
91+
7192
it('should include all data from 1 non-empty and 4 empty sources - with maxParallelIterators: 1', async () => {
7293
const iterator = new UnionIterator([
7394
new EmptyIterator(),
@@ -79,6 +100,23 @@ describe('UnionIterator', () => {
79100
(await toArray(iterator)).sort().should.eql([0, 1, 2]);
80101
});
81102

103+
it('should include all data from 4 empty sources - with maxParallelIterators: 1', async () => {
104+
const iterator = new UnionIterator([
105+
new EmptyIterator(),
106+
new EmptyIterator(),
107+
new EmptyIterator(),
108+
new EmptyIterator(),
109+
], { maxParallelIterators: 1 });
110+
(await toArray(iterator)).sort().should.eql([]);
111+
});
112+
113+
it('should include all data from 1 empty source - with maxParallelIterators: 1', async () => {
114+
const iterator = new UnionIterator([
115+
new EmptyIterator(),
116+
], { maxParallelIterators: 1 });
117+
(await toArray(iterator)).sort().should.eql([]);
118+
});
119+
82120
describe('when constructed with an array of 0 sources', () => {
83121
let iterator;
84122
before(() => {

0 commit comments

Comments
 (0)