Changeset 212520 in webkit


Ignore:
Timestamp:
Feb 16, 2017 7:50:12 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Modernize and fix measurement-set tests
https://bugs.webkit.org/show_bug.cgi?id=168484

Reviewed by Joseph Pecoraro.

Modernized and fixed the tests in measurement-set-tests.js.

  1. Return a promise instead of manually calling done in then/catch hanlders.
  2. Use arrow function everywhere.
  3. Explicitly assert the number of calls to callbacks instead of asserting never reached.

The test case labled "should return false when the range ends after the fetched cluster"
was incorrectly asserting that hasFetchedRange returns false when the end time is after
the primary cluster's end time. Test an interval before the primary cluster instead.

Added a test case for hasFetchedRange returning true when the end time appears after
the end of the primary cluster and fixed hasFetchedRange to that end. Since there are
no data points after the primary cluster which is chronologically the last cluster,
there is nothing to fetch beyond its end time.

  • public/v3/models/measurement-set.js:

(MeasurementSet.prototype.hasFetchedRange): Fixed the bug that this function returned
false when the end time was after the primary cluster's end by truncating the range by
the end of the primary cluster.

  • unit-tests/measurement-set-tests.js:
  • unit-tests/resources/mock-remote-api.js:

(assert.notReached.assert.notReached): Deleted. It's no longer used by any tests.

