How to use res2_clients method in wpt

Best JavaScript code snippet using wpt

query.tentative.https.any.js

Source:query.tentative.https.any.js Github

copy

Full Screen

1// META: title=Web Locks API: navigator.locks.query method2// META: script=resources/helpers.js3'use strict';4// Returns an array of the modes for the locks with matching name.5function modes(list, name) {6 return list.filter(item => item.name === name).map(item => item.mode);7}8// Returns an array of the clientIds for the locks with matching name.9function clients(list, name) {10 return list.filter(item => item.name === name).map(item => item.clientId);11}12promise_test(async t => {13 const res = uniqueName(t);14 await navigator.locks.request(res, async lock1 => {15 // Attempt to request this again - should be blocked.16 let lock2_acquired = false;17 navigator.locks.request(res, lock2 => { lock2_acquired = true; });18 // Verify that it was blocked.19 await navigator.locks.request(res, {ifAvailable: true}, async lock3 => {20 assert_false(lock2_acquired, 'second request should be blocked');21 assert_equals(lock3, null, 'third request should have failed');22 const state = await navigator.locks.query();23 assert_own_property(state, 'pending', 'State has `pending` property');24 assert_true(Array.isArray(state.pending),25 'State `pending` property is an array');26 const pending_info = state.pending[0];27 assert_own_property(pending_info, 'name',28 'Pending info dictionary has `name` property');29 assert_own_property(pending_info, 'mode',30 'Pending info dictionary has `mode` property');31 assert_own_property(pending_info, 'clientId',32 'Pending info dictionary has `clientId` property');33 assert_own_property(state, 'held', 'State has `held` property');34 assert_true(Array.isArray(state.held),35 'State `held` property is an array');36 const held_info = state.held[0];37 assert_own_property(held_info, 'name',38 'Held info dictionary has `name` property');39 assert_own_property(held_info, 'mode',40 'Held info dictionary has `mode` property');41 assert_own_property(held_info, 'clientId',42 'Held info dictionary has `clientId` property');43 });44 });45}, 'query() returns dictionaries with expected properties');46promise_test(async t => {47 const res = uniqueName(t);48 await navigator.locks.request(res, async lock1 => {49 const state = await navigator.locks.query();50 assert_array_equals(modes(state.held, res), ['exclusive'],51 'Held lock should appear once');52 });53 await navigator.locks.request(res, {mode: 'shared'}, async lock1 => {54 const state = await navigator.locks.query();55 assert_array_equals(modes(state.held, res), ['shared'],56 'Held lock should appear once');57 });58}, 'query() reports individual held locks');59promise_test(async t => {60 const res1 = uniqueName(t);61 const res2 = uniqueName(t);62 await navigator.locks.request(res1, async lock1 => {63 await navigator.locks.request(res2, {mode: 'shared'}, async lock2 => {64 const state = await navigator.locks.query();65 assert_array_equals(modes(state.held, res1), ['exclusive'],66 'Held lock should appear once');67 assert_array_equals(modes(state.held, res2), ['shared'],68 'Held lock should appear once');69 });70 });71}, 'query() reports multiple held locks');72promise_test(async t => {73 const res = uniqueName(t);74 await navigator.locks.request(res, async lock1 => {75 // Attempt to request this again - should be blocked.76 let lock2_acquired = false;77 navigator.locks.request(res, lock2 => { lock2_acquired = true; });78 // Verify that it was blocked.79 await navigator.locks.request(res, {ifAvailable: true}, async lock3 => {80 assert_false(lock2_acquired, 'second request should be blocked');81 assert_equals(lock3, null, 'third request should have failed');82 const state = await navigator.locks.query();83 assert_array_equals(modes(state.pending, res), ['exclusive'],84 'Pending lock should appear once');85 assert_array_equals(modes(state.held, res), ['exclusive'],86 'Held lock should appear once');87 });88 });89}, 'query() reports pending and held locks');90promise_test(async t => {91 const res = uniqueName(t);92 await navigator.locks.request(res, {mode: 'shared'}, async lock1 => {93 await navigator.locks.request(res, {mode: 'shared'}, async lock2 => {94 const state = await navigator.locks.query();95 assert_array_equals(modes(state.held, res), ['shared', 'shared'],96 'Held lock should appear twice');97 });98 });99}, 'query() reports held shared locks with appropriate count');100promise_test(async t => {101 const res = uniqueName(t);102 await navigator.locks.request(res, async lock1 => {103 let lock2_acquired = false, lock3_acquired = false;104 navigator.locks.request(res, {mode: 'shared'},105 lock2 => { lock2_acquired = true; });106 navigator.locks.request(res, {mode: 'shared'},107 lock3 => { lock3_acquired = true; });108 await navigator.locks.request(res, {ifAvailable: true}, async lock4 => {109 assert_equals(lock4, null, 'lock should not be available');110 assert_false(lock2_acquired, 'second attempt should be blocked');111 assert_false(lock3_acquired, 'third attempt should be blocked');112 const state = await navigator.locks.query();113 assert_array_equals(modes(state.held, res), ['exclusive'],114 'Held lock should appear once');115 assert_array_equals(modes(state.pending, res), ['shared', 'shared'],116 'Pending lock should appear twice');117 });118 });119}, 'query() reports pending shared locks with appropriate count');120promise_test(async t => {121 const res1 = uniqueName(t);122 const res2 = uniqueName(t);123 await navigator.locks.request(res1, async lock1 => {124 await navigator.locks.request(res2, async lock2 => {125 const state = await navigator.locks.query();126 const res1_clients = clients(state.held, res1);127 const res2_clients = clients(state.held, res2);128 assert_equals(res1_clients.length, 1, 'Each lock should have one holder');129 assert_equals(res2_clients.length, 1, 'Each lock should have one holder');130 assert_array_equals(res1_clients, res2_clients,131 'Both locks should have same clientId');132 });133 });134}, 'query() reports the same clientId for held locks from the same context');135promise_test(async t => {136 const res = uniqueName(t);137 const worker = new Worker('resources/worker.js');138 t.add_cleanup(() => { worker.terminate(); });139 await postToWorkerAndWait(140 worker, {op: 'request', name: res, mode: 'shared'});141 await navigator.locks.request(res, {mode: 'shared'}, async lock => {142 const state = await navigator.locks.query();143 const res_clients = clients(state.held, res);144 assert_equals(res_clients.length, 2, 'Clients should have same resource');145 assert_not_equals(res_clients[0], res_clients[1],146 'Clients should have different ids');147 });148}, 'query() reports different ids for held locks from different contexts');149promise_test(async t => {150 const res1 = uniqueName(t);151 const res2 = uniqueName(t);152 const worker = new Worker('resources/worker.js');153 t.add_cleanup(() => { worker.terminate(); });154 // Acquire 1 in the worker.155 await postToWorkerAndWait(worker, {op: 'request', name: res1})156 // Acquire 2 here.157 await new Promise(resolve => {158 navigator.locks.request(res2, lock => {159 resolve();160 return new Promise(() => {}); // Never released.161 });162 });163 // Request 2 in the worker.164 postToWorkerAndWait(worker, {op: 'request', name: res2});165 assert_true((await postToWorkerAndWait(worker, {166 op: 'request', name: res2, ifAvailable: true167 })).failed, 'Lock request should have failed');168 // Request 1 here.169 navigator.locks.request(170 res1, t.unreached_func('Lock should not be acquired'));171 // Verify that we're seeing a deadlock.172 const state = await navigator.locks.query();173 const res1_held_clients = clients(state.held, res1);174 const res2_held_clients = clients(state.held, res2);175 const res1_pending_clients = clients(state.pending, res1);176 const res2_pending_clients = clients(state.pending, res2);177 assert_equals(res1_held_clients.length, 1);178 assert_equals(res2_held_clients.length, 1);179 assert_equals(res1_pending_clients.length, 1);180 assert_equals(res2_pending_clients.length, 1);181 assert_equals(res1_held_clients[0], res2_pending_clients[0]);182 assert_equals(res2_held_clients[0], res1_pending_clients[0]);...

