Skip to content

Commit

Permalink
test: Fix prefetch test fake pollution (#6285)
Browse files Browse the repository at this point in the history
When overwriting any part of the library or platform in a test, we must
restore it afterward.

This fixes two test suites that overwrote SegmentPrefetch with a test
fake, but never restored the original.

This fixes failures in unrelated preload tests running in uncompiled
mode.

Closes #6275
  • Loading branch information
joeyparrish committed Feb 23, 2024
1 parent 250ad33 commit 852d5ba
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3996,6 +3996,12 @@ describe('StreamingEngine', () => {
}

describe('prefetch segments', () => {
let originalPrefetch;

beforeAll(() => {
originalPrefetch = shaka.media.SegmentPrefetch;
});

beforeEach(() => {
shaka.media.SegmentPrefetch = Util.spyFunc(
jasmine.createSpy('SegmentPrefetch')
Expand All @@ -4013,6 +4019,10 @@ describe('StreamingEngine', () => {
streamingEngine.configure(config);
});

afterAll(() => {
shaka.media.SegmentPrefetch = originalPrefetch;
});

it('should use prefetched segment without fetching again', async () => {
streamingEngine.switchVariant(variant);
await streamingEngine.start();
Expand Down Expand Up @@ -4080,6 +4090,12 @@ describe('StreamingEngine', () => {
let altVariant;
let segmentPrefetchesCreated;

let originalPrefetch;

beforeAll(() => {
originalPrefetch = shaka.media.SegmentPrefetch;
});

beforeEach(() => {
segmentPrefetchesCreated = 0;
shaka.media.SegmentPrefetch = Util.spyFunc(
Expand All @@ -4101,6 +4117,10 @@ describe('StreamingEngine', () => {
streamingEngine.configure(config);
});

afterAll(() => {
shaka.media.SegmentPrefetch = originalPrefetch;
});

it('should prefetch all audio variants for the language', async () => {
const segmentType = shaka.net.NetworkingEngine.RequestType.SEGMENT;
const context = {
Expand Down

0 comments on commit 852d5ba

Please sign in to comment.