Location:
trunk/Websites/perf.webkit.org
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Websites/perf.webkit.org/ChangeLog

    r212421 r212520  
     12017-02-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Modernize and fix measurement-set tests
     4        https://bugs.webkit.org/show_bug.cgi?id=168484
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Modernized and fixed the tests in measurement-set-tests.js.
     9
     10        1. Return a promise instead of manually calling done in then/catch hanlders.
     11        2. Use arrow function everywhere.
     12        3. Explicitly assert the number of calls to callbacks instead of asserting never reached.
     13
     14        The test case labled "should return false when the range ends after the fetched cluster"
     15        was incorrectly asserting that hasFetchedRange returns false when the end time is after
     16        the primary cluster's end time. Test an interval before the primary cluster instead.
     17
     18        Added a test case for hasFetchedRange returning true when the end time appears after
     19        the end of the primary cluster and fixed hasFetchedRange to that end. Since there are
     20        no data points after the primary cluster which is chronologically the last cluster,
     21        there is nothing to fetch beyond its end time.
     22
     23        * public/v3/models/measurement-set.js:
     24        (MeasurementSet.prototype.hasFetchedRange): Fixed the bug that this function returned
     25        false when the end time was after the primary cluster's end by truncating the range by
     26        the end of the primary cluster.
     27        * unit-tests/measurement-set-tests.js:
     28        * unit-tests/resources/mock-remote-api.js:
     29        (assert.notReached.assert.notReached): Deleted. It's no longer used by any tests.
     30
    1312017-02-15  Ryosuke Niwa  <rniwa@webkit.org>
    232
  • trunk/Websites/perf.webkit.org/public/v3/models/measurement-set.js

    r204296 r212520  
    162162    {
    163163        console.assert(startTime < endTime);
    164         var foundStart = false;
    165         var previousEndTime = null;
     164        let foundStart = false;
     165        let previousEndTime = null;
     166        endTime = Math.min(endTime, this._primaryClusterEndTime);
    166167        for (var cluster of this._sortedClusters) {
    167             var containsStart = cluster.startTime() <= startTime && startTime <= cluster.endTime();
    168             var containsEnd = cluster.startTime() <= endTime && endTime <= cluster.endTime();
    169             var preceedingClusterIsMissing = previousEndTime !== null && previousEndTime != cluster.startTime();
     168            const containsStart = cluster.startTime() <= startTime && startTime <= cluster.endTime();
     169            const containsEnd = cluster.startTime() <= endTime && endTime <= cluster.endTime();
     170            const preceedingClusterIsMissing = previousEndTime !== null && previousEndTime != cluster.startTime();
    170171            if (containsStart && containsEnd)
    171172                return true;
  • trunk/Websites/perf.webkit.org/unit-tests/measurement-set-tests.js

    r210673 r212520  
    99const MockModels = require('./resources/mock-v3-models.js').MockModels;
    1010
    11 describe('MeasurementSet', function () {
     11describe('MeasurementSet', () => {
    1212    MockModels.inject();
    1313    let requests = MockRemoteAPI.inject();
    1414
    15     beforeEach(function () {
     15    beforeEach(() => {
    1616        MeasurementSet._set = null;
    1717    });
     
    1919    function waitForMeasurementSet()
    2020    {
    21         return Promise.resolve().then(function () {
     21        return Promise.resolve().then(() => {
    2222            return Promise.resolve();
    23         }).then(function () {
     23        }).then(() => {
    2424            return Promise.resolve();
    2525        });
    2626    }
    2727
    28     describe('findSet', function () {
    29         it('should create a new MeasurementSet for a new pair of platform and matric', function () {
     28    describe('findSet', () => {
     29        it('should create a new MeasurementSet for a new pair of platform and matric', () => {
    3030            assert.notEqual(MeasurementSet.findSet(1, 1, 3000), MeasurementSet.findSet(1, 2, 3000));
    3131            assert.notEqual(MeasurementSet.findSet(1, 1, 3000), MeasurementSet.findSet(2, 1, 3000));
    3232        });
    3333
    34         it('should not create a new MeasurementSet when the same pair of platform and matric are requested', function () {
     34        it('should not create a new MeasurementSet when the same pair of platform and matric are requested', () => {
    3535            assert.equal(MeasurementSet.findSet(1, 1), MeasurementSet.findSet(1, 1));
    3636        });
    3737    });
    3838
    39     describe('findClusters', function () {
    40 
    41         it('should return clusters that exist', function (done) {
    42             var set = MeasurementSet.findSet(1, 1, 1467852503940);
    43             var callCount = 0;
    44             var promise = set.fetchBetween(1465084800000, 1470268800000, function () {
     39    describe('findClusters', () => {
     40
     41        it('should return clusters that exist', () => {
     42            const set = MeasurementSet.findSet(1, 1, 1467852503940);
     43            let callCount = 0;
     44            const promise = set.fetchBetween(1465084800000, 1470268800000, () => {
    4545                callCount++;
    4646            });
     
    5959                'status': 'OK'});
    6060
    61             promise.then(function () {
     61            return promise.then(() => {
    6262                assert.deepEqual(set.findClusters(0, Date.now()), [1449532800000, 1454716800000, 1459900800000, 1465084800000, 1470268800000]);
    63                 done();
    64             }).catch(function (error) {
    65                 done(error);
    6663            });
    6764        });
     
    6966    });
    7067
    71     describe('fetchBetween', function () {
    72         it('should always request the cached primary cluster first', function () {
    73             var set = MeasurementSet.findSet(1, 1, 3000);
    74             set.fetchBetween(1000, 2000, function () { assert.notReached(); });
    75             assert.equal(requests.length, 1);
    76             assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
    77         });
    78 
    79         it('should not request the cached primary cluster twice', function () {
    80             var set = MeasurementSet.findSet(1, 1, 3000);
    81             set.fetchBetween(1000, 2000, function () { assert.notReached(); });
    82             assert.equal(requests.length, 1);
    83             assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
    84             set.fetchBetween(2000, 3000, function () { assert.notReached(); });
    85             assert.equal(requests.length, 1);
    86         });
    87 
    88         it('should invoke the callback when the up-to-date cached primary cluster is fetched and it matches the requested range', function (done) {
    89             var set = MeasurementSet.findSet(1, 1, 3000);
    90             var callCount = 0;
    91             var promise = set.fetchBetween(2000, 3000, function () {
    92                 callCount++;
    93             });
     68    describe('fetchBetween', () => {
     69        it('should always request the cached primary cluster first', () => {
     70            const set = MeasurementSet.findSet(1, 1, 3000);
     71            let callCount = 0;
     72            set.fetchBetween(1000, 2000, () => callCount++);
     73            assert.equal(requests.length, 1);
     74            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     75            assert.equal(callCount, 0);
     76        });
     77
     78        it('should not request the cached primary cluster twice', () => {
     79            const set = MeasurementSet.findSet(1, 1, 3000);
     80            let callCount = 0;
     81            set.fetchBetween(1000, 2000, () => callCount++);
     82            assert.equal(requests.length, 1);
     83            assert.equal(callCount, 0);
     84            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     85            set.fetchBetween(2000, 3000, () => callCount++);
     86            assert.equal(requests.length, 1);
     87            assert.equal(callCount, 0);
     88        });
     89
     90        it('should invoke the callback when the requested range is in the cached primary cluster', () => {
     91            const set = MeasurementSet.findSet(1, 1, 3000);
     92            let callCount = 0;
     93            const promise = set.fetchBetween(2000, 3000, () => callCount++);
    9494            assert.equal(requests.length, 1);
    9595            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    106106                'status': 'OK'});
    107107
    108             promise.then(function () {
     108            return promise.then(() => {
    109109                assert.equal(callCount, 1);
    110110                assert.equal(requests.length, 1);
    111                 done();
    112             }).catch(function (error) {
    113                 done(error);
    114             });
    115         });
    116 
    117         it('should invoke the callback and fetch a secondary cluster when the cached primary cluster is up-to-date and within in the requested range', function (done) {
    118             var set = MeasurementSet.findSet(1, 1, 3000);
    119             var callCount = 0;
    120             var promise = set.fetchBetween(1000, 3000, function () {
    121                 callCount++;
    122             });
     111            });
     112        });
     113
     114        it('should invoke the callback and fetch a secondary cluster when the cached primary cluster is within the requested range', () => {
     115            const set = MeasurementSet.findSet(1, 1, 3000);
     116            let callCount = 0;
     117            const promise = set.fetchBetween(1000, 3000, () => callCount++);
    123118            assert.equal(requests.length, 1);
    124119            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    135130                'status': 'OK'});
    136131
    137             waitForMeasurementSet().then(function () {
     132            return waitForMeasurementSet().then(() => {
    138133                assert.equal(callCount, 1);
    139134                assert.equal(requests.length, 2);
    140135                assert.equal(requests[1].url, '../data/measurement-set-1-1-2000.json');
    141                 done();
    142             }).catch(function (error) {
    143                 done(error);
    144             });
    145         });
    146 
    147         it('should request additional secondary clusters as requested', function (done) {
    148             var set = MeasurementSet.findSet(1, 1, 5000);
    149             set.fetchBetween(2000, 3000, function () {
    150                 assert.notReached();
    151             });
     136            });
     137        });
     138
     139        it('should request additional secondary clusters as requested', () => {
     140            const set = MeasurementSet.findSet(1, 1, 5000);
     141            let callCountForWaitingCallback = 0;
     142            set.fetchBetween(2000, 3000, () => callCountForWaitingCallback++);
    152143            assert.equal(requests.length, 1);
    153144            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    164155                'status': 'OK'});
    165156
    166             var callCount = 0;
    167             waitForMeasurementSet().then(function () {
     157            let callCount = 0;
     158            return waitForMeasurementSet().then(() => {
    168159                assert.equal(requests.length, 2);
    169160                assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
    170161
    171                 set.fetchBetween(0, 7000, function () { callCount++; });
    172 
    173                 return waitForMeasurementSet();
    174             }).then(function () {
     162                set.fetchBetween(0, 7000, () => callCount++);
     163
     164                return waitForMeasurementSet();
     165            }).then(() => {
     166                assert.equal(callCountForWaitingCallback, 0);
    175167                assert.equal(callCount, 1);
    176168                assert.equal(requests.length, 4);
    177169                assert.equal(requests[2].url, '../data/measurement-set-1-1-2000.json');
    178170                assert.equal(requests[3].url, '../data/measurement-set-1-1-4000.json');
    179 
    180                 done();
    181             }).catch(function (error) {
    182                 done(error);
    183             });
    184         });
    185 
    186         it('should request secondary clusters which forms a superset of the requested range', function (done) {
    187             var set = MeasurementSet.findSet(1, 1, 5000);
    188             set.fetchBetween(2707, 4207, function () {
    189                 assert.notReached();
    190             });
     171            });
     172        });
     173
     174        it('should request secondary clusters which forms a superset of the requested range', () => {
     175            const set = MeasurementSet.findSet(1, 1, 5000);
     176            let callCount = 0;
     177            const promise = set.fetchBetween(2707, 4207, () => callCount++);
    191178            assert.equal(requests.length, 1);
    192179            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    203190                'status': 'OK'});
    204191
    205             waitForMeasurementSet().then(function () {
     192            return waitForMeasurementSet().then(() => {
    206193                assert.equal(requests.length, 3);
    207194                assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
    208195                assert.equal(requests[2].url, '../data/measurement-set-1-1-4000.json');
    209                 done();
    210             }).catch(function (error) {
    211                 done(error);
    212             });
    213         });
    214 
    215         it('should not request secondary clusters that are not requested', function (done) {
    216             var set = MeasurementSet.findSet(1, 1, 5000);
    217             set.fetchBetween(3200, 3700, function () {
    218                 assert.notReached();
    219             });
     196                assert.equal(callCount, 1); // 4000-4207
     197            });
     198        });
     199
     200        it('should not request secondary clusters that are not requested', () => {
     201            const set = MeasurementSet.findSet(1, 1, 5000);
     202            let callCountForWaitingCallback = 0;
     203            set.fetchBetween(3200, 3700, () => callCountForWaitingCallback++);
    220204            assert.equal(requests.length, 1);
    221205            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    232216                'status': 'OK'});
    233217
    234             var callCount = 0;
    235             waitForMeasurementSet().then(function () {
     218            let callCount = 0;
     219            return waitForMeasurementSet().then(() => {
    236220                assert.equal(requests.length, 2);
    237221                assert.equal(requests[1].url, '../data/measurement-set-1-1-4000.json');
    238                 set.fetchBetween(1207, 1293, function () { callCount++; });
    239                 return waitForMeasurementSet();
    240             }).then(function () {
     222                set.fetchBetween(1207, 1293, () => callCount++);
     223                return waitForMeasurementSet();
     224            }).then(() => {
     225                assert.equal(callCountForWaitingCallback, 0);
    241226                assert.equal(callCount, 0);
    242227                assert.equal(requests.length, 3);
    243228                assert.equal(requests[2].url, '../data/measurement-set-1-1-2000.json');
    244                 set.fetchBetween(1964, 3401, function () { callCount++; });
    245                 return waitForMeasurementSet();
    246             }).then(function () {
     229                set.fetchBetween(1964, 3401, () => callCount++);
     230                return waitForMeasurementSet();
     231            }).then(() => {
     232                assert.equal(callCountForWaitingCallback, 0);
    247233                assert.equal(callCount, 0);
    248234                assert.equal(requests.length, 4);
    249235                assert.equal(requests[3].url, '../data/measurement-set-1-1-3000.json');
    250                 done();
    251             }).catch(function (error) {
    252                 done(error);
    253             });
    254         });
    255 
    256         it('should not request a cluster before the very first cluster', function (done) {
    257             var set = MeasurementSet.findSet(1, 1, 5000);
    258             set.fetchBetween(0, 3000, function () {
    259                 assert.notReached();
    260             });
     236            });
     237        });
     238
     239        it('should not request a cluster before the very first cluster', () => {
     240            const set = MeasurementSet.findSet(1, 1, 5000);
     241            let callCount = 0;
     242            set.fetchBetween(0, 3000, () => callCount++);
    261243            assert.equal(requests.length, 1);
    262244            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    273255                'status': 'OK'});
    274256
    275             var callCount = 0;
    276             waitForMeasurementSet().then(function () {
     257            return waitForMeasurementSet().then(() => {
    277258                assert.equal(requests.length, 1);
    278                 done();
    279             }).catch(function (error) {
    280                 done(error);
    281             });
    282         });
    283 
    284         it('should invoke the callback when the fetching of the primray cluster fails', function (done) {
    285             var set = MeasurementSet.findSet(1, 1, 3000);
    286             var callCount = 0;
    287             set.fetchBetween(1000, 3000, function () {
    288                 callCount++;
    289             });
     259                assert.equal(callCount, 1);
     260            });
     261        });
     262
     263        it('should invoke the callback when the fetching of the primray cluster fails', () => {
     264            const set = MeasurementSet.findSet(1, 1, 3000);
     265            let callCount = 0;
     266            let rejected = false;
     267            set.fetchBetween(1000, 3000, () => callCount++).catch(() => rejected = true);
    290268            assert.equal(requests.length, 1);
    291269            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    293271            requests[0].reject(500);
    294272
    295             waitForMeasurementSet().then(function () {
     273            return waitForMeasurementSet().then(() => {
    296274                assert.equal(callCount, 1);
    297275                assert.equal(requests.length, 1);
    298                 done();
    299             }).catch(function (error) {
    300                 done(error);
    301             });
    302         });
    303 
    304         it('should request the uncached primary cluster when the cached cluster is outdated', function (done) {
    305             var set = MeasurementSet.findSet(1, 1, 3005);
    306             var callCount = 0;
    307             set.fetchBetween(1000, 2000, function () {
    308                 callCount++;
    309             });
     276                assert(rejected);
     277            });
     278        });
     279
     280        it('should request the uncached primary cluster when the cached cluster is outdated', () => {
     281            const set = MeasurementSet.findSet(1, 1, 3005);
     282            let callCount = 0;
     283            set.fetchBetween(1000, 2000, () => callCount++);
    310284            assert.equal(requests.length, 1);
    311285            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    322296                'status': 'OK'});
    323297
    324             Promise.resolve().then(function () {
     298            return waitForMeasurementSet().then(() => {
    325299                assert.equal(callCount, 0);
    326300                assert.equal(requests.length, 2);
    327301                assert.equal(requests[1].url, '../api/measurement-set?platform=1&metric=1');
    328                 done();
    329             }).catch(function (error) {
    330                 done(error);
    331             });
    332         });
    333 
    334         it('should request the uncached primary cluster when the cached cluster is 404', function (done) {
    335             var set = MeasurementSet.findSet(1, 1, 3005);
    336             var callCount = 0;
    337             set.fetchBetween(1000, 2000, function () {
    338                 callCount++;
    339             });
     302            });
     303        });
     304
     305        it('should request the uncached primary cluster when the cached cluster is 404', () => {
     306            const set = MeasurementSet.findSet(1, 1, 3005);
     307            let callCount = 0;
     308            set.fetchBetween(1000, 2000, () => callCount++);
    340309            assert.equal(requests.length, 1);
    341310            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    343312            requests[0].reject(404);
    344313
    345             waitForMeasurementSet().then(function () {
     314            return waitForMeasurementSet().then(() => {
    346315                assert.equal(callCount, 0);
    347316                assert.equal(requests.length, 2);
    348317                assert.equal(requests[1].url, '../api/measurement-set?platform=1&metric=1');
    349                 done();
    350             }).catch(function (error) {
    351                 done(error);
    352             });
    353         });
    354 
    355         it('should request the uncached primary cluster when noCache is true', function (done) {
    356             var set = MeasurementSet.findSet(1, 1, 3000);
    357             var callCount = 0;
    358             set.fetchBetween(1000, 3000, function () {
    359                 callCount++;
    360             });
     318            });
     319        });
     320
     321        it('should request the uncached primary cluster when noCache is true', () => {
     322            const set = MeasurementSet.findSet(1, 1, 3000);
     323            let callCount = 0;
     324            set.fetchBetween(1000, 3000, () => callCount++);
    361325            assert.equal(requests.length, 1);
    362326            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    373337                'status': 'OK'});
    374338
    375             var noCacheFetchCount = 0;
    376             waitForMeasurementSet().then(function () {
     339            let noCacheFetchCount = 0;
     340            return waitForMeasurementSet().then(() => {
    377341                assert.equal(callCount, 1);
    378342                assert.equal(noCacheFetchCount, 0);
     
    392356                    'status': 'OK'});
    393357
    394                 set.fetchBetween(1000, 3000, function () {
    395                     noCacheFetchCount++;
    396                 }, true /* noCache */);
    397 
    398                 return waitForMeasurementSet();
    399             }).then(function () {
     358                set.fetchBetween(1000, 3000, () => noCacheFetchCount++, true /* noCache */);
     359
     360                return waitForMeasurementSet();
     361            }).then(() => {
    400362                assert.equal(callCount, 2);
    401363                assert.equal(noCacheFetchCount, 0);
     
    416378
    417379                return waitForMeasurementSet();
    418             }).then(function () {
     380            }).then(() => {
    419381                assert.equal(callCount, 2);
    420382                assert.equal(noCacheFetchCount, 1);
     
    435397
    436398                return waitForMeasurementSet();
    437             }).then(function () {
     399            }).then(() => {
    438400                assert.equal(callCount, 3);
    439401                assert.equal(noCacheFetchCount, 2);
    440402                assert.equal(set._sortedClusters.length, 2);
    441403                assert.equal(requests.length, 4);
    442 
    443                 done();
    444             }).catch(function (error) {
    445                 done(error);
    446             });
    447         });
    448 
    449         it('should not request the primary cluster twice when multiple clients request it but should invoke all callbacks', function (done) {
    450             var set = MeasurementSet.findSet(1, 1, 3000);
    451             var callCount = 0;
    452             set.fetchBetween(2000, 3000, function () {
    453                 callCount++;
    454             });
    455             assert.equal(requests.length, 1);
    456             assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
    457 
    458             var alternativeCallCount = 0;
    459             set.fetchBetween(2000, 3000, function () {
    460                 alternativeCallCount++;
    461             });
     404            });
     405        });
     406
     407        it('should not request the primary cluster twice when multiple clients request it but should invoke all callbacks', () => {
     408            const set = MeasurementSet.findSet(1, 1, 3000);
     409            let callCount = 0;
     410            set.fetchBetween(2000, 3000, () => callCount++);
     411            assert.equal(requests.length, 1);
     412            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     413
     414            let alternativeCallCount = 0;
     415            set.fetchBetween(2000, 3000, () => alternativeCallCount++);
    462416
    463417            requests[0].resolve({
     
    472426                'status': 'OK'});
    473427
    474             waitForMeasurementSet().then(function () {
     428            return waitForMeasurementSet().then(() => {
    475429                assert.equal(callCount, 1);
    476430                assert.equal(alternativeCallCount, 1);
    477431                assert.equal(requests.length, 1);
    478                 done();
    479             }).catch(function (error) {
    480                 done(error);
    481             });
    482         });
    483 
    484         it('should invoke callback for each secondary clusters that are fetched or rejected', function (done) {
    485             var set = MeasurementSet.findSet(1, 1, 5000);
    486             var callCountFor4000 = 0;
    487             set.fetchBetween(3200, 3700, function () { callCountFor4000++; });
     432            });
     433        });
     434
     435        it('should invoke callback for each secondary clusters that are fetched or rejected', () => {
     436            const set = MeasurementSet.findSet(1, 1, 5000);
     437            let callCountFor4000 = 0;
     438            set.fetchBetween(3200, 3700, () => callCountFor4000++);
    488439            assert.equal(requests.length, 1);
    489440            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    500451                'status': 'OK'});
    501452
    502             var callCountFor4000To5000 = 0;
    503             var callCountFor2000 = 0;
    504             var callCountFor2000To4000 = 0;
    505             waitForMeasurementSet().then(function () {
     453            let callCountFor4000To5000 = 0;
     454            let callCountFor2000 = 0;
     455            let callCountFor2000To4000 = 0;
     456            return waitForMeasurementSet().then(() => {
    506457                assert.equal(callCountFor4000, 0);
    507458                assert.equal(requests.length, 2);
    508459                assert.equal(requests[1].url, '../data/measurement-set-1-1-4000.json');
    509460
    510                 set.fetchBetween(3708, 4800, function () { callCountFor4000To5000++; });
    511                 return waitForMeasurementSet();
    512             }).then(function () {
     461                set.fetchBetween(3708, 4800, () => callCountFor4000To5000++);
     462                return waitForMeasurementSet();
     463            }).then(() => {
    513464                assert.equal(callCountFor4000To5000, 1);
    514465                assert.equal(requests.length, 2);
    515466
    516                 set.fetchBetween(1207, 1293, function () { callCountFor2000++; });
    517                 return waitForMeasurementSet();
    518             }).then(function () {
     467                set.fetchBetween(1207, 1293, () => callCountFor2000++);
     468                return waitForMeasurementSet();
     469            }).then(() => {
    519470                assert.equal(callCountFor2000, 0);
    520471                assert.equal(requests.length, 3);
     
    529480                    'status': 'OK'});
    530481                return waitForMeasurementSet();
    531             }).then(function () {
     482            }).then(() => {
    532483                assert.equal(requests.length, 3);
    533484                assert.equal(callCountFor4000, 0);
     
    535486                assert.equal(callCountFor2000, 1);
    536487
    537                 set.fetchBetween(1964, 3401, function () { callCountFor2000To4000++; });
    538                 return waitForMeasurementSet();
    539             }).then(function () {
     488                set.fetchBetween(1964, 3401, () => { callCountFor2000To4000++; });
     489                return waitForMeasurementSet();
     490            }).then(() => {
    540491                assert.equal(callCountFor2000To4000, 1);
    541492                assert.equal(requests.length, 4);
     
    550501                    'status': 'OK'});
    551502                return waitForMeasurementSet();
    552             }).then(function () {
     503            }).then(() => {
    553504                assert.equal(callCountFor4000, 0);
    554505                assert.equal(callCountFor4000To5000, 1);
     
    565516                    'status': 'OK'});
    566517                return waitForMeasurementSet();
    567             }).then(function () {
     518            }).then(() => {
    568519                assert.equal(callCountFor4000, 1);
    569520                assert.equal(callCountFor4000To5000, 2);
     
    571522                assert.equal(callCountFor2000To4000, 3);
    572523                assert.equal(requests.length, 4);
    573 
    574                 done();
    575             }).catch(function (error) {
    576                 done(error);
    577             })
     524            });
    578525        });
    579526
    580527    });
    581528
    582     describe('hasFetchedRange', function () {
    583 
    584         it('should return false when no clusters had been fetched', function () {
     529    describe('hasFetchedRange', () => {
     530
     531        it('should return false when no clusters had been fetched', () => {
    585532            var set = MeasurementSet.findSet(1, 1, 3000);
    586533            assert(!set.hasFetchedRange(2000, 3000));
    587534        });
    588535
    589         it('should return true when a single cluster contains the entire range', function (done) {
    590             var set = MeasurementSet.findSet(1, 1, 3000);
    591             var promise = set.fetchBetween(2000, 3000);
     536        it('should return true when a single cluster contains the entire range', () => {
     537            const set = MeasurementSet.findSet(1, 1, 3000);
     538            const promise = set.fetchBetween(2000, 3000);
    592539            assert.equal(requests.length, 1);
    593540            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    604551                'status': 'OK'});
    605552
    606             promise.then(function () {
     553            return promise.then(() => {
    607554                assert(set.hasFetchedRange(2001, 2999));
    608555                assert(set.hasFetchedRange(2000, 3000));
    609                 done();
    610             }).catch(function (error) {
    611                 done(error);
    612             });
    613         });
    614 
    615         it('should return false when the range starts before the fetched cluster', function (done) {
    616             var set = MeasurementSet.findSet(1, 1, 3000);
    617             var promise = set.fetchBetween(2000, 3000);
     556            });
     557        });
     558
     559        it('should return false when the range starts before the fetched cluster', () => {
     560            const set = MeasurementSet.findSet(1, 1, 3000);
     561            const promise = set.fetchBetween(2000, 3000);
    618562            assert.equal(requests.length, 1);
    619563            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    630574                'status': 'OK'});
    631575
    632             promise.then(function () {
     576            return promise.then(() => {
    633577                assert(!set.hasFetchedRange(1500, 3000));
    634                 done();
    635             }).catch(function (error) {
    636                 done(error);
    637             });
    638         });
    639 
    640         it('should return false when the range ends after the fetched cluster', function (done) {
    641             var set = MeasurementSet.findSet(1, 1, 3000);
    642             var promise = set.fetchBetween(2000, 3000);
    643             assert.equal(requests.length, 1);
    644             assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
    645 
    646             requests[0].resolve({
    647                 'clusterStart': 1000,
    648                 'clusterSize': 1000,
    649                 'formatMap': [],
    650                 'configurations': {current: []},
    651                 'startTime': 2000,
    652                 'endTime': 3000,
    653                 'lastModified': 3000,
    654                 'clusterCount': 2,
    655                 'status': 'OK'});
    656 
    657             promise.then(function () {
     578            });
     579        });
     580
     581        it('should return false when the range ends after the fetched cluster', () => {
     582            const set = MeasurementSet.findSet(1, 1, 5000);
     583            const promise = set.fetchBetween(2000, 3000);
     584            assert.equal(requests.length, 1);
     585            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     586
     587            requests[0].resolve({
     588                'clusterStart': 1000,
     589                'clusterSize': 1000,
     590                'formatMap': [],
     591                'configurations': {current: []},
     592                'startTime': 4000,
     593                'endTime': 5000,
     594                'lastModified': 5000,
     595                'clusterCount': 3,
     596                'status': 'OK'});
     597
     598            return waitForMeasurementSet().then(() => {
     599                assert.equal(requests.length, 2);
     600                assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
     601                requests[1].resolve({
     602                    'clusterStart': 1000,
     603                    'clusterSize': 1000,
     604                    'formatMap': [],
     605                    'configurations': {current: []},
     606                    'startTime': 2000,
     607                    'endTime': 3000,
     608                    'lastModified': 5000,
     609                    'clusterCount': 3,
     610                    'status': 'OK'});
     611            }).then(() => {
    658612                assert(!set.hasFetchedRange(2500, 3500));
    659                 done();
    660             }).catch(function (error) {
    661                 done(error);
    662             });
    663         });
    664 
    665         it('should return true when the range is within two fetched clusters', function (done) {
    666             var set = MeasurementSet.findSet(1, 1, 5000);
    667             var promise = set.fetchBetween(2000, 3000);
     613            });
     614        });
     615
     616        it('should return true when the range is within two fetched clusters', () => {
     617            const set = MeasurementSet.findSet(1, 1, 5000);
     618            set.fetchBetween(2000, 3000);
    668619            assert.equal(requests.length, 1);
    669620            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    680631                'status': 'OK'});
    681632
    682             waitForMeasurementSet().then(function () {
     633            return waitForMeasurementSet().then(() => {
    683634                assert.equal(requests.length, 2);
    684635                assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
     
    693644                    'clusterCount': 2,
    694645                    'status': 'OK'});               
    695             }).then(function () {
     646            }).then(() => {
    696647                assert(set.hasFetchedRange(2500, 3500));
    697                 done();
    698             }).catch(function (error) {
    699                 done(error);
    700             });
    701         });
    702 
    703         it('should return false when there is a cluster missing in the range', function (done) {
    704             var set = MeasurementSet.findSet(1, 1, 5000);
    705             var promise = set.fetchBetween(2000, 5000);
     648            });
     649        });
     650
     651        it('should return false when there is a cluster missing in the range', () => {
     652            const set = MeasurementSet.findSet(1, 1, 5000);
     653            set.fetchBetween(2000, 5000);
    706654            assert.equal(requests.length, 1);
    707655            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    718666                'status': 'OK'});
    719667
    720             waitForMeasurementSet().then(function () {
     668            return waitForMeasurementSet().then(() => {
    721669                assert.equal(requests.length, 3);
    722670                assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
     
    732680                    'clusterCount': 2,
    733681                    'status': 'OK'});
    734             }).then(function () {
     682            }).then(() => {
    735683                assert(!set.hasFetchedRange(2500, 4500));
    736684                assert(set.hasFetchedRange(2100, 2300));
    737685                assert(set.hasFetchedRange(4000, 4800));
    738                 done();
    739             }).catch(function (error) {
    740                 done(error);
     686            });
     687        });
     688
     689        it('should return true even when the range extends beyond the primary cluster', () => {
     690            const set = MeasurementSet.findSet(1, 1, 3000);
     691            const promise = set.fetchBetween(2000, 3000);
     692            assert.equal(requests.length, 1);
     693            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     694
     695            requests[0].resolve({
     696                'clusterStart': 1000,
     697                'clusterSize': 1000,
     698                'formatMap': [],
     699                'configurations': {current: []},
     700                'startTime': 2000,
     701                'endTime': 3000,
     702                'lastModified': 3000,
     703                'clusterCount': 2,
     704                'status': 'OK'});
     705
     706            return promise.then(() => {
     707                assert(set.hasFetchedRange(2001, 5000));
    741708            });
    742709        });
     
    804771        let builder;
    805772        let webkit;
    806         beforeEach(function () {
     773        beforeEach(() => {
    807774            builder = new Builder(7, {name: 'EFL Linux 64-bit Release WK2 (Perf)', buildUrl: 'http://build.webkit.org/builders/$builderName/$buildNumber'});
    808775            webkit = new Repository(1, {name: 'WebKit', url: 'http://trac.webkit.org/changeset/$1'});
     
    983950    });
    984951
    985     describe('fetchSegmentation', function () {
     952    describe('fetchSegmentation', () => {
    986953
    987954        var simpleSegmentableValues = [
     
    1009976        }
    1010977
    1011         it('should be able to segment a single cluster', function (done) {
    1012             var set = MeasurementSet.findSet(1, 1, 5000);
    1013             var promise = set.fetchBetween(4000, 5000);
     978        it('should be able to segment a single cluster', () => {
     979            const set = MeasurementSet.findSet(1, 1, 5000);
     980            const promise = set.fetchBetween(4000, 5000);
    1014981            assert.equal(requests.length, 1);
    1015982            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    1028995            var timeSeries;
    1029996            assert.equal(set.fetchedTimeSeries('current', false, false).length(), 0);
    1030             waitForMeasurementSet().then(function () {
     997            return waitForMeasurementSet().then(() => {
    1031998                timeSeries = set.fetchedTimeSeries('current', false, false);
    1032999                assert.equal(timeSeries.length(), 45);
     
    10341001                assert.equal(timeSeries.lastPoint().time, 4880);
    10351002                return set.fetchSegmentation('segmentTimeSeriesByMaximizingSchwarzCriterion', [], 'current', false);
    1036             }).then(function (segmentation) {
     1003            }).then((segmentation) => {
    10371004                assert.equal(segmentation.length, 4);
    10381005
     
    10461013                assert.equal(segmentation[2].value, segmentation[3].value);
    10471014                assert.equal(segmentation[3].time, 4880);
    1048                 done();
    1049             }).catch(done);
    1050         });
    1051 
    1052         it('should be able to segment two clusters', function (done) {
    1053             var set = MeasurementSet.findSet(1, 1, 5000);
    1054             var promise = set.fetchBetween(3000, 5000);
     1015            });
     1016        });
     1017
     1018        it('should be able to segment two clusters', () => {
     1019            const set = MeasurementSet.findSet(1, 1, 5000);
     1020            const promise = set.fetchBetween(3000, 5000);
    10551021            assert.equal(requests.length, 1);
    10561022            assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
     
    10671033                'status': 'OK'});
    10681034
    1069             waitForMeasurementSet().then(function () {
     1035            return waitForMeasurementSet().then(() => {
    10701036                assert.equal(requests.length, 2);
    10711037                assert.equal(requests[1].url, '../data/measurement-set-1-1-4000.json');
    10721038                return set.fetchSegmentation('segmentTimeSeriesByMaximizingSchwarzCriterion', [], 'current', false);
    1073             }).then(function (segmentation) {
    1074                 var timeSeries = set.fetchedTimeSeries('current', false, false);
     1039            }).then((segmentation) => {
     1040                const timeSeries = set.fetchedTimeSeries('current', false, false);
    10751041                assert.equal(timeSeries.length(), 15);
    10761042                assert.equal(timeSeries.firstPoint().time, 4000);
     
    10991065                    'status': 'OK'});
    11001066                return waitForMeasurementSet();
    1101             }).then(function () {
     1067            }).then(() => {
    11021068                return set.fetchSegmentation('segmentTimeSeriesByMaximizingSchwarzCriterion', [], 'current', false);
    1103             }).then(function (segmentation) {
     1069            }).then((segmentation) => {
    11041070                var timeSeries = set.fetchedTimeSeries('current', false, false);
    11051071                assert.equal(timeSeries.length(), 45);
     
    11171083                assert.equal(segmentation[2].value, segmentation[3].value);
    11181084                assert.equal(segmentation[3].time, timeSeries.lastPoint().time);
    1119                 done();
    1120             }).catch(done);
     1085            });
    11211086        });
    11221087
  • trunk/Websites/perf.webkit.org/unit-tests/resources/mock-remote-api.js

    r202001 r212520  
    1 var assert = require('assert');
    2 
    3 if (!assert.notReached)
    4     assert.notReached = function () { assert(false, 'This code path should not be reached'); }
    5 
    61var MockRemoteAPI = {
    72    url: function (path)
Note: See TracChangeset for help on using the changeset viewer.