Best JavaScript code snippet using puppeteer
tools-buildbot-triggerable-tests.js
Source:tools-buildbot-triggerable-tests.js
...31 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);32 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());33 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());34 MockRemoteAPI.reset();35 return MockRemoteAPI.waitForRequest();36 }).then(() => {37 assert.equal(BuildRequest.all().length, 4);38 assert.equal(BuildRequest.findById(700).status(), 'completed');39 assert.equal(BuildRequest.findById(701).status(), 'running');40 assert.equal(BuildRequest.findById(702).status(), 'pending');41 assert.equal(BuildRequest.findById(703).status(), 'pending');42 assert.equal(MockRemoteAPI.requests[0].method, 'GET');43 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));44 MockRemoteAPI.requests[0].resolve({});45 return MockRemoteAPI.waitForRequest();46 }).then(() => {47 assert.equal(MockRemoteAPI.requests[1].method, 'GET');48 assert.equal(MockRemoteAPI.requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));49 MockRemoteAPI.requests[1].resolve({'builds': [MockData.runningBuildData(), MockData.finishedBuildData()]});50 return MockRemoteAPI.waitForRequest();51 }).then(() => {52 assert.equal(MockRemoteAPI.requests[2].method, 'POST');53 assert.equal(MockRemoteAPI.requests[2].url, '/api/v2/forceschedulers/force-some-builder-1');54 assert.deepEqual(MockRemoteAPI.requests[2].data, {'id': 702, 'jsonrpc': '2.0', 'method': 'force', 'params':55 {'wk': '191622', 'os': '10.11 15A284', 'build-request-id': 702, 'forcescheduler': 'force-some-builder-1'}});56 MockRemoteAPI.requests[2].resolve('OK');57 return MockRemoteAPI.waitForRequest();58 }).then(() => {59 assert.equal(MockRemoteAPI.requests[3].method, 'GET');60 assert.equal(MockRemoteAPI.requests[3].url, MockData.pendingBuildsUrl('some-builder-1'));61 MockRemoteAPI.requests[3].resolve(MockData.pendingBuild())62 return MockRemoteAPI.waitForRequest();63 }).then(() => {64 assert.equal(MockRemoteAPI.requests[4].method, 'GET');65 assert.equal(MockRemoteAPI.requests[4].url, MockData.recentBuildsUrl('some-builder-1', 2));66 MockRemoteAPI.requests[4].resolve({'builds': [MockData.runningBuildData(), MockData.finishedBuildData()]});67 return syncPromise;68 }).then(() => {69 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithSingleBuilder().triggerableName);70 }).then(() => {71 assert.equal(BuildRequest.all().length, 4);72 assert.equal(BuildRequest.findById(700).status(), 'completed');73 assert.equal(BuildRequest.findById(701).status(), 'running');74 assert.equal(BuildRequest.findById(702).status(), 'scheduled');75 assert.equal(BuildRequest.findById(703).status(), 'pending');76 });77 });78 it('should not schedule the next build request when there is a pending build', () => {79 const db = TestServer.database();80 let syncPromise;81 return MockData.addMockData(db, ['completed', 'running', 'pending', 'pending']).then(() => {82 return Manifest.fetch();83 }).then(() => {84 let config = MockData.mockTestSyncConfigWithSingleBuilder();85 let logger = new MockLogger;86 let slaveInfo = {name: 'sync-slave', password: 'password'};87 let triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);88 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());89 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());90 MockRemoteAPI.reset();91 return MockRemoteAPI.waitForRequest();92 }).then(() => {93 assert.equal(MockRemoteAPI.requests[0].method, 'GET');94 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));95 MockRemoteAPI.requests[0].resolve(MockData.pendingBuild());96 return MockRemoteAPI.waitForRequest();97 }).then(() => {98 assert.equal(MockRemoteAPI.requests[1].method, 'GET');99 assert.equal(MockRemoteAPI.requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));100 MockRemoteAPI.requests[1].resolve({'builds' : [MockData.runningBuildData(), MockData.finishedBuildData()]});101 return MockRemoteAPI.waitForRequest();102 }).then(() => {103 assert.equal(MockRemoteAPI.requests[2].method, 'GET');104 assert.equal(MockRemoteAPI.requests[2].url, MockData.pendingBuildsUrl('some-builder-1'));105 MockRemoteAPI.requests[2].resolve(MockData.pendingBuild())106 return MockRemoteAPI.waitForRequest();107 }).then(() => {108 assert.equal(MockRemoteAPI.requests[3].method, 'GET');109 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some-builder-1', 2));110 MockRemoteAPI.requests[3].resolve({'builds' : [MockData.runningBuildData(), MockData.finishedBuildData()]});111 return syncPromise;112 }).then(() => {113 assert.equal(BuildRequest.all().length, 4);114 assert.equal(BuildRequest.findById(700).status(), 'completed');115 assert.equal(BuildRequest.findById(701).status(), 'running');116 assert.equal(BuildRequest.findById(702).status(), 'pending');117 assert.equal(BuildRequest.findById(703).status(), 'pending');118 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithSingleBuilder().triggerableName);119 }).then(() => {120 assert.equal(BuildRequest.all().length, 4);121 assert.equal(BuildRequest.findById(700).status(), 'completed');122 assert.equal(BuildRequest.findById(701).status(), 'running');123 assert.equal(BuildRequest.findById(702).status(), 'scheduled');124 assert.equal(BuildRequest.findById(703).status(), 'pending');125 });126 });127 it('should schedule the build request on a builder without a pending build if it\'s the first request in the group', () => {128 const db = TestServer.database();129 let syncPromise;130 return MockData.addMockData(db, ['pending', 'pending', 'pending', 'pending']).then(() => {131 return Manifest.fetch();132 }).then(() => {133 const config = MockData.mockTestSyncConfigWithTwoBuilders();134 const logger = new MockLogger;135 const slaveInfo = {name: 'sync-slave', password: 'password'};136 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);137 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());138 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());139 MockRemoteAPI.reset();140 return MockRemoteAPI.waitForRequest();141 }).then(() => {142 assert.equal(MockRemoteAPI.requests.length, 2);143 assert.equal(MockRemoteAPI.requests[0].method, 'GET');144 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));145 MockRemoteAPI.requests[0].resolve(MockData.pendingBuild({buildRequestId: 999}));146 assert.equal(MockRemoteAPI.requests[1].method, 'GET');147 assert.equal(MockRemoteAPI.requests[1].url, MockData.pendingBuildsUrl('some builder 2'));148 MockRemoteAPI.requests[1].resolve({});149 return MockRemoteAPI.waitForRequest();150 }).then(() => {151 assert.equal(MockRemoteAPI.requests.length, 4);152 assert.equal(MockRemoteAPI.requests[2].method, 'GET');153 assert.equal(MockRemoteAPI.requests[2].url, MockData.recentBuildsUrl('some-builder-1', 2));154 MockRemoteAPI.requests[2].resolve({});155 assert.equal(MockRemoteAPI.requests[3].method, 'GET');156 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some builder 2', 2));157 MockRemoteAPI.requests[3].resolve({});158 return MockRemoteAPI.waitForRequest();159 }).then(() => {160 assert.equal(MockRemoteAPI.requests.length, 5);161 assert.equal(MockRemoteAPI.requests[4].method, 'POST');162 assert.equal(MockRemoteAPI.requests[4].url, '/api/v2/forceschedulers/force-some-builder-2');163 assert.deepEqual(MockRemoteAPI.requests[4].data, {'id': '700', 'jsonrpc': '2.0', 'method': 'force', 'params':164 {'wk': '191622', 'os': '10.11 15A284', 'build-request-id': '700', 'forcescheduler': 'force-some-builder-2'}});165 MockRemoteAPI.requests[4].resolve('OK');166 return MockRemoteAPI.waitForRequest();167 }).then(() => {168 assert.equal(MockRemoteAPI.requests.length, 7);169 assert.equal(MockRemoteAPI.requests[5].method, 'GET');170 assert.equal(MockRemoteAPI.requests[5].url, MockData.pendingBuildsUrl('some-builder-1'));171 MockRemoteAPI.requests[5].resolve(MockData.pendingBuild({buildRequestId: 999}));172 assert.equal(MockRemoteAPI.requests[6].method, 'GET');173 assert.equal(MockRemoteAPI.requests[6].url, MockData.pendingBuildsUrl('some builder 2'));174 MockRemoteAPI.requests[6].resolve(MockData.pendingBuild({builderId: MockData.builderIDForName('some builder 2'), buildRequestId: 700, buildbotBuildRequestId: 17}));175 return MockRemoteAPI.waitForRequest();176 }).then(() => {177 assert.equal(MockRemoteAPI.requests.length, 9);178 assert.equal(MockRemoteAPI.requests[7].method, 'GET');179 assert.equal(MockRemoteAPI.requests[7].url, MockData.recentBuildsUrl('some-builder-1', 2));180 MockRemoteAPI.requests[7].resolve({});181 assert.equal(MockRemoteAPI.requests[8].method, 'GET');182 assert.equal(MockRemoteAPI.requests[8].url, MockData.recentBuildsUrl('some builder 2', 2));183 MockRemoteAPI.requests[8].resolve({});184 return syncPromise;185 }).then(() => {186 assert.equal(BuildRequest.all().length, 4);187 assert.equal(BuildRequest.findById(700).status(), 'pending');188 assert.equal(BuildRequest.findById(700).statusUrl(), null);189 assert.equal(BuildRequest.findById(701).status(), 'pending');190 assert.equal(BuildRequest.findById(701).statusUrl(), null);191 assert.equal(BuildRequest.findById(702).status(), 'pending');192 assert.equal(BuildRequest.findById(702).statusUrl(), null);193 assert.equal(BuildRequest.findById(703).status(), 'pending');194 assert.equal(BuildRequest.findById(703).statusUrl(), null);195 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);196 }).then(() => {197 assert.equal(BuildRequest.all().length, 4);198 assert.equal(BuildRequest.findById(700).status(), 'scheduled');199 assert.equal(BuildRequest.findById(700).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');200 assert.equal(BuildRequest.findById(701).status(), 'pending');201 assert.equal(BuildRequest.findById(701).statusUrl(), null);202 assert.equal(BuildRequest.findById(702).status(), 'pending');203 assert.equal(BuildRequest.findById(702).statusUrl(), null);204 assert.equal(BuildRequest.findById(703).status(), 'pending');205 assert.equal(BuildRequest.findById(703).statusUrl(), null);206 });207 });208 it('should not schedule a build request on a different builder than the one the first build request is pending', () => {209 const db = TestServer.database();210 let syncPromise;211 return MockData.addMockData(db, ['pending', 'pending', 'pending', 'pending']).then(() => {212 return Manifest.fetch();213 }).then(() => {214 let config = MockData.mockTestSyncConfigWithTwoBuilders();215 let logger = new MockLogger;216 let slaveInfo = {name: 'sync-slave', password: 'password'};217 let triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);218 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());219 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());220 MockRemoteAPI.reset();221 return MockRemoteAPI.waitForRequest();222 }).then(() => {223 assert.equal(MockRemoteAPI.requests.length, 2);224 assert.equal(MockRemoteAPI.requests[0].method, 'GET');225 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));226 MockRemoteAPI.requests[0].resolve(MockData.pendingBuild({buildRequestId: 700, buildbotBuildRequestId: 17}));227 assert.equal(MockRemoteAPI.requests[1].method, 'GET');228 assert.equal(MockRemoteAPI.requests[1].url, MockData.pendingBuildsUrl('some builder 2'));229 MockRemoteAPI.requests[1].resolve({});230 return MockRemoteAPI.waitForRequest();231 }).then(() => {232 assert.equal(MockRemoteAPI.requests.length, 4);233 assert.equal(MockRemoteAPI.requests[2].method, 'GET');234 assert.equal(MockRemoteAPI.requests[2].url, MockData.recentBuildsUrl('some-builder-1', 2));235 MockRemoteAPI.requests[2].resolve({});236 assert.equal(MockRemoteAPI.requests[3].method, 'GET');237 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some builder 2', 2));238 MockRemoteAPI.requests[3].resolve({});239 return MockRemoteAPI.waitForRequest();240 }).then(() => {241 assert.equal(MockRemoteAPI.requests.length, 6);242 assert.equal(MockRemoteAPI.requests[4].method, 'GET');243 assert.equal(MockRemoteAPI.requests[4].url, MockData.pendingBuildsUrl('some-builder-1'));244 MockRemoteAPI.requests[4].resolve(MockData.pendingBuild({buildRequestId: 700, buildbotBuildRequestId: 17}));245 assert.equal(MockRemoteAPI.requests[5].method, 'GET');246 assert.equal(MockRemoteAPI.requests[5].url, MockData.pendingBuildsUrl('some builder 2'));247 MockRemoteAPI.requests[5].resolve({});248 return MockRemoteAPI.waitForRequest();249 }).then(() => {250 assert.equal(MockRemoteAPI.requests.length, 8);251 assert.equal(MockRemoteAPI.requests[6].method, 'GET');252 assert.equal(MockRemoteAPI.requests[6].url, MockData.recentBuildsUrl('some-builder-1', 2));253 MockRemoteAPI.requests[6].resolve({});254 assert.equal(MockRemoteAPI.requests[7].method, 'GET');255 assert.equal(MockRemoteAPI.requests[7].url, MockData.recentBuildsUrl('some builder 2', 2));256 MockRemoteAPI.requests[7].resolve({});257 return syncPromise;258 }).then(() => {259 assert.equal(BuildRequest.all().length, 4);260 assert.equal(BuildRequest.findById(700).status(), 'pending');261 assert.equal(BuildRequest.findById(700).statusUrl(), null);262 assert.equal(BuildRequest.findById(701).status(), 'pending');263 assert.equal(BuildRequest.findById(701).statusUrl(), null);264 assert.equal(BuildRequest.findById(702).status(), 'pending');265 assert.equal(BuildRequest.findById(702).statusUrl(), null);266 assert.equal(BuildRequest.findById(703).status(), 'pending');267 assert.equal(BuildRequest.findById(703).statusUrl(), null);268 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);269 }).then(() => {270 assert.equal(BuildRequest.all().length, 4);271 assert.equal(BuildRequest.findById(700).status(), 'scheduled');272 assert.equal(BuildRequest.findById(700).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');273 assert.equal(BuildRequest.findById(701).status(), 'pending');274 assert.equal(BuildRequest.findById(701).statusUrl(), null);275 assert.equal(BuildRequest.findById(702).status(), 'pending');276 assert.equal(BuildRequest.findById(702).statusUrl(), null);277 assert.equal(BuildRequest.findById(703).status(), 'pending');278 assert.equal(BuildRequest.findById(703).statusUrl(), null);279 });280 });281 it('should update the status of a pending build and schedule a new build if the pending build had started running', () => {282 const db = TestServer.database();283 let syncPromise;284 return MockData.addMockData(db, ['pending', 'pending', 'pending', 'pending']).then(() => {285 return Manifest.fetch();286 }).then(() => {287 const config = MockData.mockTestSyncConfigWithTwoBuilders();288 const logger = new MockLogger;289 const slaveInfo = {name: 'sync-slave', password: 'password'};290 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);291 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());292 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());293 MockRemoteAPI.reset();294 return MockRemoteAPI.waitForRequest();295 }).then(() => {296 assert.equal(MockRemoteAPI.requests.length, 2);297 assert.equal(MockRemoteAPI.requests[0].method, 'GET');298 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));299 MockRemoteAPI.requests[0].resolve({});300 assert.equal(MockRemoteAPI.requests[1].method, 'GET');301 assert.equal(MockRemoteAPI.requests[1].url, MockData.pendingBuildsUrl('some builder 2'));302 MockRemoteAPI.requests[1].resolve({});303 return MockRemoteAPI.waitForRequest();304 }).then(() => {305 assert.equal(MockRemoteAPI.requests.length, 4);306 assert.equal(MockRemoteAPI.requests[2].method, 'GET');307 assert.equal(MockRemoteAPI.requests[2].url, MockData.recentBuildsUrl('some-builder-1', 2));308 MockRemoteAPI.requests[2].resolve({'builds' : [MockData.runningBuildData({buildRequestId: 701}), MockData.finishedBuildData({buildRequestId: 700})]});309 assert.equal(MockRemoteAPI.requests[3].method, 'GET');310 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some builder 2', 2));311 MockRemoteAPI.requests[3].resolve({});312 return MockRemoteAPI.waitForRequest();313 }).then(() => {314 assert.equal(MockRemoteAPI.requests.length, 5);315 assert.equal(MockRemoteAPI.requests[4].method, 'POST');316 assert.equal(MockRemoteAPI.requests[4].url, '/api/v2/forceschedulers/force-some-builder-1');317 assert.deepEqual(MockRemoteAPI.requests[4].data, {'id': '702', 'jsonrpc': '2.0', 'method': 'force', 'params':318 {'wk': '191622', 'os': '10.11 15A284', 'build-request-id': '702', 'forcescheduler': 'force-some-builder-1'}});319 MockRemoteAPI.requests[4].resolve('OK');320 return MockRemoteAPI.waitForRequest();321 }).then(() => {322 assert.equal(MockRemoteAPI.requests.length, 7);323 assert.equal(MockRemoteAPI.requests[5].method, 'GET');324 assert.equal(MockRemoteAPI.requests[5].url, MockData.pendingBuildsUrl('some-builder-1'));325 MockRemoteAPI.requests[5].resolve(MockData.pendingBuild({buildRequestId: 702, buildbotBuildRequestId: 17}));326 assert.equal(MockRemoteAPI.requests[6].method, 'GET');327 assert.equal(MockRemoteAPI.requests[6].url, MockData.pendingBuildsUrl('some builder 2'));328 MockRemoteAPI.requests[6].resolve({});329 return MockRemoteAPI.waitForRequest();330 }).then(() => {331 assert.equal(MockRemoteAPI.requests.length, 9);332 assert.equal(MockRemoteAPI.requests[7].method, 'GET');333 assert.equal(MockRemoteAPI.requests[7].url, MockData.recentBuildsUrl('some-builder-1', 2));334 MockRemoteAPI.requests[7].resolve({'builds' : [MockData.runningBuildData({buildRequestId: 701}), MockData.finishedBuildData({buildRequestId: 700})]});335 assert.equal(MockRemoteAPI.requests[8].method, 'GET');336 assert.equal(MockRemoteAPI.requests[8].url, MockData.recentBuildsUrl('some builder 2', 2));337 MockRemoteAPI.requests[8].resolve({});338 return syncPromise;339 }).then(() => {340 assert.equal(BuildRequest.all().length, 4);341 assert.equal(BuildRequest.findById(700).status(), 'pending');342 assert.equal(BuildRequest.findById(700).statusUrl(), null);343 assert.equal(BuildRequest.findById(701).status(), 'pending');344 assert.equal(BuildRequest.findById(701).statusUrl(), null);345 assert.equal(BuildRequest.findById(702).status(), 'pending');346 assert.equal(BuildRequest.findById(702).statusUrl(), null);347 assert.equal(BuildRequest.findById(703).status(), 'pending');348 assert.equal(BuildRequest.findById(703).statusUrl(), null);349 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);350 }).then(() => {351 assert.equal(BuildRequest.all().length, 4);352 assert.equal(BuildRequest.findById(700).status(), 'failed');353 assert.equal(BuildRequest.findById(700).statusUrl(), MockData.statusUrl('some-builder-1', 123));354 assert.equal(BuildRequest.findById(701).status(), 'running');355 assert.equal(BuildRequest.findById(701).statusUrl(), MockData.statusUrl('some-builder-1', 124));356 assert.equal(BuildRequest.findById(702).status(), 'scheduled');357 assert.equal(BuildRequest.findById(702).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');358 assert.equal(BuildRequest.findById(703).status(), 'pending');359 assert.equal(BuildRequest.findById(703).statusUrl(), null);360 });361 });362 it('should update the status of a scheduled build if the pending build had started running', () => {363 const db = TestServer.database();364 let syncPromise;365 return MockData.addMockData(db, ['scheduled', 'pending', 'pending', 'pending']).then(() => {366 return Manifest.fetch();367 }).then(() => {368 let config = MockData.mockTestSyncConfigWithSingleBuilder();369 let logger = new MockLogger;370 let slaveInfo = {name: 'sync-slave', password: 'password'};371 let triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);372 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());373 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());374 MockRemoteAPI.reset();375 return MockRemoteAPI.waitForRequest();376 }).then(() => {377 assert.equal(MockRemoteAPI.requests.length, 1);378 assert.equal(MockRemoteAPI.requests[0].method, 'GET');379 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));380 MockRemoteAPI.requests[0].resolve(MockData.pendingBuild({buildRequestId: 700, buildbotBuildRequestId: 17}));381 return MockRemoteAPI.waitForRequest();382 }).then(() => {383 assert.equal(MockRemoteAPI.requests.length, 2);384 assert.equal(MockRemoteAPI.requests[1].method, 'GET');385 assert.equal(MockRemoteAPI.requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));386 MockRemoteAPI.requests[1].resolve({});387 return MockRemoteAPI.waitForRequest();388 }).then(() => {389 assert.equal(MockRemoteAPI.requests.length, 3);390 assert.equal(MockRemoteAPI.requests[2].method, 'GET');391 assert.equal(MockRemoteAPI.requests[2].url, MockData.pendingBuildsUrl('some-builder-1'));392 MockRemoteAPI.requests[2].resolve({});393 return MockRemoteAPI.waitForRequest();394 }).then(() => {395 assert.equal(MockRemoteAPI.requests.length, 4);396 assert.equal(MockRemoteAPI.requests[3].method, 'GET');397 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some-builder-1', 2));398 MockRemoteAPI.requests[3].resolve(MockData.runningBuild({buildRequestId: 700}));399 return syncPromise;400 }).then(() => {401 assert.equal(BuildRequest.all().length, 4);402 assert.equal(BuildRequest.findById(700).status(), 'scheduled');403 assert.equal(BuildRequest.findById(700).statusUrl(), null);404 assert.equal(BuildRequest.findById(701).status(), 'pending');405 assert.equal(BuildRequest.findById(701).statusUrl(), null);406 assert.equal(BuildRequest.findById(702).status(), 'pending');407 assert.equal(BuildRequest.findById(702).statusUrl(), null);408 assert.equal(BuildRequest.findById(703).status(), 'pending');409 assert.equal(BuildRequest.findById(703).statusUrl(), null);410 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);411 }).then(() => {412 assert.equal(BuildRequest.all().length, 4);413 assert.equal(BuildRequest.findById(700).status(), 'running');414 assert.equal(BuildRequest.findById(700).statusUrl(), MockData.statusUrl('some-builder-1', 124));415 assert.equal(BuildRequest.findById(701).status(), 'pending');416 assert.equal(BuildRequest.findById(701).statusUrl(), null);417 assert.equal(BuildRequest.findById(702).status(), 'pending');418 assert.equal(BuildRequest.findById(702).statusUrl(), null);419 assert.equal(BuildRequest.findById(703).status(), 'pending');420 assert.equal(BuildRequest.findById(703).statusUrl(), null);421 });422 });423 it('should schedule a build request on a builder without pending builds if the request belongs to a new test group', () => {424 const db = TestServer.database();425 let syncPromise;426 return Promise.all([427 MockData.addMockData(db, ['completed', 'pending', 'pending', 'pending']),428 MockData.addAnotherMockTestGroup(db, ['pending', 'pending', 'pending', 'pending'])429 ]).then(() => {430 return Manifest.fetch();431 }).then(() => {432 const config = MockData.mockTestSyncConfigWithTwoBuilders();433 const logger = new MockLogger;434 const slaveInfo = {name: 'sync-slave', password: 'password'};435 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);436 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());437 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());438 MockRemoteAPI.reset();439 return MockRemoteAPI.waitForRequest();440 }).then(() => {441 assert.equal(MockRemoteAPI.requests.length, 2);442 assert.equal(MockRemoteAPI.requests[0].method, 'GET');443 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));444 MockRemoteAPI.requests[0].resolve(MockData.pendingBuild({buildRequestId: 702, buildbotBuildRequestId: 17}));445 assert.equal(MockRemoteAPI.requests[1].method, 'GET');446 assert.equal(MockRemoteAPI.requests[1].url, MockData.pendingBuildsUrl('some builder 2'));447 MockRemoteAPI.requests[1].resolve({});448 return MockRemoteAPI.waitForRequest();449 }).then(() => {450 assert.equal(MockRemoteAPI.requests.length, 4);451 assert.equal(MockRemoteAPI.requests[2].method, 'GET');452 assert.equal(MockRemoteAPI.requests[2].url, MockData.recentBuildsUrl('some-builder-1', 2));453 MockRemoteAPI.requests[2].resolve({'builds' : [MockData.runningBuildData({buildRequestId: 701}), MockData.finishedBuildData({buildRequestId: 700})]});454 assert.equal(MockRemoteAPI.requests[3].method, 'GET');455 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some builder 2', 2));456 MockRemoteAPI.requests[3].resolve({});457 return MockRemoteAPI.waitForRequest();458 }).then(() => {459 assert.equal(MockRemoteAPI.requests.length, 5);460 assert.equal(MockRemoteAPI.requests[4].method, 'POST');461 assert.equal(MockRemoteAPI.requests[4].url, '/api/v2/forceschedulers/force-some-builder-2');462 assert.deepEqual(MockRemoteAPI.requests[4].data, {'id': '710', 'jsonrpc': '2.0', 'method': 'force', 'params':463 {'wk': '191622', 'os': '10.11 15A284', 'build-request-id': '710', 'forcescheduler': 'force-some-builder-2'}});464 MockRemoteAPI.requests[4].resolve('OK');465 return MockRemoteAPI.waitForRequest();466 }).then(() => {467 assert.equal(MockRemoteAPI.requests.length, 7);468 assert.equal(MockRemoteAPI.requests[5].method, 'GET');469 assert.equal(MockRemoteAPI.requests[5].url, MockData.pendingBuildsUrl('some-builder-1'));470 MockRemoteAPI.requests[5].resolve(MockData.pendingBuild({buildRequestId: 702, buildbotBuildRequestId: 17}));471 assert.equal(MockRemoteAPI.requests[6].method, 'GET');472 assert.equal(MockRemoteAPI.requests[6].url, MockData.pendingBuildsUrl('some builder 2'));473 MockRemoteAPI.requests[6].resolve(MockData.pendingBuild({builderId: MockData.builderIDForName('some builder 2'), buildRequestId: 710, buildbotBuildRequestId: 17}));474 return MockRemoteAPI.waitForRequest();475 }).then(() => {476 assert.equal(MockRemoteAPI.requests.length, 9);477 assert.equal(MockRemoteAPI.requests[7].method, 'GET');478 assert.equal(MockRemoteAPI.requests[7].url, MockData.recentBuildsUrl('some-builder-1', 2));479 MockRemoteAPI.requests[7].resolve({'builds' : [MockData.runningBuildData({buildRequestId: 701}), MockData.finishedBuildData({buildRequestId: 700})]});480 assert.equal(MockRemoteAPI.requests[8].method, 'GET');481 assert.equal(MockRemoteAPI.requests[8].url, MockData.recentBuildsUrl('some builder 2', 2));482 MockRemoteAPI.requests[8].resolve({});483 return syncPromise;484 }).then(() => {485 assert.equal(BuildRequest.all().length, 8);486 assert.equal(BuildRequest.findById(700).status(), 'completed');487 assert.equal(BuildRequest.findById(700).statusUrl(), null);488 assert.equal(BuildRequest.findById(701).status(), 'pending');489 assert.equal(BuildRequest.findById(701).statusUrl(), null);490 assert.equal(BuildRequest.findById(702).status(), 'pending');491 assert.equal(BuildRequest.findById(702).statusUrl(), null);492 assert.equal(BuildRequest.findById(703).status(), 'pending');493 assert.equal(BuildRequest.findById(703).statusUrl(), null);494 assert.equal(BuildRequest.findById(710).status(), 'pending');495 assert.equal(BuildRequest.findById(710).statusUrl(), null);496 assert.equal(BuildRequest.findById(711).status(), 'pending');497 assert.equal(BuildRequest.findById(711).statusUrl(), null);498 assert.equal(BuildRequest.findById(712).status(), 'pending');499 assert.equal(BuildRequest.findById(712).statusUrl(), null);500 assert.equal(BuildRequest.findById(713).status(), 'pending');501 assert.equal(BuildRequest.findById(713).statusUrl(), null);502 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);503 }).then(() => {504 assert.equal(BuildRequest.all().length, 8);505 assert.equal(BuildRequest.findById(700).status(), 'completed');506 assert.equal(BuildRequest.findById(700).statusUrl(), MockData.statusUrl('some-builder-1', 123));507 assert.equal(BuildRequest.findById(701).status(), 'running');508 assert.equal(BuildRequest.findById(701).statusUrl(), MockData.statusUrl('some-builder-1', 124));509 assert.equal(BuildRequest.findById(702).status(), 'scheduled');510 assert.equal(BuildRequest.findById(702).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');511 assert.equal(BuildRequest.findById(703).status(), 'pending');512 assert.equal(BuildRequest.findById(703).statusUrl(), null);513 assert.equal(BuildRequest.findById(710).status(), 'scheduled');514 assert.equal(BuildRequest.findById(710).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');515 assert.equal(BuildRequest.findById(711).status(), 'pending');516 assert.equal(BuildRequest.findById(711).statusUrl(), null);517 assert.equal(BuildRequest.findById(712).status(), 'pending');518 assert.equal(BuildRequest.findById(712).statusUrl(), null);519 assert.equal(BuildRequest.findById(713).status(), 'pending');520 assert.equal(BuildRequest.findById(713).statusUrl(), null);521 });522 });523 it('should schedule a build request on the same scheduler the first request had ran', () => {524 const db = TestServer.database();525 let syncPromise;526 return Promise.all([527 MockData.addMockData(db, ['running', 'pending', 'pending', 'pending']),528 MockData.addAnotherMockTestGroup(db, ['running', 'pending', 'pending', 'pending'])529 ]).then(() => {530 return Manifest.fetch();531 }).then(() => {532 const config = MockData.mockTestSyncConfigWithTwoBuilders();533 const logger = new MockLogger;534 const slaveInfo = {name: 'sync-slave', password: 'password'};535 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);536 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());537 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());538 MockRemoteAPI.reset();539 return MockRemoteAPI.waitForRequest();540 }).then(() => {541 assert.equal(MockRemoteAPI.requests.length, 2);542 assert.equal(MockRemoteAPI.requests[0].method, 'GET');543 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));544 MockRemoteAPI.requests[0].resolve({});545 assert.equal(MockRemoteAPI.requests[1].method, 'GET');546 assert.equal(MockRemoteAPI.requests[1].url, MockData.pendingBuildsUrl('some builder 2'));547 MockRemoteAPI.requests[1].resolve({});548 return MockRemoteAPI.waitForRequest();549 }).then(() => {550 assert.equal(MockRemoteAPI.requests.length, 4);551 assert.equal(MockRemoteAPI.requests[2].method, 'GET');552 assert.equal(MockRemoteAPI.requests[2].url, MockData.recentBuildsUrl('some-builder-1', 2));553 MockRemoteAPI.requests[2].resolve(MockData.runningBuild({buildRequestId: 710}));554 assert.equal(MockRemoteAPI.requests[3].method, 'GET');555 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some builder 2', 2));556 MockRemoteAPI.requests[3].resolve(MockData.runningBuild({builderId: MockData.builderIDForName('some builder 2'), buildRequestId: 700}));557 return MockRemoteAPI.waitForRequest();558 }).then(() => {559 assert.equal(MockRemoteAPI.requests.length, 6);560 assert.equal(MockRemoteAPI.requests[4].method, 'POST');561 assert.equal(MockRemoteAPI.requests[4].url, '/api/v2/forceschedulers/force-some-builder-2');562 assert.deepEqual(MockRemoteAPI.requests[4].data, {'id': '701', 'jsonrpc': '2.0', 'method': 'force', 'params':563 {'wk': '192736', 'os': '10.11 15A284', 'build-request-id': '701', 'forcescheduler': 'force-some-builder-2'}});564 MockRemoteAPI.requests[4].resolve('OK');565 assert.equal(MockRemoteAPI.requests[5].method, 'POST');566 assert.equal(MockRemoteAPI.requests[5].url, '/api/v2/forceschedulers/force-some-builder-1');567 assert.deepEqual(MockRemoteAPI.requests[5].data, {'id': '711', 'jsonrpc': '2.0', 'method': 'force', 'params':568 {'wk': '192736', 'os': '10.11 15A284', 'build-request-id': '711', 'forcescheduler': 'force-some-builder-1'}});569 MockRemoteAPI.requests[5].resolve('OK');570 return MockRemoteAPI.waitForRequest();571 }).then(() => {572 assert.equal(MockRemoteAPI.requests.length, 8);573 assert.equal(MockRemoteAPI.requests[6].method, 'GET');574 assert.equal(MockRemoteAPI.requests[6].url, MockData.pendingBuildsUrl('some-builder-1'));575 MockRemoteAPI.requests[6].resolve(MockData.pendingBuild({buildRequestId: 711, buildbotBuildRequestId: 17}));576 assert.equal(MockRemoteAPI.requests[7].method, 'GET');577 assert.equal(MockRemoteAPI.requests[7].url, MockData.pendingBuildsUrl('some builder 2'));578 MockRemoteAPI.requests[7].resolve(MockData.pendingBuild({builderId: MockData.builderIDForName('some builder 2'), buildRequestId: 701, buildbotBuildRequestId: 17}));579 return MockRemoteAPI.waitForRequest();580 }).then(() => {581 assert.equal(MockRemoteAPI.requests.length, 10);582 assert.equal(MockRemoteAPI.requests[8].method, 'GET');583 assert.equal(MockRemoteAPI.requests[8].url, MockData.recentBuildsUrl('some-builder-1', 2));584 MockRemoteAPI.requests[8].resolve(MockData.runningBuild({buildRequestId: 710}));585 assert.equal(MockRemoteAPI.requests[9].method, 'GET');586 assert.equal(MockRemoteAPI.requests[9].url, MockData.recentBuildsUrl('some builder 2', 2));587 MockRemoteAPI.requests[9].resolve(MockData.runningBuild({builderId: MockData.builderIDForName('some builder 2'), buildRequestId: 700}));588 return syncPromise;589 }).then(() => {590 assert.equal(BuildRequest.all().length, 8);591 assert.equal(BuildRequest.findById(700).status(), 'running');592 assert.equal(BuildRequest.findById(700).statusUrl(), null);593 assert.equal(BuildRequest.findById(701).status(), 'pending');594 assert.equal(BuildRequest.findById(701).statusUrl(), null);595 assert.equal(BuildRequest.findById(702).status(), 'pending');596 assert.equal(BuildRequest.findById(702).statusUrl(), null);597 assert.equal(BuildRequest.findById(703).status(), 'pending');598 assert.equal(BuildRequest.findById(703).statusUrl(), null);599 assert.equal(BuildRequest.findById(710).status(), 'running');600 assert.equal(BuildRequest.findById(710).statusUrl(), null);601 assert.equal(BuildRequest.findById(711).status(), 'pending');602 assert.equal(BuildRequest.findById(711).statusUrl(), null);603 assert.equal(BuildRequest.findById(712).status(), 'pending');604 assert.equal(BuildRequest.findById(712).statusUrl(), null);605 assert.equal(BuildRequest.findById(713).status(), 'pending');606 assert.equal(BuildRequest.findById(713).statusUrl(), null);607 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);608 }).then(() => {609 assert.equal(BuildRequest.all().length, 8);610 assert.equal(BuildRequest.findById(700).status(), 'running');611 assert.equal(BuildRequest.findById(700).statusUrl(), MockData.statusUrl('some builder 2', 124));612 assert.equal(BuildRequest.findById(701).status(), 'scheduled');613 assert.equal(BuildRequest.findById(701).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');614 assert.equal(BuildRequest.findById(702).status(), 'pending');615 assert.equal(BuildRequest.findById(702).statusUrl(), null);616 assert.equal(BuildRequest.findById(703).status(), 'pending');617 assert.equal(BuildRequest.findById(703).statusUrl(), null);618 assert.equal(BuildRequest.findById(710).status(), 'running');619 assert.equal(BuildRequest.findById(710).statusUrl(), MockData.statusUrl('some-builder-1', 124));620 assert.equal(BuildRequest.findById(711).status(), 'scheduled');621 assert.equal(BuildRequest.findById(711).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');622 assert.equal(BuildRequest.findById(712).status(), 'pending');623 assert.equal(BuildRequest.findById(712).statusUrl(), null);624 assert.equal(BuildRequest.findById(713).status(), 'pending');625 assert.equal(BuildRequest.findById(713).statusUrl(), null);626 });627 });628 it('should wait for POST to complete before trying to poll buildbot again', () => {629 const db = TestServer.database();630 const requests = MockRemoteAPI.requests;631 let syncPromise;632 return Promise.all([633 MockData.addMockData(db, ['pending', 'pending', 'pending', 'pending']),634 MockData.addAnotherMockTestGroup(db, ['pending', 'pending', 'pending', 'pending'])635 ]).then(() => Manifest.fetch()).then(() => {636 const config = MockData.mockTestSyncConfigWithSingleBuilder();637 const logger = new MockLogger;638 const slaveInfo = {name: 'sync-slave', password: 'password'};639 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);640 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());641 assertRequestAndResolve(requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());642 MockRemoteAPI.reset();643 return MockRemoteAPI.waitForRequest();644 }).then(() => {645 assert.equal(requests.length, 1);646 assert.equal(requests[0].method, 'GET');647 assert.equal(requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));648 MockRemoteAPI.requests[0].resolve({});649 return MockRemoteAPI.waitForRequest();650 }).then(() => {651 assert.equal(requests.length, 2);652 assert.equal(requests[1].method, 'GET');653 assert.equal(requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));654 requests[1].resolve({});655 return MockRemoteAPI.waitForRequest();656 }).then(() => {657 assert.equal(requests.length, 3);658 assert.equal(requests[2].method, 'POST');659 assert.equal(requests[2].url, '/api/v2/forceschedulers/force-some-builder-1');660 assert.deepEqual(requests[2].data, {'id': '700', 'jsonrpc': '2.0', 'method': 'force', 'params':661 {'wk': '191622', 'os': '10.11 15A284', 'build-request-id': '700', 'forcescheduler': 'force-some-builder-1'}});662 return new Promise((resolve) => setTimeout(resolve, 10));663 }).then(() => {664 assert.equal(requests.length, 3);665 requests[2].resolve('OK');666 return MockRemoteAPI.waitForRequest();667 }).then(() => {668 assert.equal(requests.length, 4);669 assert.equal(requests[3].method, 'GET');670 assert.equal(requests[3].url, MockData.pendingBuildsUrl('some-builder-1'));671 MockRemoteAPI.requests[3].resolve(MockData.pendingBuild({buildRequestId: 700, buildbotBuildRequestId: 17}));672 return MockRemoteAPI.waitForRequest();673 }).then(() => {674 assert.equal(requests.length, 5);675 assert.equal(requests[4].method, 'GET');676 assert.equal(requests[4].url, MockData.recentBuildsUrl('some-builder-1', 2));677 requests[4].resolve({});678 return syncPromise;679 }).then(() => {680 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);681 }).then(() => {682 assert.equal(BuildRequest.all().length, 8);683 assert.equal(BuildRequest.findById(700).status(), 'scheduled');684 assert.equal(BuildRequest.findById(700).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');685 assert.equal(BuildRequest.findById(701).status(), 'pending');686 assert.equal(BuildRequest.findById(701).statusUrl(), null);687 assert.equal(BuildRequest.findById(702).status(), 'pending');688 assert.equal(BuildRequest.findById(702).statusUrl(), null);689 assert.equal(BuildRequest.findById(703).status(), 'pending');690 assert.equal(BuildRequest.findById(703).statusUrl(), null);691 assert.equal(BuildRequest.findById(710).status(), 'pending');692 assert.equal(BuildRequest.findById(710).statusUrl(), null);693 assert.equal(BuildRequest.findById(711).status(), 'pending');694 assert.equal(BuildRequest.findById(711).statusUrl(), null);695 assert.equal(BuildRequest.findById(712).status(), 'pending');696 assert.equal(BuildRequest.findById(712).statusUrl(), null);697 assert.equal(BuildRequest.findById(713).status(), 'pending');698 assert.equal(BuildRequest.findById(713).statusUrl(), null);699 });700 });701 it('should recover from multiple test groups running simultenously', () => {702 const db = TestServer.database();703 const requests = MockRemoteAPI.requests;704 let syncPromise;705 let triggerable;706 return Promise.all([707 MockData.addMockData(db, ['completed', 'pending', 'pending', 'pending']),708 MockData.addAnotherMockTestGroup(db, ['completed', 'pending', 'pending', 'pending'])709 ]).then(() => {710 return Manifest.fetch();711 }).then(() => {712 const config = MockData.mockTestSyncConfigWithSingleBuilder();713 const logger = new MockLogger;714 const slaveInfo = {name: 'sync-slave', password: 'password'};715 triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);716 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());717 assertRequestAndResolve(requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());718 MockRemoteAPI.reset();719 return MockRemoteAPI.waitForRequest();720 }).then(() => {721 assert.equal(requests.length, 1);722 assertRequestAndResolve(requests[0], 'GET', MockData.pendingBuildsUrl('some-builder-1'), {});723 return MockRemoteAPI.waitForRequest();724 }).then(() => {725 assert.equal(requests.length, 2);726 assertRequestAndResolve(requests[1], 'GET', MockData.recentBuildsUrl('some-builder-1', 2),727 {'builds' : [MockData.runningBuildData({buildRequestId: 700}), MockData.finishedBuildData({buildRequestId: 710})]});728 return MockRemoteAPI.waitForRequest();729 }).then(() => {730 assert.equal(requests.length, 3);731 assertRequestAndResolve(requests[2], 'POST', '/api/v2/forceschedulers/force-some-builder-1');732 assert.deepEqual(MockRemoteAPI.requests[2].data, {'id': '701', 'jsonrpc': '2.0', 'method': 'force', 'params':733 {'wk': '192736', 'os': '10.11 15A284', 'build-request-id': '701', 'forcescheduler': 'force-some-builder-1'}});734 return MockRemoteAPI.waitForRequest();735 }).then(() => {736 assert.equal(requests.length, 4);737 assertRequestAndResolve(requests[3], 'GET', MockData.pendingBuildsUrl('some-builder-1'),738 MockData.pendingBuild({buildRequestId: 701, buildbotBuildRequestId: 17}));739 return MockRemoteAPI.waitForRequest();740 }).then(() => {741 assert.equal(requests.length, 5);742 assertRequestAndResolve(requests[4], 'GET', MockData.recentBuildsUrl('some-builder-1', 2),743 {'builds': [MockData.runningBuildData({buildRequestId: 700}), MockData.finishedBuildData({buildRequestId: 710})]});744 return syncPromise;745 }).then(() => {746 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());747 assertRequestAndResolve(requests[5], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());748 return MockRemoteAPI.waitForRequest();749 }).then(() => {750 assert.equal(requests.length, 7);751 assertRequestAndResolve(requests[6], 'GET', MockData.pendingBuildsUrl('some-builder-1'), {});752 return MockRemoteAPI.waitForRequest();753 }).then(() => {754 assert.equal(requests.length, 8);755 assertRequestAndResolve(requests[7], 'GET', MockData.recentBuildsUrl('some-builder-1', 2),756 {'builds': [MockData.runningBuildData({buildRequestId: 701}), MockData.runningBuildData({buildRequestId: 700})]});757 return MockRemoteAPI.waitForRequest();758 }).then(() => {759 assert.equal(requests.length, 9);760 assertRequestAndResolve(requests[8], 'GET', MockData.pendingBuildsUrl('some-builder-1'), {});761 return MockRemoteAPI.waitForRequest();762 }).then(() => {763 assert.equal(requests.length, 10);764 assertRequestAndResolve(requests[9], 'GET', MockData.recentBuildsUrl('some-builder-1', 2),765 {'builds': [MockData.runningBuildData({buildRequestId: 701}), MockData.runningBuildData({buildRequestId: 700})]});766 return syncPromise;767 });768 });769 it('should recover from missing failed build request', () => {770 const db = TestServer.database();771 let syncPromise;772 return MockData.addMockData(db, ['failed', 'pending', 'pending', 'pending']).then(() => {773 return Manifest.fetch();774 }).then(() => {775 const config = MockData.mockTestSyncConfigWithSingleBuilder();776 const logger = new MockLogger;777 const slaveInfo = {name: 'sync-slave', password: 'password'};778 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);779 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());780 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());781 MockRemoteAPI.reset();782 return MockRemoteAPI.waitForRequest();783 }).then(() => {784 assert.equal(MockRemoteAPI.requests.length, 1);785 assert.equal(MockRemoteAPI.requests[0].method, 'GET');786 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));787 MockRemoteAPI.requests[0].resolve({});788 return MockRemoteAPI.waitForRequest();789 }).then(() => {790 assert.equal(MockRemoteAPI.requests.length, 2);791 assert.equal(MockRemoteAPI.requests[1].method, 'GET');792 assert.equal(MockRemoteAPI.requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));793 MockRemoteAPI.requests[1].resolve({});794 return MockRemoteAPI.waitForRequest();795 }).then(() => {796 assert.equal(MockRemoteAPI.requests.length, 3);797 assert.equal(MockRemoteAPI.requests[2].method, 'POST');798 assert.equal(MockRemoteAPI.requests[2].url, '/api/v2/forceschedulers/force-some-builder-1');799 assert.deepEqual(MockRemoteAPI.requests[2].data, {'id': '701', 'jsonrpc': '2.0', 'method': 'force', 'params':800 {'wk': '192736', 'os': '10.11 15A284', 'build-request-id': '701', 'forcescheduler': 'force-some-builder-1'}});801 MockRemoteAPI.requests[2].resolve('OK');802 return MockRemoteAPI.waitForRequest();803 }).then(() => {804 assert.equal(MockRemoteAPI.requests.length, 4);805 assert.equal(MockRemoteAPI.requests[3].method, 'GET');806 assert.equal(MockRemoteAPI.requests[3].url, MockData.pendingBuildsUrl('some-builder-1'));807 MockRemoteAPI.requests[3].resolve(MockData.pendingBuild({buildRequestId: 701, buildbotBuildRequestId: 17}));808 return MockRemoteAPI.waitForRequest();809 }).then(() => {810 assert.equal(MockRemoteAPI.requests.length, 5);811 assert.equal(MockRemoteAPI.requests[4].method, 'GET');812 assert.equal(MockRemoteAPI.requests[4].url, MockData.recentBuildsUrl('some-builder-1', 2));813 MockRemoteAPI.requests[4].resolve({});814 return syncPromise;815 }).then(() => {816 assert.equal(BuildRequest.all().length, 4);817 assert.equal(BuildRequest.findById(700).status(), 'failed');818 assert.equal(BuildRequest.findById(700).statusUrl(), null);819 assert.equal(BuildRequest.findById(701).status(), 'pending');820 assert.equal(BuildRequest.findById(701).statusUrl(), null);821 assert.equal(BuildRequest.findById(702).status(), 'pending');822 assert.equal(BuildRequest.findById(702).statusUrl(), null);823 assert.equal(BuildRequest.findById(703).status(), 'pending');824 assert.equal(BuildRequest.findById(703).statusUrl(), null);825 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);826 }).then(() => {827 assert.equal(BuildRequest.all().length, 4);828 assert.equal(BuildRequest.findById(700).status(), 'failed');829 assert.equal(BuildRequest.findById(700).statusUrl(), null);830 assert.equal(BuildRequest.findById(701).status(), 'scheduled');831 assert.equal(BuildRequest.findById(701).statusUrl(), 'http://build.webkit.org/#/buildrequests/17');832 assert.equal(BuildRequest.findById(702).status(), 'pending');833 assert.equal(BuildRequest.findById(702).statusUrl(), null);834 assert.equal(BuildRequest.findById(703).status(), 'pending');835 assert.equal(BuildRequest.findById(703).statusUrl(), null);836 });837 });838 it('should update the status of a supposedly scheduled build that went missing', () => {839 const db = TestServer.database();840 let syncPromise;841 return MockData.addMockData(db, ['scheduled', 'pending', 'pending', 'pending']).then(() => {842 return Manifest.fetch();843 }).then(() => {844 const config = MockData.mockTestSyncConfigWithSingleBuilder();845 const logger = new MockLogger;846 const slaveInfo = {name: 'sync-slave', password: 'password'};847 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);848 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());849 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());850 MockRemoteAPI.reset();851 return MockRemoteAPI.waitForRequest();852 }).then(() => {853 assert.equal(MockRemoteAPI.requests.length, 1);854 assert.equal(MockRemoteAPI.requests[0].method, 'GET');855 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));856 MockRemoteAPI.requests[0].resolve({});857 return MockRemoteAPI.waitForRequest();858 }).then(() => {859 assert.equal(MockRemoteAPI.requests.length, 2);860 assert.equal(MockRemoteAPI.requests[1].method, 'GET');861 assert.equal(MockRemoteAPI.requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));862 MockRemoteAPI.requests[1].resolve({});863 return MockRemoteAPI.waitForRequest();864 }).then(() => {865 assert.equal(MockRemoteAPI.requests.length, 3);866 assert.equal(MockRemoteAPI.requests[2].method, 'GET');867 assert.equal(MockRemoteAPI.requests[2].url, MockData.pendingBuildsUrl('some-builder-1'));868 MockRemoteAPI.requests[2].resolve({});869 return MockRemoteAPI.waitForRequest();870 }).then(() => {871 assert.equal(MockRemoteAPI.requests.length, 4);872 assert.equal(MockRemoteAPI.requests[3].method, 'GET');873 assert.equal(MockRemoteAPI.requests[3].url, MockData.recentBuildsUrl('some-builder-1', 2));874 MockRemoteAPI.requests[3].resolve({});875 return syncPromise;876 }).then(() => {877 assert.equal(BuildRequest.all().length, 4);878 assert.equal(BuildRequest.findById(700).status(), 'scheduled');879 assert.equal(BuildRequest.findById(701).status(), 'pending');880 assert.equal(BuildRequest.findById(702).status(), 'pending');881 assert.equal(BuildRequest.findById(703).status(), 'pending');882 return BuildRequest.fetchForTriggerable(MockData.mockTestSyncConfigWithTwoBuilders().triggerableName);883 }).then(() => {884 assert.equal(BuildRequest.all().length, 4);885 assert.equal(BuildRequest.findById(700).status(), 'failed');886 assert.equal(BuildRequest.findById(701).status(), 'pending');887 assert.equal(BuildRequest.findById(702).status(), 'pending');888 assert.equal(BuildRequest.findById(703).status(), 'pending');889 });890 });891 it('should schedule a build request of an user created test group before ones created by automatic change detection', () => {892 const db = TestServer.database();893 let syncPromise;894 return Promise.all([895 MockData.addMockData(db, ['pending', 'pending', 'pending', 'pending']),896 MockData.addAnotherMockTestGroup(db, ['pending', 'pending', 'pending', 'pending'], 'rniwa'),897 ]).then(() => {898 return Manifest.fetch();899 }).then(() => {900 const config = MockData.mockTestSyncConfigWithSingleBuilder();901 const logger = new MockLogger;902 const slaveInfo = {name: 'sync-slave', password: 'password'};903 const triggerable = new BuildbotTriggerable(config, TestServer.remoteAPI(), MockRemoteAPI, slaveInfo, logger);904 syncPromise = triggerable.initSyncers().then(() => triggerable.syncOnce());905 assertRequestAndResolve(MockRemoteAPI.requests[0], 'GET', MockData.buildbotBuildersURL(), MockData.mockBuildbotBuilders());906 MockRemoteAPI.reset();907 return MockRemoteAPI.waitForRequest();908 }).then(() => {909 assert.equal(MockRemoteAPI.requests.length, 1);910 assert.equal(MockRemoteAPI.requests[0].method, 'GET');911 assert.equal(MockRemoteAPI.requests[0].url, MockData.pendingBuildsUrl('some-builder-1'));912 MockRemoteAPI.requests[0].resolve({});913 return MockRemoteAPI.waitForRequest();914 }).then(() => {915 assert.equal(MockRemoteAPI.requests.length, 2);916 assert.equal(MockRemoteAPI.requests[1].method, 'GET');917 assert.equal(MockRemoteAPI.requests[1].url, MockData.recentBuildsUrl('some-builder-1', 2));918 MockRemoteAPI.requests[1].resolve({});919 return MockRemoteAPI.waitForRequest();920 }).then(() => {921 assert.equal(MockRemoteAPI.requests.length, 3);922 assert.equal(MockRemoteAPI.requests[2].method, 'POST');923 assert.equal(MockRemoteAPI.requests[2].url, '/api/v2/forceschedulers/force-some-builder-1');924 assert.deepEqual(MockRemoteAPI.requests[2].data, {'id': '710', 'jsonrpc': '2.0', 'method': 'force', 'params':925 {'wk': '191622', 'os': '10.11 15A284', 'build-request-id': '710', 'forcescheduler': 'force-some-builder-1'}});926 MockRemoteAPI.requests[2].resolve('OK');927 });928 });929 });930 describe('updateTriggerables', () => {931 function refetchManifest()932 {933 MockData.resetV3Models();...
privileged-api-tests.js
Source:privileged-api-tests.js
...53 requests[0].resolve({54 token: 'abc',55 expiration: Date.now() + 100 * 1000,56 });57 return MockRemoteAPI.waitForRequest().then(() => {58 assert.equal(requests.length, 2);59 assert.equal(requests[1].url, '/privileged-api/test');60 });61 });62 it('should not generate a new token if the existing token had not been expired', () => {63 PrivilegedAPI.sendRequest('test', {});64 assert.equal(requests.length, 1);65 assert.equal(requests[0].url, '/privileged-api/generate-csrf-token');66 requests[0].resolve({67 token: 'abc',68 expiration: Date.now() + 3600 * 1000,69 });70 return MockRemoteAPI.waitForRequest().then(() => {71 assert.equal(requests.length, 2);72 assert.equal(requests[1].url, '/privileged-api/test');73 PrivilegedAPI.sendRequest('test2', {});74 return MockRemoteAPI.waitForRequest();75 }).then(() => {76 assert.equal(requests.length, 3);77 assert.equal(requests[2].url, '/privileged-api/test2');78 });79 });80 it('should reject immediately when a token generation had failed', () => {81 const request = PrivilegedAPI.sendRequest('test', {});82 let caught = false;83 request.catch(() => { caught = true; });84 assert.equal(requests.length, 1);85 assert.equal(requests[0].url, '/privileged-api/generate-csrf-token');86 requests[0].reject({status: 'FailedToGenerateToken'});87 return new Promise((resolve) => setTimeout(resolve, 0)).then(() => {88 assert.equal(requests.length, 1);89 assert(caught);90 });91 });92 it('should re-generate token when it had become invalid', () => {93 PrivilegedAPI.sendRequest('test', {});94 assert.equal(requests.length, 1);95 assert.equal(requests[0].url, '/privileged-api/generate-csrf-token');96 requests[0].resolve({97 token: 'abc',98 expiration: Date.now() + 3600 * 1000,99 });100 return MockRemoteAPI.waitForRequest().then(() => {101 assert.equal(requests.length, 2);102 assert.equal(requests[1].data.token, 'abc');103 assert.equal(requests[1].url, '/privileged-api/test');104 requests[1].reject('InvalidToken');105 return MockRemoteAPI.waitForRequest();106 }).then(() => {107 assert.equal(requests.length, 3);108 assert.equal(requests[2].url, '/privileged-api/generate-csrf-token');109 requests[2].resolve({110 token: 'def',111 expiration: Date.now() + 3600 * 1000,112 });113 return MockRemoteAPI.waitForRequest();114 }).then(() => {115 assert.equal(requests.length, 4);116 assert.equal(requests[3].data.token, 'def');117 assert.equal(requests[3].url, '/privileged-api/test');118 });119 });120 it('should not re-generate token when the re-fetched token was invalid', () => {121 const request = PrivilegedAPI.sendRequest('test', {});122 let caught = false;123 request.catch(() => caught = true);124 assert.equal(requests.length, 1);125 assert.equal(requests[0].url, '/privileged-api/generate-csrf-token');126 requests[0].resolve({127 token: 'abc',128 expiration: Date.now() + 3600 * 1000,129 });130 return MockRemoteAPI.waitForRequest().then(() => {131 assert.equal(requests.length, 2);132 assert.equal(requests[1].data.token, 'abc');133 assert.equal(requests[1].url, '/privileged-api/test');134 requests[1].reject('InvalidToken');135 return MockRemoteAPI.waitForRequest();136 }).then(() => {137 assert.equal(requests.length, 3);138 assert.equal(requests[2].url, '/privileged-api/generate-csrf-token');139 requests[2].resolve({140 token: 'def',141 expiration: Date.now() + 3600 * 1000,142 });143 return MockRemoteAPI.waitForRequest();144 }).then(() => {145 assert.equal(requests.length, 4);146 assert.equal(requests[3].data.token, 'def');147 assert.equal(requests[3].url, '/privileged-api/test');148 requests[3].reject('InvalidToken');149 return new Promise((resolve) => setTimeout(resolve, 0));150 }).then(() => {151 assert(caught);152 assert.equal(requests.length, 4);153 });154 });155 });156});157describe('NodePrivilegedAPI', () => {...
install_ps.js
Source:install_ps.js
...77}78const interceptReq = async (browser, page) => {79// console.log('je suis ici')80 let date_debut =new Date()81 const step1 = await page.waitForRequest(request => request.url().toString().startsWith(URL+ '/index.php?populateDatabase=true') && !(request.failure()), { timeout: 300000});82 console.log('step1 populateDatabase')83 const step2 = await page.waitForRequest(request => request.url().toString().startsWith(URL+ '/index.php?configureShop=true') && !(request.failure()), { timeout: 300000});84 console.log('step2 configureShop')85 const step3 = await page.waitForRequest(request => request.url().toString().startsWith(URL+ '/index.php?installFixtures=true') && !(request.failure()), { timeout: 300000});86 console.log('step3 installFixtures')87 const step4 = await page.waitForRequest(request => request.url().toString().startsWith(URL+ '/index.php?installModules=true') && !(request.failure()), { timeout: 300000});88 console.log('step4 installModules')89 const step5 = await page.waitForRequest(request => request.url().toString().startsWith(URL+ '/index.php?installModulesAddons=true') && !(request.failure()), { timeout: 300000});90 console.log('step5 installModulesAddons')91 const finalRequest = await page.waitForRequest(request => request.url().toString().startsWith(URL+ '/index.php?installTheme=true') && !(request.failure()), { timeout: 3000000});92// const finalRequest = await page.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET');93 let date_fin =new Date()94 console.log('----shop successfully created in : ' + ((date_fin.getTime() - date_debut.getTime())/1000) + ' sec')95// console.log('----shop successfully created in : ' + ((date_fin.getTime() - date_debut.getTime())/60000) + ' min')96 return finalRequest.url();97}98const run = async () => {99 const browser = await puppeteer.launch({ headless: false })100 const page = await browser.newPage()101 const populateInstall = await populatePS(browser, page)102 const interceptRequest = await interceptReq(browser, page)103 browser.close()104}105run()106 .then(value => {...
organiser.js
Source:organiser.js
1'use strict'2const Telegram = require('telegram-node-bot');3var fs = require('fs');4var dataObj = JSON.parse(fs.readFileSync('./datastore/data.json', 'utf8'));5class OrganiserController extends Telegram.TelegramBaseController {6 editDetailsHandler($) {7 if ($.message.from.username == dataObj.masterUserName) {8 $.sendMessage('Old Details : \n\n' + dataObj.details + '\n\nEnter the New Details :');9 $.waitForRequest10 .then($ => {11 dataObj.details = $.message.text;12 $.sendMessage(`Details Updated! New Details are : \n\n${dataObj.details}`);13 });14 } else15 $.sendMessage('You are not authorized for this command!');16 }17 editCriteriaHandler($) {18 if ($.message.from.username == dataObj.masterUserName) {19 $.sendMessage('Old Judging Criteria : \n\n' + dataObj.criteria + '\n\nEnter the New Judging Criteria :');20 $.waitForRequest21 .then($ => {22 dataObj.criteria = $.message.text;23 $.sendMessage(`Judging Criteria Updated! New Judging Criteria is : \n\n${dataObj.criteria}`);24 });25 } else26 $.sendMessage('You are not authorized for this command!');27 }28 editScheduleHandler($) {29 if ($.message.from.username == dataObj.masterUserName) {30 $.sendMessage('Old Schedule : \n\n' + dataObj.schedule + '\n\nEnter the New Schedule :');31 $.waitForRequest32 .then($ => {33 dataObj.schedule = $.message.text;34 $.sendMessage(`Schedule Updated! New Schedule is : \n\n${dataObj.schedule}`);35 });36 } else37 $.sendMessage('You are not authorized for this command!');38 }39 editLocationHandler($) {40 if ($.message.from.username == dataObj.masterUserName) {41 $.sendMessage('Enter the New Location\'s Latitude :');42 $.waitForRequest43 .then($ => {44 dataObj.location.latitude = $.message.text;45 $.sendMessage('Enter the New Location\'s Longitude :');46 $.waitForRequest47 .then($ => {48 dataObj.location.longitude = $.message.text;49 $.sendMessage(`Location Updated! New Location is : `);50 $.sendLocation(dataObj.location.latitude, dataObj.location.longitude);51 })52 });53 } else54 $.sendMessage('You are not authorized for this command!');55 }56 allApplicantsHandler($) {57 if ($.message.from.username == dataObj.masterUserName) {58 let applicantsList = 'List of Applicants\n\n';59 dataObj.applicants.forEach((applicant, i) => {60 applicantsList += `${i+1}. ${applicant.name}\n`;61 })62 $.sendMessage(applicantsList);63 }64 else65 $.sendMessage('You are not authorized for this command!');66 }67 announcementHandler($) {68 if ($.message.from.username == dataObj.masterUserName) {69 $.sendMessage("This announcement will be sent to all the applicants :\n\nEnter the announcement :")70 $.waitForRequest71 .then($ => {72 dataObj.announcements.push($.message.text);73 dataObj.applicants.forEach(applicant => {74 $.sendMessage(`ANNOUNCEMENT\n\n${$.message.text}`, {'chat_id': applicant.chatID});75 });76 $.sendMessage(`${$.message.text}\n\nThis announcement has been sent to all the applicants.`);77 });78 }79 else80 $.sendMessage('You are not authorized for this command!');81 }82 get routes() {83 return {84 'editDetailsCommand': 'editDetailsHandler',85 'editCriteriaCommand': 'editCriteriaHandler',86 'editScheduleCommand': 'editScheduleHandler',87 'editLocationCommand': 'editLocationHandler',88 'allApplicantsCommand': 'allApplicantsHandler',89 'announcementCommand': 'announcementHandler',90 };91 }92}...
book.js
Source:book.js
1/**2 * @author Alexi Jamal3 * 4 */5 "use strict";6 const Telegram = require("telegram-node-bot");7 8 class BookController extends Telegram.TelegramBaseController {9 bookHandler($) {10 $.sendMessage("Available services to book:\n1. Home cleaning\n2. Pest control");11 $.sendMessage("Send the number of the service you want to book.");12 $.waitForRequest.then($ => { 13 let service = $.message.text;14 if(isNaN(service)){15 $.sendMessage("Please send a valid number");16 } else {17 if(service == 1){18 $.sendMessage("What time?");19 $.waitForRequest.then($ => {20 let userTime = $.message.text;21 $.sendMessage(`Home cleaning at ${userTime}, what date?`);22 $.waitForRequest.then($ => {23 let userDate = $.message.text;24 $.sendMessage(`Home cleaning at ${userTime} on ${userDate}, got it.`);25 $.sendMessage("Kindly provide us with your phone number");26 $.waitForRequest.then($ => {27 let userPhone = $.message.text;28 $.sendMessage("Awesome! A team member will call to confirm the booking.\nThank you.")29 let textToReturn = `${$.message.from.firstName} booked "home cleaning" on ${userDate} at ${userTime}\nCall ${userPhone} to confirm`30 this._api.sendMessage('379633660', textToReturn)31 })32 })33 })34 }35 if(service == 2){36 $.sendMessage("What time?");37 $.waitForRequest.then($ => {38 let userTime = $.message.text;39 $.sendMessage(`Pest control at ${userTime}, what date?`);40 $.waitForRequest.then($ => {41 let userDate = $.message.text;42 $.sendMessage(`Pest control at ${userTime} on ${userDate}, got it.`);43 $.sendMessage("Kindly provide us with your phone number");44 $.waitForRequest.then($ => {45 let userPhone = $.message.text;46 $.sendMessage("Awesome! A team member will call to confirm the booking.\nThank you.");47 let textToReturn = `${$.message.from.firstName} booked "pest control" on ${userDate} at ${userTime}\nCall ${userPhone} to confirm`48 this._api.sendMessage('379633660', textToReturn)49 })50 })51 })52 }53 }54 })55 }56 57 get routes() {58 return {59 bookCommand: "bookHandler"60 };61 }62 }63 64 module.exports = BookController;...
worker.js
Source:worker.js
...6 DAY = 86400000,7 ONE = 1,8 ZERO = 0,9 DB_VERSION = 1;10function waitForRequest(request) {11 return new Promise((resolve, reject) => {12 request.addEventListener("success", resolve, LISTENER_OPTS);13 request.addEventListener("error", reject, LISTENER_OPTS);14 });15}16function expunge(database) {17 const transaction = database.transaction(STORE, 'readwrite'),18 store = transaction.objectStore(STORE),19 index = store.index('expires'),20 request = index.openCursor(),21 start = new Date(ZERO),22 end = new Date(Date.now() - DAY);23 return new Promise((resolve, reject) => {24 request.addEventListener("success", (event) => {25 const cursor = event.target.result;26 if(cursor) {27 if(cursor.value.expires > start && cursor.value.expires <= end) {28 waitForRequest(cursor.delete()).catch(console.error);29 }30 cursor.continue();31 }32 else {33 resolve();34 postMessage("expunged");35 }36 });37 request.addEventListener("error", reject);38 });39}40function timeout(database) {41 expunge(database).catch(console.error);42 setInterval(() => {43 expunge(database).catch(console.error);44 }, DAY);45}46function getUntilMidnight() {47 const now = new Date(),48 midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + ONE, ZERO, ZERO, ZERO, ZERO);49 return midnight.getTime() - Date.now();50}51const request = indexedDB.open(STORE, DB_VERSION);52waitForRequest(request)53 .then(({ target: { result: database } }) => {54 setTimeout(() => {55 timeout(database);56 }, getUntilMidnight());57 return expunge(database);58 })...
watch.e2e.js
Source:watch.e2e.js
...19 const chat = '.panel-block p'20 const input = 'xpath=(//input)[1]';21 const sendButton = 'xpath=//button[text()="Send"]';22 await Promise.all([23 page.waitForRequest('**/interact'),24 page.waitForResponse('**/interact'),25 page.fill(input, 'Hello!')26 ]);27 await Promise.all([28 page.waitForRequest('**/interact'),29 page.waitForResponse('**/interact'),30 page.click(sendButton)31 ]);32 expect(page).toHaveText(chat, "Tim: 'Hello!'");33 await Promise.all([34 page.waitForRequest('**/interact'),35 page.waitForResponse('**/interact'),36 // We can recycle the selector because the first input is37 // temporarily replaced by a Done at this stage.38 page.fill(input, 'Hi there!')39 ]);40 [request, resp] = await Promise.all([41 page.waitForRequest('**/interact'),42 page.waitForResponse('**/interact'),43 page.click(sendButton)44 ]);45 expect(page).toHaveText(chat, "Tim: 'Hello!'\nNico: 'Hi there!'");46 });...
mdata-worker.js
Source:mdata-worker.js
...13const MDataIndexer = require('./MdataIndexer.js');14async function main(){15 console.info(`Sleeping for ${process.env.BOOTSTRAP_SLEEP_SECS} secs`);16 await sleep(process.env.BOOTSTRAP_SLEEP_SECS*1000);17 waitForRequest();18}19async function waitForRequest() {20 client.brpop(['mdata_org_index', 1], async function (list, items) {21 if (items && items.length === 2) {22 logger.info('Received request to index org ... ');23 await handleMdataIndexRequest(JSON.parse(items[1]));24 setTimeout(waitForRequest, 3000);25 } else {26 logger.info('No active request...');27 setTimeout(waitForRequest, 3000);28 }29 30 });31}32async function handleMdataIndexRequest(authInfo) {33 let sfConn = new SFConnectionUtils();...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await browser.close();6})();7const puppeteer = require('puppeteer');8(async () => {9 const browser = await puppeteer.launch({headless: false});10 const page = await browser.newPage();11 await browser.close();12})();13const puppeteer = require('puppeteer');14(async () => {15 const browser = await puppeteer.launch({headless: false});16 const page = await browser.newPage();17 await page.waitForSelector('input[name="q"]');18 await browser.close();19})();20const puppeteer = require('puppeteer');21(async () => {22 const browser = await puppeteer.launch({headless: false});23 const page = await browser.newPage();24 await browser.close();25})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await browser.close();6})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await browser.close();6})();7const puppeteer = require('puppeteer');8(async () => {9 const browser = await puppeteer.launch();10 const page = await browser.newPage();11 await browser.close();12})();13const puppeteer = require('puppeteer');14(async () => {15 const browser = await puppeteer.launch();16 const page = await browser.newPage();17 await page.waitForSelector('h1');18 await browser.close();19})();20const puppeteer = require('puppeteer');21(async () => {22 const browser = await puppeteer.launch();23 const page = await browser.newPage();24 await browser.close();25})();26const puppeteer = require('puppeteer');27(async () => {28 const browser = await puppeteer.launch();29 const page = await browser.newPage();30 await page.waitForTimeout(1000);31 await browser.close();32})();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!