Full Screen

Full Screen

query.test.ts

Source:query.test.ts Github

copy

Full Screen

1import {2 beforeEachHandle,3 createWebLocksInstance,4 generateRandomId,5 LockInfo,6} from "./helpers";7// Returns an array of the modes for the locks with matching name.8function modes(list: LockInfo[], name: string) {9 return list.filter((item) => item.name === name).map((item) => item.mode);10}11// Returns an array of the clientIds for the locks with matching name.12function clients(list: LockInfo[], name: string) {13 return list.filter((item) => item.name === name).map((item) => item.clientId);14}15describe("Web Locks API: navigator.locks.query method", () => {16 beforeEachHandle();17 test("query() returns dictionaries with expected properties", async () => {18 const webLocks = createWebLocksInstance();19 const sourceName = generateRandomId();20 await webLocks.request(sourceName, async (lock1) => {21 // Attempt to request this again - should be blocked.22 let lock2_acquired = false;23 webLocks.request(sourceName, (lock2) => {24 lock2_acquired = true;25 });26 // Verify that it was blocked.27 await webLocks.request(28 sourceName,29 { ifAvailable: true },30 async (lock3) => {31 // second request should be blocked32 expect(lock2_acquired).toBeFalsy();33 // third request should have failed34 expect(lock3).toEqual(null);35 const state = await webLocks.query();36 // State has `pending` property37 expect(state).toHaveProperty("pending");38 // State `pending` property is an array39 expect(Array.isArray(state.pending)).toBeTruthy();40 const pending_info = state.pending[0];41 // Pending info dictionary has `name` property42 expect(pending_info).toHaveProperty("name");43 // Pending info dictionary has `mode` property44 expect(pending_info).toHaveProperty("mode");45 // Pending info dictionary has `clientId` property46 expect(pending_info).toHaveProperty("clientId");47 // State has `held` property48 expect(state).toHaveProperty("held");49 // State `held` property is an array50 expect(Array.isArray(state.held)).toBeTruthy();51 const held_info = state.held[0];52 // Held info dictionary has `name` property53 expect(held_info).toHaveProperty("name");54 // Held info dictionary has `mode` property55 expect(held_info).toHaveProperty("mode");56 // Held info dictionary has `clientId` property57 expect(held_info).toHaveProperty("clientId");58 }59 );60 });61 });62 test("query() reports individual held locks", async () => {63 const webLocks = createWebLocksInstance();64 const sourceName = generateRandomId();65 await webLocks.request(sourceName, async (lock1) => {66 const state = await webLocks.query();67 // Held lock should appear once68 expect(modes(state.held, sourceName)).toEqual(["exclusive"]);69 });70 await webLocks.request(sourceName, { mode: "shared" }, async (lock1) => {71 const state = await webLocks.query();72 // Held lock should appear once73 expect(modes(state.held, sourceName)).toEqual(["shared"]);74 });75 });76 test("query() reports multiple held locks", async () => {77 const webLocks = createWebLocksInstance();78 const sourceName1 = generateRandomId();79 const sourceName2 = generateRandomId();80 await webLocks.request(sourceName1, async (lock1) => {81 await webLocks.request(sourceName2, { mode: "shared" }, async (lock2) => {82 const state = await webLocks.query();83 // SHeld lock should appear once84 expect(modes(state.held, sourceName1)).toEqual(["exclusive"]);85 // Held lock should appear once86 expect(modes(state.held, sourceName2)).toEqual(["shared"]);87 });88 });89 });90 test("query() reports pending and held locks", async () => {91 const webLocks = createWebLocksInstance();92 const sourceName = generateRandomId();93 await webLocks.request(sourceName, async (lock1) => {94 // Attempt to request this again - should be blocked.95 let lock2_acquired = false;96 webLocks.request(sourceName, (lock2) => {97 lock2_acquired = true;98 });99 // Verify that it was blocked.100 await webLocks.request(101 sourceName,102 { ifAvailable: true },103 async (lock3) => {104 // second request should be blocked105 expect(lock2_acquired).toBeFalsy();106 // third request should have failed107 expect(lock3).toEqual(null);108 const state = await webLocks.query();109 // Pending lock should appear once110 expect(modes(state.pending, sourceName)).toEqual(["exclusive"]);111 // Held lock should appear once112 expect(modes(state.held, sourceName)).toEqual(["exclusive"]);113 }114 );115 });116 });117 test("query() reports held shared locks with appropriate count", async () => {118 const webLocks = createWebLocksInstance();119 const sourceName = generateRandomId();120 await webLocks.request(sourceName, { mode: "shared" }, async (lock1) => {121 await webLocks.request(sourceName, { mode: "shared" }, async (lock2) => {122 const state = await webLocks.query();123 // Held lock should appear twice124 expect(modes(state.held, sourceName)).toEqual(["shared", "shared"]);125 });126 });127 });128 test("query() reports pending shared locks with appropriate count", async () => {129 const webLocks = createWebLocksInstance();130 const sourceName = generateRandomId();131 await webLocks.request(sourceName, async (lock1) => {132 let lock2_acquired = false,133 lock3_acquired = false;134 webLocks.request(sourceName, { mode: "shared" }, (lock2) => {135 lock2_acquired = true;136 });137 webLocks.request(sourceName, { mode: "shared" }, (lock3) => {138 lock3_acquired = true;139 });140 await webLocks.request(141 sourceName,142 { ifAvailable: true },143 async (lock4) => {144 // lock should not be available145 expect(lock4).toEqual(null);146 // second attempt should be blocked147 expect(lock2_acquired).toBeFalsy();148 // third attempt should be blocked149 expect(lock3_acquired).toBeFalsy();150 const state = await webLocks.query();151 // Held lock should appear once152 expect(modes(state.held, sourceName)).toEqual(["exclusive"]);153 // Pending lock should appear twice154 expect(modes(state.pending, sourceName)).toEqual([155 "shared",156 "shared",157 ]);158 }159 );160 });161 });162 test("query() reports the same clientId for held locks from the same context", async () => {163 const webLocks = createWebLocksInstance();164 const sourceName1 = generateRandomId();165 const sourceName2 = generateRandomId();166 await webLocks.request(sourceName1, async (lock1) => {167 await webLocks.request(sourceName2, async (lock2) => {168 const state = await webLocks.query();169 const res1_clients = clients(state.held, sourceName1);170 const res2_clients = clients(state.held, sourceName2);171 // Each lock should have one holder172 expect(res1_clients.length).toEqual(1);173 // Each lock should have one holder174 expect(res2_clients.length).toEqual(1);175 // Both locks should have same clientId176 expect(res1_clients).toEqual(res2_clients);177 });178 });179 });180 // TODO: other method to replace181 test("query() reports different ids for held locks from different contexts", async () => {});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = wpt('www.webpagetest.org');3api.runTest(url, { location: 'Dulles:Chrome', connectivity: 'Cable', firstViewOnly: true, video: true, label: 'Test' }, function(err, data) {4 if (err) return console.error(err);5 var testId = data.data.testId;6 api.getTestResults(testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});11api.getLocations(function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15api.getTesters(function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19api.getTesters("Dulles", function(err, data) {20 if (err) return console.error(err);21 console.log(data);22});23api.getTesters("Dulles", "Chrome", function(err, data) {24 if (err) return console.error(err);25 console.log(data);26});27api.getTesters("Dulles", "Chrome", "Cable", function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31api.getTesters("Dulles", "Chrome", "Cable", "3G", function(err, data) {32 if (err) return console.error(err);33 console.log(data);34});35api.getTesters("Dulles", "Chrome", "Cable", "3G", "1", function(err, data) {36 if (err) return console.error(err);37 console.log(data);38});39api.getTesters("Dulles", "Chrome", "Cable", "3G", "1", "true", function(err, data) {40 if (err) return console.error(err);41 console.log(data);42});43api.getTesters("Dulles", "Chrome", "Cable", "3G", "1", "true", "false", function(err, data) {44 if (err) return console.error(err);45 console.log(data);46});47api.getTesters("Dulles", "Chrome", "C

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0d2f2f7f9c9a8a0a3c3b1e0f0f0a0a0');3var testId = '140819_F9_1R8';4wpt.res2_clients(testId, function(err, data) {5 if (err) throw err;6 console.log(data);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt_config = require('./config.json');3var client = wpt.createClient(wpt_config);4client.res2_clients(function(err, res) {5 if(err) {6 console.log(err);7 }8 else {9 console.log(res);10 }11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest(options);5wpt.runTest(url, function(err, data) {6 if (err) return console.error(err);7 console.log('Test submitted to WebPageTest for %s', url);8 console.log('View your test at: %s', data.data.userUrl);9 var testId = data.data.testId;10 wpt.getTestResults(testId, function(err, data) {11 if (err) return console.error(err);12 console.log('Test completed for %s', url);13 console.log('First View (i.e. Load Time): %d ms', data.data.average.firstView.loadTime);14 console.log('Repeat View (i.e. Load Time): %d ms', data.data.average.repeatView.loadTime);15 });16});

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