Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-barstow committed Nov 15, 2024
1 parent b7a775a commit be7a3ff
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/util/media-sequence-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class DependantMediaSequenceSync extends MediaSequenceSync {
this.parent_ = parent;
}

calculateBaseTime_(mediaSequence, fallback) {
calculateBaseTime_(mediaSequence, segments, fallback) {
if (!this.storage_.size) {
const info = this.parent_.getSyncInfoForMediaSequence(mediaSequence);

Expand All @@ -284,6 +284,6 @@ export class DependantMediaSequenceSync extends MediaSequenceSync {
return 0;
}

return super.calculateBaseTime_(mediaSequence, fallback);
return super.calculateBaseTime_(mediaSequence, segments, fallback);
}
}
109 changes: 109 additions & 0 deletions test/util/media-sequence-sync.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import QUnit from 'qunit';
import { MediaSequenceSync } from '../../src/util/media-sequence-sync';

QUnit.module('MediaSequenceSync: update', function(hooks) {
let mediaSequenceSync;

hooks.beforeEach(function() {
mediaSequenceSync = new MediaSequenceSync();
});

QUnit.test('update calculates correct base time based on mediaSequence of new playlist', function(assert) {
const initialMediaSequence = 10;
const initialSegments = [
// Segment 10 with duration 5
{ duration: 5 },
// Segment 11 with duration 6
{ duration: 6 },
// Segment 12 with duration 7
{ duration: 7 }
];

// Initial update with starting playlist
mediaSequenceSync.update(
{
mediaSequence: initialMediaSequence,
segments: initialSegments
},
// Current time, value is used for fallback and not significant here
20
);

// Confirm that the initial update set the correct start and end times
assert.strictEqual(
mediaSequenceSync.start,
0,
'The start time is set to the initial value of 0.'
);

// Confirm the end time is the correct sum of the segment durations
// = 18
const expectedInitialEndTime = 0 + 5 + 6 + 7;

assert.strictEqual(
mediaSequenceSync.end,
expectedInitialEndTime,
'The end time is calculated correctly after the initial update.'
);

// New playlist with higher mediaSequence
let newMediaSequence = 11;
let newSegments = [
// Segment 11 with duration 4
{ duration: 4 },
// Segment 12 with duration 5
{ duration: 5 },
// Segment 13 with duration 6
{ duration: 6 }
];

// Update with the new playlist
mediaSequenceSync.update(
{
mediaSequence: newMediaSequence,
segments: newSegments
},
30
);

// Segment 10 with duration 5 has fallen off the start of the playlist
let expectedStartTime = 5;

assert.strictEqual(
mediaSequenceSync.start,
expectedStartTime,
'The base time is calculated correctly when a new playlist with a higher mediaSequence is loaded.'
);

// New playlist with lower mediaSequence
newMediaSequence = 10;
newSegments = [
// Segment 10 with duration 5
{ duration: 5 },
// Segment 11 with duration 6
{ duration: 6 },
// Segment 12 with duration 7
{ duration: 7 }
];

// Update with the new playlist
mediaSequenceSync.update(
{
mediaSequence: newMediaSequence,
segments: newSegments
},
40
);

// Expected base time is calculated by extrapolating backwards:
// Segment 11 start time: 5
// Segment 10 start time: Segment 11 start time (5) - Segment 10 duration (5) = 0
expectedStartTime = 0;

assert.strictEqual(
mediaSequenceSync.start,
expectedStartTime,
'The base time is calculated correctly when a new playlist with a lower mediaSequence is loaded.'
);
});
});

0 comments on commit be7a3ff

Please sign in to comment.