Skip to content

Commit

Permalink
Fix tests on Node 12.16 (#349)
Browse files Browse the repository at this point in the history
* Fix expected async operations on node 12.16.0

* fixup! Fix expected async operations on node 12.16.0

* add back PR link for TIMERWRAP

* remove useless comment
  • Loading branch information
goto-bus-stop committed Feb 24, 2020
1 parent 6656fa1 commit eb4dddc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
21 changes: 12 additions & 9 deletions test/cmd-collect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const test = require('tap').test
const async = require('async')
const endpoint = require('endpoint')
const semver = require('semver')
const CollectAndRead = require('./collect-and-read.js')

test('collect command produces data files with content', function (t) {
Expand Down Expand Up @@ -74,15 +75,17 @@ test('collect command produces data files with content', function (t) {
asyncOperationTypes.push(trackedTraceEvent[0].type)
}

const majorVersion = parseInt(process.version.match(/^v(\d+)\./)[1], 10)
// Expect Timeout and TIMERWRAP to be there in Node 10.x and below
const oldExpected = ['TIMERWRAP', 'Timeout']
// TIMERWRAP was removed in Node 11: https://github.com/nodejs/node/pull/20894
const newExpected = ['Timeout']
t.strictDeepEqual(
asyncOperationTypes.sort(),
majorVersion >= 11 ? newExpected : oldExpected
)
const expected =
// Expect Timeout and TIMERWRAP to be there in Node 10.x and below. TIMERWRAP was removed in https://github.com/nodejs/node/pull/20894
semver.satisfies(process.version, '< 11.0')
? ['TIMERWRAP', 'Timeout']
// A `Promise.resolve()` call was added to bootstrap code in Node 12.16.x: https://github.com/nodejs/node/pull/30624
// Node.js 13 does not appear to show this `resolve()` call in its trace event log.
: semver.satisfies(process.version, '>= 12.16.0 < 13.0.0')
? ['PROMISE', 'Timeout']
: ['Timeout']

t.strictDeepEqual(asyncOperationTypes.sort(), expected)

t.end()
})
Expand Down
16 changes: 12 additions & 4 deletions test/integration-timeout.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const test = require('tap').test
const semver = require('semver')
const endpoint = require('endpoint')
const CollectAndRead = require('./collect-and-read.js')
const analysis = require('../analysis/index.js')
Expand All @@ -21,11 +22,18 @@ test('collect-analysis pipeline', function (t) {
const nodeMap = new Map(
aggregateNodes.map((node) => [node.aggregateId, node])
)
t.strictEqual(nodes.length, 2)
t.strictEqual(nodeMap.size, 2)
if (semver.satisfies(process.version, '>= 12.16.0 < 13.0.0')) {
t.strictEqual(nodes.length, 3)
t.strictEqual(nodeMap.size, 3)
// aggregateId = 1 is the root and points to the Timeout and a PROMISE from Node.js's initialization code
t.strictDeepEqual(nodeMap.get(1).children, [2, 3])
} else {
t.strictEqual(nodes.length, 2)
t.strictEqual(nodeMap.size, 2)
// aggregateId = 1 is the root and points to the Timeout
t.strictDeepEqual(nodeMap.get(1).children, [2])
}

// aggregateId = 1 is the root and points to the Timeout
t.strictDeepEqual(nodeMap.get(1).children, [2])
// aggregateId = 2 is the Timeout
t.strictEqual(nodeMap.get(2).sources[0].type, 'Timeout')

Expand Down

0 comments on commit eb4dddc

Please sign in to comment.