How to use aborted method in wpt

Best JavaScript code snippet using wpt

test_TelemetrySession_abortedSessionQueued.js

Source:test_TelemetrySession_abortedSessionQueued.js Github

copy

Full Screen

1/* Any copyright is dedicated to the Public Domain.2 http://creativecommons.org/publicdomain/zero/1.0/3*/4/**5 * This file only contains the |test_abortedSessionQueued| test. This needs6 * to be in a separate, stand-alone file since we're initializing Telemetry7 * twice, in a non-standard way to simulate incorrect shutdowns. Doing this8 * in other files might interfere with the other tests.9 */10ChromeUtils.import("resource://services-common/utils.js", this);11ChromeUtils.import("resource://gre/modules/TelemetryStorage.jsm", this);12ChromeUtils.import("resource://gre/modules/Services.jsm", this);13const DATAREPORTING_DIR = "datareporting";14const ABORTED_PING_FILE_NAME = "aborted-session-ping";15const ABORTED_SESSION_UPDATE_INTERVAL_MS = 5 * 60 * 1000;16const PING_TYPE_MAIN = "main";17const REASON_ABORTED_SESSION = "aborted-session";18const TEST_PING_TYPE = "test-ping-type";19XPCOMUtils.defineLazyGetter(this, "DATAREPORTING_PATH", function() {20 return OS.Path.join(OS.Constants.Path.profileDir, DATAREPORTING_DIR);21});22function sendPing() {23 if (PingServer.started) {24 TelemetrySend.setServer("http://localhost:" + PingServer.port);25 } else {26 TelemetrySend.setServer("http://doesnotexist");27 }28 let options = {29 addClientId: true,30 addEnvironment: true,31 };32 return TelemetryController.submitExternalPing(TEST_PING_TYPE, {}, options);33}34add_task(async function test_setup() {35 do_get_profile();36 PingServer.start();37 Services.prefs.setCharPref(38 TelemetryUtils.Preferences.Server,39 "http://localhost:" + PingServer.port40 );41});42add_task(async function test_abortedSessionQueued() {43 const ABORTED_FILE = OS.Path.join(DATAREPORTING_PATH, ABORTED_PING_FILE_NAME);44 // Make sure the aborted sessions directory does not exist to test its creation.45 await OS.File.removeDir(DATAREPORTING_PATH, { ignoreAbsent: true });46 let schedulerTickCallback = null;47 let now = new Date(2040, 1, 1, 0, 0, 0);48 fakeNow(now);49 // Fake scheduler functions to control aborted-session flow in tests.50 fakeSchedulerTimer(51 callback => (schedulerTickCallback = callback),52 () => {}53 );54 await TelemetryController.testReset();55 Assert.ok(56 await OS.File.exists(DATAREPORTING_PATH),57 "Telemetry must create the aborted session directory when starting."58 );59 // Fake now again so that the scheduled aborted-session save takes place.60 now = futureDate(now, ABORTED_SESSION_UPDATE_INTERVAL_MS);61 fakeNow(now);62 // The first aborted session checkpoint must take place right after the initialisation.63 Assert.ok(!!schedulerTickCallback);64 // Execute one scheduler tick.65 await schedulerTickCallback();66 // Check that the aborted session is due at the correct time.67 Assert.ok(68 await OS.File.exists(ABORTED_FILE),69 "There must be an aborted session ping."70 );71 await TelemetryStorage.testClearPendingPings();72 PingServer.clearRequests();73 await TelemetryController.testReset();74 Assert.ok(75 !(await OS.File.exists(ABORTED_FILE)),76 "The aborted session ping must be removed from the aborted session ping directory."77 );78 // Restarting Telemetry again to trigger sending pings in TelemetrySend.79 await TelemetryController.testReset();80 // We should have received an aborted-session ping.81 const receivedPing = await PingServer.promiseNextPing();82 Assert.equal(83 receivedPing.type,84 PING_TYPE_MAIN,85 "Should have the correct type"86 );87 Assert.equal(88 receivedPing.payload.info.reason,89 REASON_ABORTED_SESSION,90 "Ping should have the correct reason"91 );92 await TelemetryController.testShutdown();93});94/*95 * An aborted-session ping might have been written when Telemetry upload was disabled and96 * the profile had a canary client ID.97 * These pings should not be sent out at a later point when Telemetry is enabled again.98 */99add_task(async function test_abortedSession_canary_clientid() {100 const ABORTED_FILE = OS.Path.join(DATAREPORTING_PATH, ABORTED_PING_FILE_NAME);101 // Make sure the aborted sessions directory does not exist to test its creation.102 await OS.File.removeDir(DATAREPORTING_PATH, { ignoreAbsent: true });103 let schedulerTickCallback = null;104 let now = new Date(2040, 1, 1, 0, 0, 0);105 fakeNow(now);106 // Fake scheduler functions to control aborted-session flow in tests.107 fakeSchedulerTimer(108 callback => (schedulerTickCallback = callback),109 () => {}110 );111 await TelemetryController.testReset();112 Assert.ok(113 await OS.File.exists(DATAREPORTING_PATH),114 "Telemetry must create the aborted session directory when starting."115 );116 // Fake now again so that the scheduled aborted-session save takes place.117 now = futureDate(now, ABORTED_SESSION_UPDATE_INTERVAL_MS);118 fakeNow(now);119 // The first aborted session checkpoint must take place right after the initialisation.120 Assert.ok(!!schedulerTickCallback);121 // Execute one scheduler tick.122 await schedulerTickCallback();123 // Check that the aborted session is due at the correct time.124 Assert.ok(125 await OS.File.exists(ABORTED_FILE),126 "There must be an aborted session ping."127 );128 // Set clientID in aborted-session ping to canary value129 let abortedPing = await CommonUtils.readJSON(ABORTED_FILE);130 abortedPing.clientId = TelemetryUtils.knownClientID;131 OS.File.writeAtomic(ABORTED_FILE, JSON.stringify(abortedPing), {132 encoding: "utf-8",133 });134 await TelemetryStorage.testClearPendingPings();135 PingServer.clearRequests();136 await TelemetryController.testReset();137 Assert.ok(138 !(await OS.File.exists(ABORTED_FILE)),139 "The aborted session ping must be removed from the aborted session ping directory."140 );141 // Restarting Telemetry again to trigger sending pings in TelemetrySend.142 await TelemetryController.testReset();143 // Trigger a test ping, so we can verify the server received something.144 sendPing();145 // We should have received an aborted-session ping.146 const receivedPing = await PingServer.promiseNextPing();147 Assert.equal(148 receivedPing.type,149 TEST_PING_TYPE,150 "Should have received test ping"151 );152 await TelemetryController.testShutdown();153});154add_task(async function stopServer() {155 await PingServer.stop();...

Full Screen

Full Screen

get_request_aborted_signal.test.ts

Source:get_request_aborted_signal.test.ts Github

copy

Full Screen

1/*2 * Licensed to Elasticsearch B.V. under one or more contributor3 * license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright5 * ownership. Elasticsearch B.V. licenses this file to you under6 * the Apache License, Version 2.0 (the "License"); you may7 * not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19import { Subject } from 'rxjs';20import { getRequestAbortedSignal } from './get_request_aborted_signal';21describe('abortableRequestHandler', () => {22 jest.useFakeTimers();23 it('should call abort if disconnected', () => {24 const abortedSubject = new Subject<void>();25 const aborted$ = abortedSubject.asObservable();26 const onAborted = jest.fn();27 const signal = getRequestAbortedSignal(aborted$);28 signal.addEventListener('abort', onAborted);29 // Shouldn't be aborted or call onAborted prior to disconnecting30 expect(signal.aborted).toBe(false);31 expect(onAborted).not.toBeCalled();32 abortedSubject.next();33 jest.runAllTimers();34 // Should be aborted and call onAborted after disconnecting35 expect(signal.aborted).toBe(true);36 expect(onAborted).toBeCalled();37 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.log(err);5 console.log('Test ID: %s', data.data.testId);6 var testId = data.data.testId;7 wpt.getTestResults(testId, function(err, data) {8 if (err) return console.log(err);9 console.log('Test Results: %j', data);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./lib/wpt');2var wpt = new wpt();3var url = process.argv[2];4var location = process.argv[3];5var key = process.argv[4];6var runs = process.argv[5];7var timeout = process.argv[6];8var options = {9};10wpt.runTest(options, function(err, data) {11 if (err) return console.log(err);12 console.log(data);13 setTimeout(function() {14 wpt.getTestStatus(data.data.testId, function(err, data) {15 if (err) return console.log(err);16 console.log(data);17 wpt.abortTest(data.data.testId, function(err, data) {18 if (err) return console.log(err);19 console.log(data);20 });21 });22 }, 5000);23});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webpagetest = require('webpagetest');2var wpt = new webpagetest('www.webpagetest.org', 'A.1f5e5a5d5a5b5c5d5e5f5g5h5i5j5k5l5m5n5o5p5q5r5s5t5u5v5w5x5y5z5', { secure: true });3var options = {4 videoParams: {5 },6 timelineParams: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3var testId = '170424_3T_1e9f7d0e8c2e1e9f7d0e8c2e1e9f7d0e';4var abort = test.abortTest(testId);5abort.on('data', function(data) {6 console.log(data);7});8abort.on('error', function(err) {9 console.log(err);10});11var wpt = require('webpagetest');12var test = wpt('www.webpagetest.org');13var testId = '170424_3T_1e9f7d0e8c2e1e9f7d0e8c2e1e9f7d0e';14var status = test.testStatus(testId);15status.on('data', function(data) {16 console.log(data);17});18status.on('error', function(err) {19 console.log(err);20});21var wpt = require('webpagetest');22var test = wpt('www.webpagetest.org');23var testId = '170424_3T_1e9f7d0e8c2e1e9f7d0e8c2e1e9f7d0e';24var results = test.getTestResults(testId);25results.on('data', function(data) {26 console.log(data);27});28results.on('error', function(err) {29 console.log(err);30});31var wpt = require('webpagetest');32var test = wpt('www.webpagetest.org');33var testId = '170424_3T_1e9f7d0e8c2e1e9f7d0e8c2e1e9f7d0e';34var result = test.getTestResult(testId, 'speedIndex');35result.on('data', function(data) {36 console.log(data);37});38result.on('error',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = wpt(options);5test.runTest(url, function(err, data) {6 if (err) return console.error(err);7 console.log('Test started: %s', data.data.testId);8 test.getTestResults(data.data.testId, function(err, data) {9 if (err) return console.error(err);10 console.log('Test completed: %s', data.data.testId);11 console.log('View the test at: %s', data.data.summary);12 console.log('View the video at: %s', data.data.video);13 test.abortTest(data.data.testId, function(err, data) {14 if (err) return console.error(err);15 console.log('Test aborted: %s', data.data.testId);16 test.getTestResults(data.data.testId, function(err, data) {17 if (err) return console.error(err);18 console.log('Test completed: %s', data.data.testId);19 console.log('View the test at: %s', data.data.summary);20 console.log('View the video at: %s', data.data.video);21 });22 });23 });24});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful