Skip to content

Commit

Permalink
test: add a test moving average decaying even without new data
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev committed Jun 18, 2021
1 parent 0f35f7e commit d2313dd
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"netlify": "node scripts/netlify.js",
"build-test": "cross-env-shell TEST_BUNDLE_ONLY=1 'npm run build'",
"build-prod": "cross-env-shell NO_TEST_BUNDLE=1 'npm run build'",
"build": "npm-run-all -s clean -p build:*",
"build": "npm-run-all -s clean -p build:prod build:test",
"build:js": "rollup -c scripts/rollup.config.js",
"docs": "npm-run-all docs:*",
"docs:api": "jsdoc src -g plugins/markdown -r -d docs/api",
Expand Down Expand Up @@ -70,6 +70,7 @@
},
"devDependencies": {
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-strip": "^2.0.1",
"@videojs/generator-helpers": "~2.0.1",
"d3": "^3.4.8",
"es5-shim": "^4.5.13",
Expand Down
10 changes: 10 additions & 0 deletions scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const worker = require('rollup-plugin-worker-factory');
const {terser} = require('rollup-plugin-terser');
const createTestData = require('./create-test-data.js');
const replace = require('@rollup/plugin-replace');
const strip = require('@rollup/plugin-strip');

const CI_TEST_TYPE = process.env.CI_TEST_TYPE || '';
const NO_TEST_BUNDLE = process.env.NO_TEST_BUNDLE || '';

let syncWorker;
// see https://github.com/videojs/videojs-generate-rollup-config
Expand Down Expand Up @@ -57,6 +59,11 @@ const options = {
}
defaults.module.unshift('replace');

if (NO_TEST_BUNDLE) {
defaults.module.unshift('strip');
defaults.browser.unshift('strip');
}

return defaults;
},
primedPlugins(defaults) {
Expand All @@ -71,6 +78,9 @@ const options = {
output: {comments: 'some'},
compress: {passes: 2}
}),
strip: strip({
functions: ['TEST_ONLY_*']
}),
createTestData: createTestData()
});

Expand Down
45 changes: 45 additions & 0 deletions test/playlist-selectors.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import document from 'global/document';
import {
TEST_ONLY_SIMPLE_SELECTOR,
simpleSelector,
movingAverageBandwidthSelector,
minRebufferMaxBandwidthSelector,
Expand Down Expand Up @@ -64,6 +65,50 @@ test('Exponential moving average has a configurable decay parameter', function(a
assert.equal(playlist.attributes.BANDWIDTH, 50, 'selected the middle playlist');
});

test('Calling exponential moing average wont decay average unless new bandwidth data was provided', function(assert) {
let playlist;
const simSel = simpleSelector;
const bandwidthAverages = [];

const resetSimpleSelector = TEST_ONLY_SIMPLE_SELECTOR((...args) => {
// second argument to simpleSelector is the average
bandwidthAverages.push(args[1]);
return simSel(...args);
});

this.vhs.playlists.master.playlists = [
{ attributes: { BANDWIDTH: 1 } },
{ attributes: { BANDWIDTH: 50 } },
{ attributes: { BANDWIDTH: 100 } }
];

const fiftyPercentDecay = movingAverageBandwidthSelector(0.50);

this.vhs.systemBandwidth = 50 * Config.BANDWIDTH_VARIANCE + 1;
playlist = fiftyPercentDecay.call(this.vhs);
assert.equal(playlist.attributes.BANDWIDTH, 50, 'selected the middle playlist');

this.vhs.systemBandwidth = 1000 * Config.BANDWIDTH_VARIANCE + 1;
playlist = fiftyPercentDecay.call(this.vhs);
assert.equal(playlist.attributes.BANDWIDTH, 100, 'selected the top playlist');

// using the systemBandwidth values above, 50->1000
// we decay into 1000 after 50 iterations
let i = 50;

while (i--) {
playlist = fiftyPercentDecay.call(this.vhs);
}

assert.equal(
bandwidthAverages[bandwidthAverages.length - 1],
bandwidthAverages[1],
'bandwidth should only change when we get new bandwidth data'
);

resetSimpleSelector();
});

test(
'minRebufferMaxBandwidthSelector picks highest rendition without rebuffering',
function(assert) {
Expand Down

0 comments on commit d2313dd

Please sign in to comment.