How to use expectTimeout method in stryker-parent

Best JavaScript code snippet using stryker-parent

test.js

Source:test.js Github

copy

Full Screen

1/*2 * (c) Copyright IBM Corp. 20213 * (c) Copyright Instana Inc. and contributors 20214 */5'use strict';6const { expect } = require('chai');7const path = require('path');8const constants = require('@instana/core').tracing.constants;9const Control = require('../Control');10const config = require('../../../serverless/test/config');11const expectExactlyOneMatching = require('../../../core/test/test_util/expectExactlyOneMatching');12const retry = require('../../../serverless/test/util/retry');13const { fail } = expect;14const functionName = 'functionName';15const unqualifiedArn = `arn:aws:lambda:us-east-2:410797082306:function:${functionName}`;16const version = '$LATEST';17const qualifiedArn = `${unqualifiedArn}:${version}`;18const backendPort = 8443;19const backendBaseUrl = `https://localhost:${backendPort}/serverless`;20const downstreamDummyPort = 3456;21const downstreamDummyUrl = `http://localhost:${downstreamDummyPort}/`;22const instanaAgentKey = 'aws-lambda-dummy-key';23function prelude(opts) {24 const timeout = opts.lambdaTimeout * 2;25 this.timeout(process.env.CI ? config.getTestTimeout() : timeout);26 this.slow(timeout);27 if (opts.startBackend == null) {28 opts.startBackend = true;29 }30 // eslint-disable-next-line prefer-object-spread31 const env = Object.assign(32 {33 INSTANA_ENDPOINT_URL: opts.instanaEndpointUrl,34 INSTANA_AGENT_KEY: opts.instanaAgentKey,35 LAMBDA_TIMEOUT: opts.lambdaTimeout36 },37 opts.env38 );39 const control = new Control({40 faasRuntimePath: path.join(__dirname, '../runtime_mock'),41 handlerDefinitionPath: opts.handlerDefinitionPath,42 startBackend: opts.startBackend,43 backendPort,44 backendBaseUrl,45 downstreamDummyUrl,46 env,47 timeout,48 lambdaTimeout: opts.lambdaTimeout49 });50 control.registerTestHooks();51 return control;52}53describe('timeout heuristic', () => {54 const handlerDefinitionPath = path.join(__dirname, './lambda');55 describe('when the Lambda has a very short timeout and times out', function () {56 // For Lambdas with timeout configured at 1 second or lower, we disable timeout detection.57 runTest.bind(this)({58 lambdaTimeout: 1000,59 delay: 1500,60 expectEntrySpan: false,61 expectTimeout: false,62 expectResponseFromLambda: false63 });64 });65 describe('when the Lambda has a short timeout and times out', function () {66 runTest.bind(this)({67 lambdaTimeout: 3100,68 delay: 3500,69 expectEntrySpan: true,70 expectTimeout: true,71 expectResponseFromLambda: false,72 expectedMillisRemainingAtTimeout: 28073 });74 });75 describe('when the Lambda has a short timeout and finishes just after the timeout detection', function () {76 runTest.bind(this)({77 lambdaTimeout: 3100,78 delay: 2900, // timeout is assumed after ~ 3100 ms * 0.9 ~= 2800 ms79 expectEntrySpan: true,80 expectTimeout: true,81 expectResponseFromLambda: true,82 expectedMillisRemainingAtTimeout: 28083 });84 });85 describe('when the Lambda has a short timeout and finishes before the timeout detection', function () {86 runTest.bind(this)({87 lambdaTimeout: 3100,88 delay: 2000,89 expectEntrySpan: true,90 expectTimeout: false,91 expectResponseFromLambda: true92 });93 });94 describe('when the Lambda has a longer timeout and times out', function () {95 runTest.bind(this)({96 lambdaTimeout: 10000,97 delay: 11000,98 expectEntrySpan: true,99 expectTimeout: true,100 expectResponseFromLambda: false,101 expectedMillisRemainingAtTimeout: 400102 });103 });104 describe('when the Lambda has a longer timeout and finishes just after the timeout detection', function () {105 runTest.bind(this)({106 lambdaTimeout: 10000,107 delay: 9750,108 expectEntrySpan: true,109 expectTimeout: true,110 expectResponseFromLambda: true,111 expectedMillisRemainingAtTimeout: 400112 });113 });114 describe('when the Lambda has a longer timeout and finishes before the timeout detection', function () {115 runTest.bind(this)({116 lambdaTimeout: 10000,117 delay: 8000,118 expectEntrySpan: true,119 expectTimeout: false,120 expectResponseFromLambda: true121 });122 });123 describe('when the timeout detection is disabled and a timeout occurs', function () {124 runTest.bind(this)({125 lambdaTimeout: 3100,126 delay: 3500,127 expectEntrySpan: false,128 expectTimeout: true,129 expectResponseFromLambda: false,130 disableLambdaTimeoutDetection: true131 });132 });133 describe('when the timeout detection env is set but its set to false', function () {134 runTest.bind(this)({135 lambdaTimeout: 3100,136 delay: 3500,137 expectEntrySpan: true,138 expectTimeout: true,139 expectResponseFromLambda: false,140 disableLambdaTimeoutDetection: false,141 expectedMillisRemainingAtTimeout: 300142 });143 });144 function runTest({145 lambdaTimeout,146 delay,147 expectEntrySpan,148 expectTimeout,149 expectResponseFromLambda,150 expectedMillisRemainingAtTimeout,151 disableLambdaTimeoutDetection152 }) {153 const envs = {154 DELAY: delay155 };156 if (disableLambdaTimeoutDetection !== undefined) {157 envs.INSTANA_DISABLE_LAMBDA_TIMEOUT_DETECTION = disableLambdaTimeoutDetection;158 }159 const opts = {160 handlerDefinitionPath,161 instanaEndpointUrl: backendBaseUrl,162 instanaAgentKey,163 lambdaTimeout,164 env: envs165 };166 const control = prelude.bind(this)(opts);167 let label;168 if (expectTimeout && !expectResponseFromLambda) {169 label = 'must detect the timeout';170 } else if (expectTimeout) {171 label = "must a assume timeout but not impact the handler's response";172 } else {173 label = 'must not detect a timeout';174 }175 it(label, () => {176 const lambdaFinishedUnexpectedlyMessage = 'The Lambda was expected to time out but it actually finished.';177 return control178 .runHandler()179 .then(() => {180 if (expectResponseFromLambda) {181 if (control.getLambdaErrors() && control.getLambdaErrors().length > 0) {182 // eslint-disable-next-line no-console183 console.log('Unexpected Errors:');184 // eslint-disable-next-line no-console185 console.log(JSON.stringify(control.getLambdaErrors()));186 }187 expect(control.getLambdaErrors()).to.be.empty;188 expect(control.getLambdaResults().length).to.equal(1);189 const result = control.getLambdaResults()[0];190 expect(result).to.exist;191 expect(result.body).to.deep.equal({ message: 'Stan says hi!' });192 } else {193 fail(lambdaFinishedUnexpectedlyMessage);194 }195 })196 .catch(e => {197 if (e.name === 'AssertionError' && e.message === lambdaFinishedUnexpectedlyMessage) {198 throw e;199 }200 expect(e.message).to.include('but it ran only 0 time(s).');201 })202 .finally(async () => {203 await retry(async () => {204 const spans = await control.getSpans();205 if (expectEntrySpan) {206 verifyLambdaEntry(207 spans,208 expectTimeout,209 expectedMillisRemainingAtTimeout - 100,210 expectedMillisRemainingAtTimeout + 100211 );212 }213 });214 });215 });216 }217 function verifyLambdaEntry(spans, expectTimeout, minRemaining, maxRemaining) {218 let expectations = [219 span => expect(span.t).to.exist,220 span => expect(span.p).to.not.exist,221 span => expect(span.s).to.exist,222 span => expect(span.n).to.equal('aws.lambda.entry'),223 span => expect(span.k).to.equal(constants.ENTRY),224 span => expect(span.f).to.be.an('object'),225 span => expect(span.f.hl).to.be.true,226 span => expect(span.f.cp).to.equal('aws'),227 span => expect(span.f.e).to.equal(qualifiedArn),228 span => expect(span.data.lambda).to.be.an('object'),229 span => expect(span.data.lambda.runtime).to.equal('nodejs')230 ];231 if (expectTimeout) {232 expectations = expectations.concat([233 span => expect(span.data.lambda.msleft).to.be.at.least(minRemaining),234 span => expect(span.data.lambda.msleft).to.be.at.most(maxRemaining),235 span => expect(span.ec).to.equal(1),236 span => {237 const regex = /Possible Lambda timeout with only (\d+) ms left./;238 expect(span.data.lambda.error).to.match(regex);239 const digitsFromErrorMessage = regex.exec(span.data.lambda.error)[1];240 const remainingMillisFromErrorMessage = parseInt(digitsFromErrorMessage, 10);241 expect(remainingMillisFromErrorMessage).to.equal(span.data.lambda.msleft);242 }243 ]);244 } else {245 expectations = expectations.concat([246 span => expect(span.data.lambda.msleft).to.not.exist,247 span => expect(span.ec).to.equal(0),248 span => expect(span.data.lambda.error).to.not.exist249 ]);250 }251 return expectExactlyOneMatching(spans, expectations);252 }...

Full Screen

Full Screen

sun-phase.spec.ts

Source:sun-phase.spec.ts Github

copy

Full Screen

1import { SunPhases } from "@/store/sun-phase";2import { jest } from "@jest/globals";3jest.useFakeTimers();4afterEach(jest.clearAllTimers);5function expectTimeout(time: number) {6 expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), time);7 jest.runOnlyPendingTimers();8}9it("should fail on empty points", () => {10 expect(() => new SunPhases({})).toThrow();11});12describe("ofTime", () => {13 const data = new SunPhases({ one: 0, two: 12 });14 it("should return correct phase", () => {15 expect(data.ofTime(new Date("2019-01-01T00:00:00"))).toBe("one");16 expect(data.ofTime(new Date("2019-01-01T12:00:00"))).toBe("two");17 });18});19describe("nextOf", () => {20 const data = new SunPhases({ one: 0, two: 12 });21 it("should return next phase", () => {22 expect(data.nextOf("one")).toBe("two");23 expect(data.nextOf("two")).toBe("one");24 });25 it("should throws on unknown name", () => {26 expect(() => data.nextOf("zero")).toThrow();27 });28 it("should work with single phase", () => {29 const data = new SunPhases({ one: 0 });30 expect(data.nextOf("one")).toBe("one");31 });32});33describe("observe", () => {34 it("should push phases", () => {35 const data = new SunPhases({36 first: 5,37 second: 10,38 third: 20,39 });40 const time = new Date("2019-01-13T02:20:25");41 const results: string[] = [];42 data.observe(time).subscribe(name => results.push(name));43 expectTimeout(9575000);44 expectTimeout(3600000 * 5);45 expectTimeout(3600000 * 10);46 expectTimeout(3600000 * 9);47 jest.clearAllTimers();48 expect(results).toStrictEqual(["third", "first", "second", "third", "first"]);49 });50 it("should work with single phase", () => {51 const results: string[] = [];52 new SunPhases({ first: 19 })53 .observe()54 .subscribe(name => results.push(name));55 jest.runOnlyPendingTimers();56 expectTimeout(86400 * 1000);57 expect(results).toStrictEqual(["first", "first", "first"]);58 });59 it("should work on edge case", () => {60 const data = new SunPhases({61 first: 0,62 second: 23,63 });64 const time = new Date("2019-01-13T00:00:00");65 const results: string[] = [];66 data.observe(time).subscribe(name => results.push(name));67 expectTimeout(3600000 * 23);68 expectTimeout(3600000);69 expect(results).toStrictEqual(["first", "second", "first"]);70 });...

Full Screen

Full Screen

timers.js

Source:timers.js Github

copy

Full Screen

...16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,17 * Boston, MA 02110-1301 USA18 */19import { Timer } from '../src/index.js';20function expectTimeout(t, cb) {21 return new Promise((resolve, reject) => {22 const now = performance.now();23 cb(() => {24 if (Math.abs(performance.now - now - t) > 5)25 reject(new Error('Bad Timeout'));26 resolve();27 });28 });29}30describe('Timers', () => {31 it('restart() with increasing time', () => {32 return expectTimeout(40, (cb) => {33 const t = new Timer(cb);34 t.restart(10);35 t.restart(20);36 t.restart(30);37 t.restart(40);38 });39 });40 it('restart() with decreasing time', () => {41 return expectTimeout(40, (cb) => {42 const t = new Timer(cb);43 t.restart(100);44 t.restart(80);45 t.restart(60);46 t.restart(40);47 });48 });49 it('restart() with both', () => {50 return expectTimeout(40, (cb) => {51 const t = new Timer(cb);52 t.restart(10);53 t.restart(20);54 t.restart(30);55 t.restart(40);56 t.restart(100);57 t.restart(80);58 t.restart(60);59 t.restart(40);60 });61 });62 it('stop()', (done) => {63 const t = new Timer(done);64 t.restart(40);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectTimeout = require('stryker-parent').expectTimeout;2expectTimeout(1000);3const expectTimeout = require('stryker-parent').expectTimeout;4expectTimeout(1000);5const expectTimeout = require('stryker-parent').expectTimeout;6expectTimeout(1000);7const expectTimeout = require('stryker-parent').expectTimeout;8expectTimeout(1000);9const expectTimeout = require('stryker-parent').expectTimeout;10expectTimeout(1000);11const expectTimeout = require('stryker-parent').expectTimeout;12expectTimeout(1000);13const expectTimeout = require('stryker-parent').expectTimeout;14expectTimeout(1000);15const expectTimeout = require('stryker-parent').expectTimeout;16expectTimeout(1000);17const expectTimeout = require('stryker-parent').expectTimeout;18expectTimeout(1000);19const expectTimeout = require('stryker-parent').expectTimeout;20expectTimeout(1000);21const expectTimeout = require('stryker-parent').expectTimeout;22expectTimeout(1000);23const expectTimeout = require('stryker-parent').expectTimeout;24expectTimeout(1000);25const expectTimeout = require('stryker-parent').expectTimeout;26expectTimeout(1000);27const expectTimeout = require('stryker-parent').expect

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectTimeout = require('stryker-parent').expectTimeout;2expectTimeout(5000);3const expectTimeout = require('stryker-child').expectTimeout;4expectTimeout(5000);5module.exports = {6 expectTimeout: require('stryker-parent').expectTimeout7};8module.exports = {9 expectTimeout: require('stryker-child').expectTimeout10};11module.exports = {12 mochaOptions: {13 }14};15{16 "dependencies": {17 }18}19const expectTimeout = require('stryker-parent').expectTimeout;20expectTimeout(5000);21const expectTimeout = require('stryker-child').expectTimeout;22expectTimeout(5000);23module.exports = {24 expectTimeout: require('stryker-parent').expectTimeout25};26module.exports = {27 expectTimeout: require('stryker-child').expectTimeout28};29module.exports = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectTimeout = require('stryker-parent').expectTimeout;2describe('test', () => {3 it('should timeout', () => {4 expectTimeout(1000);5 return new Promise((resolve) => {6 setTimeout(resolve, 2000);7 });8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var expectTimeout = require('stryker-parent/expectTimeout');2var expectTimeout = require('stryker-parent/expectTimeout');3var expectTimeout = require('stryker-parent/expectTimeout');4var expectTimeout = require('stryker-parent/expectTimeout');5var expectTimeout = require('stryker-parent/expectTimeout');6var expectTimeout = require('stryker-parent/expectTimeout');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { expectTimeout } = require('stryker-parent');2const { expectTimeout } = require('stryker-parent');3const { expectTimeout } = require('stryker-parent');4const { expectTimeout } = require('stryker-parent');5const { expectTimeout } = require('stryker-parent');6const { expectTimeout } = require('stryker-parent');7const { expectTimeout } = require('stryker-parent');8const { expectTimeout } = require('stryker-parent');9const { expectTimeout } = require('stryker-parent');10const { expectTimeout } = require('stryker-parent');11const { expectTimeout } = require('stryker-parent');12const { expectTimeout } = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

1var expectTimeout = require('stryker-parent').expectTimeout;2var expectTimeout = require('stryker-parent').expectTimeout;3var expectTimeout = require('stryker-parent').expectTimeout;4var expectTimeout = require('stryker-parent').expectTimeout;5var expectTimeout = require('stryker-parent').expectTimeout;6var expectTimeout = require('stryker-parent').expectTimeout;7var expectTimeout = require('stryker-parent').expectTimeout;8var expectTimeout = require('stryker-parent').expectTimeout;9var expectTimeout = require('stryker-parent').expectTimeout;10var expectTimeout = require('stryker-parent').expectTimeout;11var expectTimeout = require('stryker-parent').expectTimeout;12var expectTimeout = require('stryker-parent').expectTimeout;

Full Screen

Using AI Code Generation

copy

Full Screen

1var expectTimeout = require('stryker-parent').expectTimeout;2expectTimeout();3module.exports = function(config) {4 config.set({5 });6};7module.exports = function(config) {8 config.set({9 mochaOptions: {10 }11 });12};13module.exports = function(config) {14 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1const { expectTimeout } = require('stryker-parent');2expectTimeout(1000);3describe('A suite', () => {4 it('should fail', () => {5 expect(true).toBe(false);6 });7});8Stryker 3.0.0 (node 10.15.1) mutated 1 file (2 mutants) and got 1/2 tests passing (50% survived) Ran all tests for this mutant. (0 survived, 0 timed out) Ran all tests for this mutant. (0 survived, 1 timed out) [2019-06-21 10:39:18.901] [INFO] InitialTestExecutor - Starting initial test run. This may take a while. [2019-06-21 10:39:18.902] [INFO] InitialTestExecutor - Initial test run succeeded. Ran 1 tests in 1 second (net 1 ms, overhead 1000 ms). [2019-06-21 10:39:18.903] [INFO] SandboxPool - Creating 1 test runners (based on CPU count) [2019-06-21 10:39:18.903] [INFO] Stryker - 1 Mutant(s) generated [2019-06-21 10:39:18.903] [INFO] Stryker - 0 Mutant(s) ignored [2019-06-21 10:39:18.903] [INFO] Stryker - 1 Mutant(s) left [2019-06-21 10:39:18.903] [INFO] SandboxPool - Creating 1 test runners (based on CPU count) [2019-06-21 10:39:18.904] [INFO] SandboxPool - Starting test runner child process

Full Screen

Using AI Code Generation

copy

Full Screen

1const expectTimeout = require('stryker-parent').expectTimeout;2describe('A test', () => {3 it('should not take too long', () => {4 return somePromise();5 });6});

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 stryker-parent 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