Skip to content

Commit

Permalink
ci: fixed coverage job (#825)
Browse files Browse the repository at this point in the history
refs 132534
  • Loading branch information
kirrg001 authored Jul 26, 2023
1 parent 4d9904d commit 08b5eb4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/collector/test/tracing/database/db2/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const DB2_TABLE_NAME_3 = process.env.DB2_TABLE_NAME_3 || 'table3';
*/
let tries = 0;
const MAX_TRIES = 10;
const CONNECT_TIMEOUT_IN_MS = 500;
const CONNECT_TIMEOUT_IN_MS = 2000;
let stmtObjectFromStart;

const db2OpenPromisified = promisify(ibmdb.open);
Expand Down
52 changes: 22 additions & 30 deletions packages/collector/test/tracing/database/db2/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const testUtils = require('../../../../../core/test/test_util');
const config = require('../../../../../core/test/config');
const ProcessControls = require('../../../test_util/ProcessControls');
const globalAgent = require('../../../globalAgent');

const oTelIntegrationIsEnabled = require('../../../test_util/isOTelIntegrationEnabled');

const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : describe.skip;

if (testUtils.isCI() && !process.env.DB2_CONNECTION_STR) {
Expand All @@ -36,12 +33,12 @@ const DB2_DATABASE_NAME = 'nodedb';
let TABLE_NAME_1;
let TABLE_NAME_2;
let TABLE_NAME_3;
const DELAY_TIMEOUT_IN_MS = 500;
const DELAY_TIMEOUT_IN_MS = 2000;

const DB2_CLOSE_TIMEOUT_IN_MS = 1000;

const testTimeout = Math.max(20000, config.getTestTimeout());
const retryTime = testTimeout / 2;
const testTimeout = Math.max(50000, config.getTestTimeout());
const retryTime = 30000;

const generateTableName = () => {
const randomStr = Array(8)
Expand All @@ -54,6 +51,15 @@ const generateTableName = () => {
return randomStr;
};

/**
* NOTE: When using `nyc` (our coverage tool) the number of spans are different,
* because `nyc` is using `node-preload`, which adds certain npm packages to the require cache.
* And if the require cache is containing libraries, which we instrument, we loose spans.
* DB2 is using fs-extra, which uses graceful-fs. `nyc` is using `graceful-fs` too.
* That's why we are loosing fs spans.
* We have removed the assertions for checking the exact number of spans for now.
* See https://github.com/instana/nodejs/pull/825#discussion_r1268002295
*/
const verifySpans = (agentControls, controls, options = {}) =>
agentControls.getSpans().then(spans => {
if (options.expectSpans === false) {
Expand All @@ -72,8 +78,6 @@ const verifySpans = (agentControls, controls, options = {}) =>
return;
}

expect(spans.length).to.equal(options.numberOfSpans || 2);

if (options.verifyCustom) return options.verifyCustom(entrySpan, spans);

testUtils.expectAtLeastOneMatching(spans, [
Expand Down Expand Up @@ -391,8 +395,7 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
stmt: `SELECT * FROM ${TABLE_NAME_1}`,
numberOfSpans: 3
stmt: `SELECT * FROM ${TABLE_NAME_1}`
})
)
);
Expand All @@ -407,8 +410,7 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
stmt: `SELECT * FROM ${TABLE_NAME_1}`,
numberOfSpans: 3
stmt: `SELECT * FROM ${TABLE_NAME_1}`
})
)
);
Expand All @@ -426,7 +428,6 @@ mochaSuiteFn('tracing/db2', function () {
verifySpans(agentControls, controls, {
stmt: `SELECT * FROM ${TABLE_NAME_1}`,
error: 'Error: [IBM][CLI Driver] CLI0115E Invalid cursor state. SQLSTATE=24000',
numberOfSpans: 3,
verifyCustom: (entrySpan, spans) => {
testUtils.expectAtLeastOneMatching(spans, [
span => expect(span.t).to.equal(entrySpan.t),
Expand Down Expand Up @@ -466,7 +467,6 @@ mochaSuiteFn('tracing/db2', function () {
testUtils.retry(() =>
verifySpans(agentControls, controls, {
stmt: `SELECT * FROM ${TABLE_NAME_1}`,
numberOfSpans: 3,
verifyCustom: (entrySpan, spans) => {
const realParent = testUtils.expectAtLeastOneMatching(spans, [
span => expect(span.n).to.equal('node.http.server'),
Expand Down Expand Up @@ -527,7 +527,6 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
numberOfSpans: 3,
verifyCustom: (entrySpan, spans) => {
testUtils.expectExactlyNMatching(spans, 2, [
span => expect(span.t).to.equal(entrySpan.t),
Expand Down Expand Up @@ -561,7 +560,6 @@ mochaSuiteFn('tracing/db2', function () {
testUtils.retry(() =>
verifySpans(agentControls, controls, {
stmt: `insert into ${TABLE_NAME_1} (COLINT, COLDATETIME, COLTEXT) VALUES (?, ?, ?)`,
numberOfSpans: 3,
verifyCustom: (entrySpan, spans) => {
testUtils.expectAtLeastOneMatching(spans, [
span => expect(span.t).to.equal(entrySpan.t),
Expand Down Expand Up @@ -609,8 +607,7 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
expectNoDb2Span: true,
numberOfSpans: 1
expectNoDb2Span: true
})
)
);
Expand Down Expand Up @@ -657,7 +654,6 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
numberOfSpans: 7,
verifyCustom: (entrySpan, spans) => {
const stmtsToExpect = [
`drop table ${TABLE_NAME_2} if exists`,
Expand Down Expand Up @@ -746,8 +742,7 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
expectNoDb2Span: true,
numberOfSpans: 1
expectNoDb2Span: true
})
)
);
Expand All @@ -764,8 +759,7 @@ mochaSuiteFn('tracing/db2', function () {
testUtils.retry(() =>
verifySpans(agentControls, controls, {
stmt: `SELECT * FROM ${TABLE_NAME_1}`,
error: `'result.closeSync' was not called within ${DB2_CLOSE_TIMEOUT_IN_MS}ms.`,
numberOfSpans: 2
error: `'result.closeSync' was not called within ${DB2_CLOSE_TIMEOUT_IN_MS}ms.`
})
)
);
Expand Down Expand Up @@ -849,8 +843,7 @@ mochaSuiteFn('tracing/db2', function () {
testUtils.retry(() =>
verifySpans(agentControls, controls, {
stmt: `SELECT * FROM ${TABLE_NAME_1}`,
error: `'result.closeSync' was not called within ${DB2_CLOSE_TIMEOUT_IN_MS}ms.`,
numberOfSpans: 2
error: `'result.closeSync' was not called within ${DB2_CLOSE_TIMEOUT_IN_MS}ms.`
})
)
);
Expand Down Expand Up @@ -880,10 +873,11 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
// Spans:
// 11 queries splitted from the file
// 4 fs operations on top (ours + from db2 internally fs-extra)
// https://github.com/ibmdb/node-ibm_db/blob/fb25937524d74d25917e9aa67fb4737971317986/lib/odbc.js#L916
numberOfSpans: oTelIntegrationIsEnabled ? 15 : 11,
// If the Otel integration is disabled, we expect 11 spans.
verifyCustom: (entrySpan, spans) => {
const stmtsToExpect = [
`create table ${TABLE_NAME_3}(no integer,name varchar(10))`,
Expand Down Expand Up @@ -929,8 +923,7 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
// 11 queries + fs calls
numberOfSpans: oTelIntegrationIsEnabled ? 16 : 11,
// 11 Instana spans + 5 Otel Spans
verifyCustom: (entrySpan, spans) => {
const stmtsToExpect = [
`create table ${TABLE_NAME_3}(no integer,name varchar(10))`,
Expand Down Expand Up @@ -976,8 +969,7 @@ mochaSuiteFn('tracing/db2', function () {
.then(() =>
testUtils.retry(() =>
verifySpans(agentControls, controls, {
// 11 queries + fs calls
numberOfSpans: oTelIntegrationIsEnabled ? 16 : 11,
// 11 Instana spans + 5 Otel fs spans
verifyCustom: (entrySpan, spans) => {
const stmtsToExpect = [
`create table ${TABLE_NAME_3}(no integer,name varchar(10))`,
Expand Down

0 comments on commit 08b5eb4

Please sign in to comment.