tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

compute_pressure_timestamp_faster_collector.https.window.js (1486B)


      1 // META: timeout=long
      2 // META: variant=?globalScope=window
      3 // META: variant=?globalScope=dedicated_worker
      4 // META: script=/resources/testdriver.js
      5 // META: script=/resources/testdriver-vendor.js
      6 // META: script=/common/utils.js
      7 // META: script=/common/dispatcher/dispatcher.js
      8 // META: script=./resources/common.js
      9 // META: script=./resources/sync-pressure-observer.js
     10 
     11 'use strict';
     12 
     13 pressure_test(async (t) => {
     14  await create_virtual_pressure_source('cpu');
     15  t.add_cleanup(async () => {
     16    await remove_virtual_pressure_source('cpu');
     17  });
     18 
     19  const sampleInterval = 250;
     20  const readings = ['nominal', 'fair', 'serious', 'critical'];
     21 
     22  const syncObserver = new SyncPressureObserver(t);
     23  await syncObserver.observer().observe('cpu', {sampleInterval});
     24 
     25  for (let i = 0; i < readings.length; ++i) {
     26    await update_virtual_pressure_source('cpu', readings[i]);
     27    await syncObserver.waitForUpdate();
     28  }
     29 
     30  const pressureChanges = syncObserver.changes();
     31  assert_equals(pressureChanges.length, readings.length);
     32 
     33  assert_greater_than_equal(
     34      pressureChanges[1][0].time - pressureChanges[0][0].time, sampleInterval);
     35  assert_greater_than_equal(
     36      pressureChanges[2][0].time - pressureChanges[1][0].time, sampleInterval);
     37  assert_greater_than_equal(
     38      pressureChanges[3][0].time - pressureChanges[2][0].time, sampleInterval);
     39 }, 'Faster collector: Timestamp difference between two changes should be higher or equal to the observer sample rate');
     40 
     41 mark_as_done();