2015-03-13 06:10:11 -04:00
|
|
|
import {
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
|
|
|
} from 'angular2/test_lib';
|
2015-02-20 16:32:54 -05:00
|
|
|
|
|
|
|
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
|
|
|
|
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
|
|
|
|
|
2015-03-02 12:23:09 -05:00
|
|
|
import { Metric, MultiMetric, bind, Injector } from 'benchpress/common';
|
2015-02-20 16:32:54 -05:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
function createMetric(ids) {
|
2015-04-10 20:05:31 -04:00
|
|
|
return Injector.resolveAndCreate([
|
2015-02-20 16:32:54 -05:00
|
|
|
ListWrapper.map(ids, (id) => bind(id).toValue(new MockMetric(id)) ),
|
|
|
|
MultiMetric.createBindings(ids)
|
|
|
|
]).asyncGet(MultiMetric);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('multi metric', () => {
|
|
|
|
|
2015-03-13 06:10:11 -04:00
|
|
|
it('should merge descriptions', inject([AsyncTestCompleter], (async) => {
|
2015-02-20 16:32:54 -05:00
|
|
|
createMetric(['m1', 'm2']).then( (m) => {
|
|
|
|
expect(m.describe()).toEqual({
|
|
|
|
'm1': 'describe', 'm2': 'describe'
|
|
|
|
});
|
2015-03-13 06:10:11 -04:00
|
|
|
async.done();
|
2015-02-20 16:32:54 -05:00
|
|
|
});
|
2015-03-13 06:10:11 -04:00
|
|
|
}));
|
2015-02-20 16:32:54 -05:00
|
|
|
|
2015-03-13 06:10:11 -04:00
|
|
|
it('should merge all beginMeasure calls', inject([AsyncTestCompleter], (async) => {
|
2015-02-20 16:32:54 -05:00
|
|
|
createMetric(['m1', 'm2'])
|
|
|
|
.then( (m) => m.beginMeasure() )
|
|
|
|
.then( (values) => {
|
|
|
|
expect(values).toEqual([
|
|
|
|
'm1_beginMeasure', 'm2_beginMeasure'
|
|
|
|
]);
|
2015-03-13 06:10:11 -04:00
|
|
|
async.done();
|
2015-02-20 16:32:54 -05:00
|
|
|
});
|
2015-03-13 06:10:11 -04:00
|
|
|
}));
|
2015-02-20 16:32:54 -05:00
|
|
|
|
|
|
|
[false, true].forEach( (restartFlag) => {
|
2015-03-13 06:10:11 -04:00
|
|
|
it(`should merge all endMeasure calls for restart=${restartFlag}`, inject([AsyncTestCompleter], (async) => {
|
2015-02-20 16:32:54 -05:00
|
|
|
createMetric(['m1', 'm2'])
|
|
|
|
.then( (m) => m.endMeasure(restartFlag) )
|
|
|
|
.then( (values) => {
|
|
|
|
expect(values).toEqual({
|
|
|
|
'm1': { 'restart': restartFlag },
|
|
|
|
'm2': { 'restart': restartFlag }
|
|
|
|
});
|
2015-03-13 06:10:11 -04:00
|
|
|
async.done();
|
2015-02-20 16:32:54 -05:00
|
|
|
});
|
2015-03-13 06:10:11 -04:00
|
|
|
}));
|
2015-02-20 16:32:54 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockMetric extends Metric {
|
|
|
|
_id:string;
|
|
|
|
|
|
|
|
constructor(id) {
|
|
|
|
super();
|
|
|
|
this._id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
beginMeasure():Promise {
|
|
|
|
return PromiseWrapper.resolve(`${this._id}_beginMeasure`);
|
|
|
|
}
|
|
|
|
|
|
|
|
endMeasure(restart:boolean):Promise<StringMap> {
|
|
|
|
var result = {};
|
|
|
|
result[this._id] = {
|
|
|
|
'restart': restart
|
|
|
|
};
|
|
|
|
return PromiseWrapper.resolve(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe():StringMap {
|
|
|
|
var result = {};
|
|
|
|
result[this._id] = 'describe';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|