blob: fb4dc0d6ccaafcff8bd0f8693fc65a0f4d8ac072 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>binary-size-view</title>
<script src="./bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="./bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="./bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../static/binary-size-view.html">
<test-fixture id="basic">
<template>
<binary-size-view></binary-size-view>
</template>
</test-fixture>
<script>
suite('binary-size-view basic tests', () => {
let element;
let sandbox;
setup(() => {
element = fixture('basic');
Object.assign(element, {
plugin: {
getPluginName() { return 'binary-size'; },
restApi() {
return {
getLoggedIn: async () => true,
};
},
},
change: {
project: 'project-foo',
_number: 1,
revisions: {
'deadbeef': {
_number: 1,
},
},
},
_pluginConfig: {
gerritHost: 'gerrit.example.com',
buckets: [],
builders: [],
},
revision: {
_number: 1,
},
});
element.$.client.getOAuthToken = async () => {};
sandbox = sinon.sandbox.create();
});
teardown(() => {
sandbox.restore();
});
test('_humanByteSize below first threshold', () => {
assert.equal(element._humanByteSize(1024), '1024 B');
});
test('_humanByteSize KiB', () => {
assert.equal(element._humanByteSize(2048), '2.00 KiB');
});
test('_humanByteSize MiB', () => {
assert.equal(element._humanByteSize(12345678), '11.774 MiB');
});
test('_humanByteSize above last threshold', () => {
assert.equal(element._humanByteSize(111222333444555), '103583.8699 GiB');
});
test('_humanByteSizeDelta zero', () => {
assert.equal(element._humanByteSizeDelta(0, 0), '—');
});
test('_humanByteSizeDelta positive', () => {
assert.equal(element._humanByteSizeDelta(0, 1), '+1 B');
});
test('_humanByteSizeDelta negative', () => {
assert.equal(element._humanByteSizeDelta(123456, 0), '−120.56 KiB');
});
test('_percentSizeDelta negative', () => {
assert.equal(element._percentSizeDelta(10000000, 9686630), '−3.1337%');
});
test('_getBuilds', async () => {
const searchBuilds = sandbox.stub(element.$.client, 'searchBuilds');
searchBuilds.onCall(0).returns(Promise.resolve(['build1', 'build2']));
searchBuilds.onCall(1).returns(Promise.resolve(['build3']));
assert.deepEqual(
await element._getBuilds(['some.bucket', 'a.b.c'],
['buildset:foo/bar', 'baz']),
['build1', 'build2', 'build3']);
const params = searchBuilds.getCall(0).args[0];
assert.deepEqual(params.getAll('tag'), ['buildset:foo/bar']);
assert.deepEqual(params.getAll('bucket'), ['some.bucket', 'a.b.c']);
});
test('_selectRelevantBuilds', () => {
const builds = [
{'result_details_json':
'{"properties": {"got_revision": "abc", "binary_sizes": {}}}'},
{'result_details_json': '{"properties": {}}'},
{'result_details_json': 'in{valid'},
{}];
assert.deepEqual(element._selectRelevantBuilds(builds), [builds[0]]);
});
test('_sortUniqueInfoRows sorts', () => {
const rows = [
{builder: 'abc', binary: 'b.so', id: '2'},
{builder: 'abc', binary: 'a.so', id: '1'},
];
assert.deepEqual(element._sortUniqueInfoRows(rows), [rows[1], rows[0]]);
});
test('_sortUniqueInfoRows keeps only latest', () => {
const rows = [
{builder: 'abc', binary: 'a.so', id: '3'},
{builder: 'abc', binary: 'b.so', id: '2'},
{builder: 'abc', binary: 'a.so', id: '1'},
];
// Remember: build IDs are monotonically decreasing.
assert.deepEqual(element._sortUniqueInfoRows(rows), [rows[2], rows[1]]);
});
test('_tryjobTags', () => {
element.change = {_number: 42};
element._pluginConfig = {gerritHost: 'webrtc-review.googlesource.com'};
assert.deepEqual(element._tryjobTags([2, 3, 4]), [
'buildset:patch/gerrit/webrtc-review.googlesource.com/42/2',
'buildset:patch/gerrit/webrtc-review.googlesource.com/42/3',
'buildset:patch/gerrit/webrtc-review.googlesource.com/42/4']);
});
test('_revisionTags', () => {
element.change = {project: 'src'};
element._pluginConfig = {gitHost: 'webrtc.googlesource.com'};
const builds = [
{properties: {got_revision: 'deadbeef'}},
{properties: {got_revision: 'da39a3ee'}},
{properties: {got_revision: 'deadbeef'}},
];
assert.deepEqual(element._revisionTags(builds), [
'buildset:commit/gitiles/webrtc.googlesource.com/src/+/deadbeef',
'buildset:commit/gitiles/webrtc.googlesource.com/src/+/da39a3ee',
]);
});
const BUILDERS = [{
'tryBucket': 'bucket.try', 'tryBuilder': 'builder1',
'ciBucket': 'bucket.ci', 'ciBuilder': 'Builder 1',
}, {
'tryBucket': 'bucket.try', 'tryBuilder': 'builder2',
'ciBucket': 'bucket.ci', 'ciBuilder': 'Builder 2',
}, {
'tryBucket': 'other.try', 'tryBuilder': 'builder1',
'ciBucket': 'other.ci', 'ciBuilder': 'Builder 1',
}];
Object.freeze(BUILDERS);
test('_binarySizeInfo basic', () => {
assert.deepEqual(element._collateBinarySizeInfoFromBuildPairs(BUILDERS, [
{bucket: 'bucket.try', tags: ['builder:builder1'],
id: '7', url: 'http://example.org/builder1/7',
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1337}}},
], [
{bucket: 'bucket.ci', tags: ['builder:Builder 1'],
id: '8', url: 'http://example.org/Builder%201/8',
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1338}}},
]), [{
id: '7',
builder: 'builder1',
binary: 'a',
trySize: 1337,
tryUrl: 'http://example.org/builder1/7',
ciSize: 1338,
ciUrl: 'http://example.org/Builder%201/8',
}]);
});
test('_binarySizeInfo no match on bucket', () => {
assert.deepEqual(element._collateBinarySizeInfoFromBuildPairs(BUILDERS, [
{bucket: 'bucket.try', tags: ['builder:builder1'],
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1337}}},
], [
{bucket: 'other.ci', tags: ['builder:Builder 1'],
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1338}}},
]), []);
});
test('_binarySizeInfo no match on binary', () => {
assert.deepEqual(element._collateBinarySizeInfoFromBuildPairs(BUILDERS, [
{bucket: 'bucket.try', tags: ['builder:builder1'],
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1337}}},
], [
{bucket: 'bucket.ci', tags: ['builder:Builder 1'],
properties: {got_revision: 'deadbeef', binary_sizes: {'b': 1338}}},
]), []);
});
test('_binarySizeInfo multiple try builds', () => {
const result = element._collateBinarySizeInfoFromBuildPairs(BUILDERS, [
{bucket: 'bucket.try', tags: ['builder:builder1'],
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1337,
'b': 2222}}},
{bucket: 'bucket.try', tags: ['builder:builder1'],
properties: {got_revision: 'da39a3ee', binary_sizes: {'a': 1111}}},
{bucket: 'bucket.try', tags: ['builder:builder1'],
properties: {got_revision: 'da39a3ee', binary_sizes: {'a': 1110}}},
], [
{bucket: 'bucket.ci', tags: ['builder:Builder 1'],
properties: {got_revision: 'deadbeef', binary_sizes: {'a': 1338,
'b': 2223}}},
{bucket: 'bucket.ci', tags: ['builder:Builder 1'],
properties: {got_revision: 'da39a3ee', binary_sizes: {'a': 1112}}},
]);
assert.equal(result.length, 4);
assert.equal(result[0].builder, 'builder1');
assert.equal(result[0].binary, 'a');
assert.equal(result[0].ciSize, 1338);
assert.equal(result[1].builder, 'builder1');
assert.equal(result[1].binary, 'b');
assert.equal(result[1].ciSize, 2223);
assert.equal(result[2].builder, 'builder1');
assert.equal(result[2].binary, 'a');
assert.equal(result[2].trySize, 1111);
assert.equal(result[3].builder, 'builder1');
assert.equal(result[3].binary, 'a');
assert.equal(result[3].trySize, 1110);
});
test('_getBuilder', () => {
assert.equal(
element._getBuilder({tags: ['foo:bar', 'builder:bob']}), 'bob');
});
test('exponential backoff', async () => {
assert.isNotOk(element._updateTimeoutID);
sandbox.stub(element.$.client, 'searchBuilds',
() => Promise.reject('nope'));
const timeoutMs = element._updateIntervalMs;
await element._refresh();
assert.isAbove(element._updateIntervalMs, 2 * timeoutMs);
assert.isOk(element._updateTimeoutID);
});
test('valid patch numbers', () => {
let change = {
revisions: {
rev1: {_number: 1, kind: 'TRIVIAL_REBASE'},
rev2: {_number: 2, kind: 'TRIVIAL_REBASE'},
rev3: {_number: 3, kind: 'TRIVIAL_REBASE'},
},
};
assert.deepEqual(element._computeValidPatchNums(change, 3), [3, 2, 1]);
assert.deepEqual(element._computeValidPatchNums(change, 2), [2, 1]);
change.status = 'MERGED';
assert.deepEqual(element._computeValidPatchNums(change, 3), [2, 1]);
change = {
revisions: {
rev1: {_number: 1, kind: 'TRIVIAL_REBASE'},
rev2: {_number: 2, kind: 'REBASE'},
rev3: {_number: 3, kind: 'TRIVIAL_REBASE'},
},
};
assert.deepEqual(element._computeValidPatchNums(change, 3), [3, 2]);
});
});
</script>