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

Add functional tests to cover all diagnostic channel autocollection #328

Merged
merged 22 commits into from
Sep 20, 2017
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
20 changes: 20 additions & 0 deletions AutoCollection/CorrelationContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ export class CorrelationContextManager {

// Restore Zone stack rewriting settings
(<any>orig).stackRewrite = stackRewrite;

// Remove unexpected bits from stack trace
if (this.stack && typeof this.stack === "string") {
var stackFrames: string[] = (<string>this.stack).split("\n");
// Remove this class
if (stackFrames.length > 3) {
if (stackFrames[2].trim().indexOf("at Error.AppInsightsAsyncCorrelatedErrorWrapper") === 0) {
stackFrames.splice(2, 1);
}
}
// Remove AI correlation ids
this.stack = stackFrames.map((v) => {
let startIndex = v.indexOf(") [");
if (startIndex > -1) {
v = v.substr(0, startIndex + 1);
}
return v;
}).join("\n");
}


// getOwnPropertyNames should be a superset of Object.keys...
// This appears to not always be the case
Expand Down
7 changes: 6 additions & 1 deletion AutoCollection/diagnostic-channel/console.sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ let clients: TelemetryClient[] = [];

const subscriber = (event: IStandardEvent<consolePub.IConsoleData>) => {
clients.forEach((client) => {
client.trackTrace({message: event.data.message, severity: (event.data.stderr ? SeverityLevel.Warning : SeverityLevel.Information)});
// Message can have a trailing newline
let message = event.data.message;
if (message.lastIndexOf("\n") == message.length - 1) {
message = message.substring(0, message.length - 1);
}
client.trackTrace({message: message, severity: (event.data.stderr ? SeverityLevel.Warning : SeverityLevel.Information)});
});
};

Expand Down
4 changes: 0 additions & 4 deletions AutoCollection/diagnostic-channel/mongodb.sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export const subscriber = (event: IStandardEvent<mongodb.IMongoData>) => {
resultCode: event.data.succeeded ? "0" : "1",
dependencyTypeName: 'mongodb'
});

if (!event.data.succeeded) {
client.trackException({exception:new Error(event.data.event.failure)});
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion AutoCollection/diagnostic-channel/postgres.sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let clients: TelemetryClient[] = [];
export const subscriber = (event: IStandardEvent<pg.IPostgresData>) => {
clients.forEach((client) => {
const q = event.data.query;
const sql = q.preparable.text || q.plan || q.text || "unknown query";
const sql = (q.preparable && q.preparable.text) || q.plan || q.text || "unknown query";
const success = !event.data.error;
const conn = `${event.data.database.host}:${event.data.database.port}`;
client.trackDependency({
Expand Down
8 changes: 4 additions & 4 deletions AutoCollection/diagnostic-channel/winston.sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ const winstonToAILevelMap: { [key: string]: (og: string) => number } = {
debug: SeverityLevel.Verbose
};

return map[og] || SeverityLevel.Information;
return map[og] === undefined ? SeverityLevel.Information : map[og];
},
npm(og: string) {
const map: { [key: string]: number } = {
error: SeverityLevel.Critical,
const map: { [key: string ]: number } = {
error: SeverityLevel.Error,
warn: SeverityLevel.Warning,
info: SeverityLevel.Information,
verbose: SeverityLevel.Verbose,
debug: SeverityLevel.Verbose,
silly: SeverityLevel.Verbose
};

return map[og] || SeverityLevel.Information;
return map[og] === undefined ? SeverityLevel.Information : map[og];
},
unknown(og: string) {
return SeverityLevel.Information;
Expand Down
28 changes: 24 additions & 4 deletions Tests/FunctionalTests/RunFunctionalTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,33 @@ function runAsync(cmd, workingDir) {
}

function startDocker() {
const mongo = run("docker run -d -p 27017:27017 --name ainjsmongo mongo");

return mongo.code === 0;
const tasks = [
run("docker run -d -p 27017:27017 --name ainjsmongo mongo"),
run("docker run -e MYSQL_ROOT_PASSWORD=dummypw -e MYSQL_DATABASE=testdb -d -p 33060:3306 --name ainjsmysql mysql"),
run("docker run -d -p 63790:6379 --name ainjsredis redis:alpine"),
run("docker run -d -p 54320:5432 --name ainjspostgres postgres:alpine")
];

for(let i = 0; i < tasks.length; i++) {
if (tasks[i].code !== 0) {
console.error("Failed to start container!");
console.error(tasks[i].output);
return false;
}
}
return true;
}

function cleanUpDocker() {
run("docker stop ainjsmongo");
run("docker stop ainjsmysql");
run("docker stop ainjsredis");
run("docker stop ainjspostgres");

run("docker rm ainjsmongo");
run("docker rm ainjsmysql");
run("docker rm ainjsredis");
run("docker rm ainjspostgres");
}

function main() {
Expand Down Expand Up @@ -111,7 +130,8 @@ function main() {
return 1;
}
console.log("Installing " + path);
if (run("npm install " + path, "./TestApp").code !== 0) {
run("npm uninstall applicationinsights", "./TestApp");
if (run("npm install --no-save " + path, "./TestApp").code !== 0) {
console.error("Could not install SDK!");
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/FunctionalTests/Runner/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const validateTestSequence = (index) => {
}
};
const runAndValidateLongTest = () => {
Utils.Logging.enterSubunit("Performing stress test sequence for " + Config.StressTestTime + "ms");
Utils.Logging.enterSubunit("Performing parallel requests test sequence for " + Config.StressTestTime + "ms");

// Find stress test
let testSequence = null;
Expand All @@ -65,7 +65,7 @@ const runAndValidateLongTest = () => {

// Don't continue if we don't have one
if (!testSequence) {
Utils.Logging.info("No stress test sequence defined. Skipping.");
Utils.Logging.info("No parallel test sequence defined. Skipping.");
Utils.Logging.exitSubunit();
return Promise.resolve(false);
} else if (!successfulRun) {
Expand Down
Loading