Skip to content

Commit

Permalink
ci(jenkins): support windows (elastic#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Mar 4, 2020
1 parent c33d4f8 commit f955a86
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 129 deletions.
28 changes: 0 additions & 28 deletions .appveyor.yml

This file was deleted.

88 changes: 67 additions & 21 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ pipeline {
script {
def node = readYaml(file: '.ci/.jenkins_nodejs.yml')
def parallelTasks = [:]
def parallelTasksWithoutAsyncHooks = [:]
node['NODEJS_VERSION'].each{ version ->
parallelTasks["Node.js-${version}"] = generateStep(version: version)
if (!version.startsWith('6')) {
parallelTasks["Node.js-${version}-async-hooks-false"] = generateStep(version: version, disableAsyncHooks: true)
}
// TODO: to be enabled if required.
// parallelTasks["Windows-Node.js-${version}"] = generateStepForWindows(version: version)
}

// Only 12 for the time being
parallelTasks["Windows-Node.js-12"] = generateStepForWindows(version: '12')

// PRs don't require to run here as it's now managed within the linting pipeline
if (!env.CHANGE_ID) {
// Linting in parallel with the test stage
Expand Down Expand Up @@ -330,28 +334,26 @@ def generateStep(Map params = [:]){
def edge = params.containsKey('edge') ? params.edge : false
def disableAsyncHooks = params.get('disableAsyncHooks', false)
return {
node('docker && linux && immutable'){
try {
env.HOME = "${WORKSPACE}"
if (disableAsyncHooks) {
env.ELASTIC_APM_ASYNC_HOOKS = 'false'
}
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
retry(2){
sleep randomNumber(min:10, max: 30)
sh(label: "Run Tests", script: """.ci/scripts/test.sh "${version}" "${tav}" "${edge}" """)
node('linux && immutable'){
withEnv(["VERSION=${version}", "ELASTIC_APM_ASYNC_HOOKS=${disableAsyncHooks}"]) {
try {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
retry(2){
sleep randomNumber(min:5, max: 10)
sh(label: "Run Tests", script: """.ci/scripts/test.sh "${version}" "${tav}" "${edge}" """)
}
}
} catch(e){
error(e.toString())
} finally {
docker.image('node:12').inside("-v ${WORKSPACE}/${BASE_DIR}:/app"){
sh(label: "Convert Test results to JUnit format", script: 'cd /app && .ci/scripts/convert_tap_to_junit.sh')
}
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/junit-*.xml")
codecov(repo: env.REPO, basedir: "${BASE_DIR}", secret: "${CODECOV_SECRET}")
}
} catch(e){
error(e.toString())
} finally {
docker.image('node:12').inside("-v ${WORKSPACE}/${BASE_DIR}:/app"){
sh(label: "Convert Test results to JUnit format", script: 'cd /app && .ci/scripts/convert_tap_to_junit.sh')
}
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/junit-*.xml")
codecov(repo: env.REPO, basedir: "${BASE_DIR}", secret: "${CODECOV_SECRET}")
}
}
}
Expand Down Expand Up @@ -423,3 +425,47 @@ def getSmartTAVContext() {
}
}
}

def generateStepForWindows(Map params = [:]){
def version = params?.version
def disableAsyncHooks = params.get('disableAsyncHooks', false)
return {
sh label: 'Prepare services', script: ".ci/scripts/windows/prepare-test.sh ${version}"
def linuxIp = sh(label: 'Get IP', script: '''hostname -I | awk '{print $1}' ''', returnStdout: true)?.trim()
node('windows-2019-docker-immutable'){
// When installing with choco the PATH might not be updated within the already connected worker.
withEnv(["PATH=${PATH};C:\\Program Files\\nodejs",
"VERSION=${version}",
"ELASTIC_APM_ASYNC_HOOKS=${disableAsyncHooks}",
"CASSANDRA_HOST=${linuxIp}",
"ES_HOST=${linuxIp}",
"MEMCACHED_HOST=${linuxIp}",
"MONGODB_HOST=${linuxIp}",
"MSSQL_HOST=${linuxIp}",
"MYSQL_HOST=${linuxIp}",
"PGHOST=${linuxIp}",
"REDIS_HOST=${linuxIp}"]) {
try {
deleteDir()
unstash 'source'
dir(BASE_DIR) {
installTools([ [tool: 'nodejs', version: "${version}" ] ])
bat label: 'Tool versions', script: '''
npm --version
node --version
'''
bat 'npm install'
bat 'node test/test.js'
}
} catch(e){
error(e.toString())
} finally {
echo 'JUnit archiving no yet in place'
}
}
}

// If the above execution failed, then it will not reach this section. TBD
sh label: 'Stop services', script: ".ci/scripts/windows/stop-test.sh ${version}"
}
}
16 changes: 16 additions & 0 deletions .ci/scripts/windows/prepare-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -exo pipefail

NODE_VERSION=${1:?Nodejs version missing NODE_VERSION is not set}

NODE_VERSION=${NODE_VERSION} \
USER_ID="$(id -u):$(id -g)" \
docker-compose \
--no-ansi \
--log-level ERROR \
-f .ci/docker/docker-compose-all.yml \
up \
--build \
--remove-orphans \
--quiet-pull \
--detach
16 changes: 16 additions & 0 deletions .ci/scripts/windows/stop-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -exo pipefail

NODE_VERSION=${1:?Nodejs version missing NODE_VERSION is not set}

NODE_VERSION=${NODE_VERSION} docker-compose \
--no-ansi \
-f .ci/docker/docker-compose-all.yml \
logs \
--timestamps > docker-compose-logs.txt

NODE_VERSION=${NODE_VERSION} docker-compose \
--no-ansi \
--log-level ERROR \
-f .ci/docker/docker-compose-all.yml \
down -v
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ build
coverage
node_modules
test/benchmarks/.tmp
coverage.lcov
test-suite-output.tap
5 changes: 1 addition & 4 deletions test/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,10 +1362,7 @@ function assertMetadata (t, payload) {
t.equal(payload.process.pid, process.pid)
t.ok(payload.process.pid > 0, 'should have a pid greater than 0')
t.ok(payload.process.title, 'should have a process title')
t.ok(
/(npm|node)/.test(payload.process.title),
`process.title should contain expected value (was: "${payload.process.title}")`
)
t.equal(payload.process.title, process.title)
t.deepEqual(payload.process.argv, process.argv)
t.ok(payload.process.argv.length >= 2, 'should have at least two process arguments')
}
Expand Down
26 changes: 22 additions & 4 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,22 @@ test('serviceName defaults to package name', function (t) {
{
action: 'mkdirp',
dir: path.join(tmp, 'node_modules')
},
{
}
]

if (process.platform === 'win32') {
files.push({
action: 'npm link',
from: path.resolve(__dirname, '..'),
to: tmp
})
} else {
files.push({
action: 'symlink',
from: path.resolve(__dirname, '..'),
to: path.join(tmp, 'node_modules/elastic-apm-node')
}
]
})
}

// NOTE: Reduce the sequence to a promise chain rather
// than using Promise.all(), as the tasks are dependent.
Expand All @@ -473,6 +482,15 @@ test('serviceName defaults to package name', function (t) {
case 'symlink': {
return symlink(file.from, file.to)
}
case 'npm link': {
return exec('npm link', {
cwd: file.from
}).then(() => {
return exec('npm link elastic-apm-node', {
cwd: file.to
})
})
}
}
})
}, Promise.resolve())
Expand Down
2 changes: 1 addition & 1 deletion test/instrumentation/modules/bluebird/bluebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ test('Promise.promisify', function (t) {

readFile(__filename, 'utf8').then(function (contents) {
var firstLine = contents.split('\n')[0]
t.equal(firstLine, '\'use strict\'')
t.ok(/use strict/.test(firstLine))
t.equal(ins.currentTransaction.id, trans.id)
})
})
Expand Down
10 changes: 8 additions & 2 deletions test/instrumentation/modules/pg/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ exports.reset = reset
exports.loadData = loadData

function reset (cb) {
var client = new Client({ database: 'postgres' })
var client = new Client({
database: 'postgres',
user: process.env.PGUSER || 'postgres'
})

client.connect(function (err) {
if (err) throw err
Expand All @@ -22,7 +25,10 @@ function reset (cb) {
}

function loadData (cb) {
var client = new Client({ database: 'test_elastic_apm' })
var client = new Client({
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
})

client.connect(function (err) {
if (err) throw err
Expand Down
5 changes: 4 additions & 1 deletion test/instrumentation/modules/pg/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ function createClient (cb) {
setup(function () {
knex = Knex({
client: 'pg',
connection: 'postgres:///test_elastic_apm'
connection: {
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
}
})
cb()
})
Expand Down
11 changes: 8 additions & 3 deletions test/instrumentation/modules/pg/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ function assertBasicQuery (t, sql, data) {
function createClient (cb) {
setup(function () {
queryable = new pg.Client({
database: 'test_elastic_apm'
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
})
queryable.connect(function (err) {
if (err) throw err
Expand All @@ -523,11 +524,15 @@ function createPool (cb) {
if (semver.satisfies(pgVersion, '<6.0.0')) {
queryable = pg
connector = function connector (cb) {
return pg.connect('postgres:///test_elastic_apm', cb)
return pg.connect({
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
}, cb)
}
} else {
var pool = new pg.Pool({
database: 'test_elastic_apm'
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
})
queryable = pool
connector = function connector (cb) {
Expand Down
21 changes: 0 additions & 21 deletions test/script/appveyor/install-cassandra.ps1

This file was deleted.

27 changes: 0 additions & 27 deletions test/script/appveyor/install-elasticsearch.ps1

This file was deleted.

17 changes: 0 additions & 17 deletions test/script/appveyor/install-redis.ps1

This file was deleted.

0 comments on commit f955a86

Please sign in to comment.