Skip to content

Commit

Permalink
test: Add missing test case for SegmentIterator
Browse files Browse the repository at this point in the history
Based on discussion of PR #3419

Change-Id: I02bfc615a169b54b94cdc624ace77d9ffefd624e
  • Loading branch information
joeyparrish committed Jun 10, 2021
1 parent 7c77ea4 commit 43a056e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/media/segment_index_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
makeReference(uri(20.30), 20, 30),
];

const additionalRefs = [
makeReference(uri(30.40), 30, 40),
makeReference(uri(40.50), 40, 50),
makeReference(uri(50.60), 50, 60),
];

const partialRefs1 = [
makeReference(uri(10.15), 10, 15),
makeReference(uri(15.20), 15, 20),
Expand Down Expand Up @@ -626,6 +632,45 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
expect(Array.from(index)).toEqual(inputRefs.slice(1));
});

it('resumes iteration after new references are added', () => {
const refs = inputRefs.slice();
const index = new shaka.media.SegmentIndex(refs);

// This simulates the pattern of calls in StreamingEngine when we buffer
// to the edge of a live stream.
const iterator = index[Symbol.iterator]();
iterator.next();
expect(iterator.current()).toBe(inputRefs[0]);

iterator.next();
expect(iterator.current()).toBe(inputRefs[1]);

iterator.next();
expect(iterator.current()).toBe(inputRefs[2]);

iterator.next();
expect(iterator.current()).toBe(null);
// After we reach the end of the iteration, we should still get null back
// on subsequent requests.
expect(iterator.current()).toBe(null);
expect(iterator.current()).toBe(null);

// Although we have reached the end, we should still be able to add new
// references and iterate to them without starting over the iteration.
refs.push(...additionalRefs);

expect(iterator.current()).toBe(additionalRefs[0]);

iterator.next();
expect(iterator.current()).toBe(additionalRefs[1]);

iterator.next();
expect(iterator.current()).toBe(additionalRefs[2]);

iterator.next();
expect(iterator.current()).toBe(null);
});

describe('seek', () => {
it('returns the matching segment', () => {
const index = new shaka.media.SegmentIndex(inputRefs);
Expand Down

0 comments on commit 43a056e

Please sign in to comment.