Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅[karma cbt] add retry for UnhandledException #194

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ unit-cbt:
image: $CI_IMAGE
script:
- yarn
- ./ci-cbt.sh test:unit
- ./scripts/ci-cbt.sh test:unit

e2e-cbt:
except:
Expand All @@ -93,7 +93,7 @@ e2e-cbt:
image: $CI_IMAGE
script:
- yarn
- ./ci-cbt.sh test:e2e
- ./scripts/ci-cbt.sh test:e2e

deploy-staging:
only:
Expand All @@ -105,9 +105,9 @@ deploy-staging:
script:
- yarn
- TARGET_DATACENTER=eu TARGET_ENV=staging VERSION=staging yarn build:bundle
- ./deploy.sh staging eu
- ./scripts/deploy.sh staging eu
- TARGET_DATACENTER=us TARGET_ENV=staging VERSION=staging yarn build:bundle
- ./deploy.sh staging us
- ./scripts/deploy.sh staging us

deploy-release:
only:
Expand All @@ -121,9 +121,9 @@ deploy-release:
script:
- yarn
- TARGET_DATACENTER=eu TARGET_ENV=production VERSION=release yarn build:bundle
- ./deploy.sh prod eu
- ./scripts/deploy.sh prod eu
- TARGET_DATACENTER=us TARGET_ENV=production VERSION=release yarn build:bundle
- ./deploy.sh prod us
- ./scripts/deploy.sh prod us

########################################################################################################################
# Notify
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dev": "ENV=development node test/server/server.js",
"test": "yarn test:unit",
"test:unit": "karma start ./test/unit/karma.local.conf.js",
"test:unit:cbt": "karma start ./test/unit/karma.cbt.conf.js",
"test:unit:cbt": "node ./scripts/karma-cbt-with-retry.js",
"test:e2e": "yarn run test:e2e:bundle",
"test:e2e:bundle": "TARGET_ENV=e2e-test yarn build && E2E_MODE=bundle wdio test/e2e/wdio.local.conf.js",
"test:e2e:npm": "TARGET_ENV=e2e-test yarn build && (cd test/app && rm -rf node_modules && yarn) && E2E_MODE=npm wdio test/e2e/wdio.local.conf.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:bundle": "rm -rf bundle && webpack --config webpack.config.js --mode=production && yarn replace-build-env bundle",
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
"replace-build-env": "node ../../replace-build-env.js"
"replace-build-env": "node ../../scripts/replace-build-env.js"
},
"dependencies": {
"@browser-sdk/core": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:bundle": "rm -rf bundle && webpack --config webpack.config.js --mode=production && yarn replace-build-env bundle",
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json && yarn replace-build-env cjs",
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json && yarn replace-build-env esm",
"replace-build-env": "node ../../replace-build-env.js"
"replace-build-env": "node ../../scripts/replace-build-env.js"
},
"dependencies": {
"@browser-sdk/core": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion build-env.js → scripts/build-env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const execSync = require('child_process').execSync
const lernaJson = require('./lerna.json')
const lernaJson = require('../lerna.json')

let version
switch (process.env.VERSION) {
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions scripts/karma-cbt-with-retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

const path = require('path')
const exec = require('child_process').exec

const rootDirectory = path.join(__dirname, '..')
const COMMAND = `${rootDirectory}/node_modules/.bin/karma start ${rootDirectory}/test/unit/karma.cbt.conf.js`
const MAX_RETRY_COUNT = 3
let retryCount = 0

function executeWithRetry() {
let logs = ''
const current = exec(COMMAND)
current.stdout.pipe(process.stdout)
current.stdout.on('data', (data) => (logs += data))
current.on('exit', (code) => {
if (code !== 0 && isRetryAllowed(logs)) {
if (retryCount < MAX_RETRY_COUNT) {
retryCount += 1
console.log(`\n${COMMAND} (Retry ${retryCount}/${MAX_RETRY_COUNT})\n\n`)
executeWithRetry()
}
} else {
process.exit(code)
}
})
}

function isRetryAllowed(logs) {
return logs.indexOf('UnhandledRejection') !== -1
}

executeWithRetry()
File renamed without changes.
2 changes: 1 addition & 1 deletion test/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const webpack = require('webpack')
const logsConfig = require('../../packages/logs/webpack.config')
const rumConfig = require('../../packages/rum/webpack.config')
const fakeBackend = require('./fake-backend')
const buildEnv = require('.././../build-env')
const buildEnv = require('../../scripts/build-env')

let port = 3000
const app = express()
Expand Down