Skip to content

Commit d739dc5

Browse files
szegedirochdev
authored andcommitted
Fix flaky dns and net timeline event tests (#5011)
1 parent ac02048 commit d739dc5

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

integration-tests/profiler/profiler.spec.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ async function gatherNetworkTimelineEvents (cwd, scriptFilePath, eventType, args
133133
const events = []
134134
for (const sample of profile.sample) {
135135
let ts, event, host, address, port, name, spanId, localRootSpanId
136+
const unexpectedLabels = []
136137
for (const label of sample.label) {
137138
switch (label.key) {
138139
case tsKey: ts = label.num; break
@@ -143,23 +144,28 @@ async function gatherNetworkTimelineEvents (cwd, scriptFilePath, eventType, args
143144
case portKey: port = label.num; break
144145
case spanIdKey: spanId = label.str; break
145146
case localRootSpanIdKey: localRootSpanId = label.str; break
146-
default: assert.fail(`Unexpected label key ${label.key} ${strings.strings[label.key]} ${encoded}`)
147+
default: unexpectedLabels.push(label.key)
147148
}
148149
}
149-
// Timestamp must be defined and be between process start and end time
150-
assert.isDefined(ts, encoded)
151-
assert.isTrue(ts <= procEnd, encoded)
152-
assert.isTrue(ts >= procStart, encoded)
153-
if (process.platform !== 'win32') {
154-
assert.isDefined(spanId, encoded)
155-
assert.isDefined(localRootSpanId, encoded)
156-
} else {
157-
assert.isUndefined(spanId, encoded)
158-
assert.isUndefined(localRootSpanId, encoded)
159-
}
160150
// Gather only DNS events; ignore sporadic GC events
161151
if (event === eventValue) {
152+
// Timestamp must be defined and be between process start and end time
153+
assert.isDefined(ts, encoded)
154+
assert.isTrue(ts <= procEnd, encoded)
155+
assert.isTrue(ts >= procStart, encoded)
156+
if (process.platform !== 'win32') {
157+
assert.isDefined(spanId, encoded)
158+
assert.isDefined(localRootSpanId, encoded)
159+
} else {
160+
assert.isUndefined(spanId, encoded)
161+
assert.isUndefined(localRootSpanId, encoded)
162+
}
162163
assert.isDefined(name, encoded)
164+
if (unexpectedLabels.length > 0) {
165+
const labelsStr = JSON.stringify(unexpectedLabels)
166+
const labelsStrStr = unexpectedLabels.map(k => strings.strings[k]).join(',')
167+
assert.fail(`Unexpected labels: ${labelsStr}\n${labelsStrStr}\n${encoded}`)
168+
}
163169
// Exactly one of these is defined
164170
assert.isTrue(!!address !== !!host, encoded)
165171
const ev = { name: strings.strings[name] }

0 commit comments

Comments
 (0)