Skip to content

Commit

Permalink
refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rstiller committed Nov 2, 2018
1 parent 2856b85 commit 279cce5
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 165 deletions.
251 changes: 113 additions & 138 deletions test/metrics/reporter/logger-reporter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,21 @@ export class LoggerReporterTest {
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(2);
let logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("monotone-counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;

logMetadata = this.loggerSpy.getCall(1).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}
return Promise.reject();
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(2);
let logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("monotone-counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;

logMetadata = this.loggerSpy.getCall(1).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}

Expand All @@ -159,22 +155,19 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("gauge1");
expect(logMetadata.measurement_type).to.equal("gauge");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("gauge1");
expect(logMetadata.measurement_type).to.equal("gauge");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}

@test
Expand All @@ -184,22 +177,19 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("histogram1");
expect(logMetadata.measurement_type).to.equal("histogram");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("histogram1");
expect(logMetadata.measurement_type).to.equal("histogram");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}

@test
Expand All @@ -209,22 +199,19 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("meter1");
expect(logMetadata.measurement_type).to.equal("meter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("meter1");
expect(logMetadata.measurement_type).to.equal("meter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}

@test
Expand All @@ -234,22 +221,19 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("timer1");
expect(logMetadata.measurement_type).to.equal("timer");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("timer1");
expect(logMetadata.measurement_type).to.equal("timer");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
});
}

@test
Expand All @@ -261,24 +245,21 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
expect(logMetadata.tags["application"]).to.equal("app");
expect(logMetadata.tags["mode"]).to.equal("dev");
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
expect(logMetadata.tags["application"]).to.equal("app");
expect(logMetadata.tags["mode"]).to.equal("dev");
});
}

@test
Expand All @@ -290,24 +271,21 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
expect(logMetadata.tags["application"]).to.equal("app");
expect(logMetadata.tags["mode"]).to.equal("dev");
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
expect(logMetadata.tags["application"]).to.equal("app");
expect(logMetadata.tags["mode"]).to.equal("dev");
});
}

@test
Expand All @@ -321,25 +299,22 @@ export class LoggerReporterTest {
expect(this.loggerSpy).to.not.have.been.called;
expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
return this.internalCallback()
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
expect(logMetadata.tags["application"]).to.equal("app");
expect(logMetadata.tags["mode"]).to.equal("test");
expect(logMetadata.tags["component"]).to.equal("main");
});
}
return Promise.reject();
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.loggerSpy.callCount).to.equal(1);
const logMetadata = this.loggerSpy.getCall(0).args[1];
expect(logMetadata.measurement).to.equal("counter1");
expect(logMetadata.measurement_type).to.equal("counter");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags).to.not.be.null;
expect(logMetadata.tags["application"]).to.equal("app");
expect(logMetadata.tags["mode"]).to.equal("test");
expect(logMetadata.tags["component"]).to.equal("main");
});
}

}
48 changes: 21 additions & 27 deletions test/metrics/reporter/logger-reporter-v1.3-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class LoggerReporterTest {
}

@test
public "report multiple metric with same name"(callback: (err?: any) => any): void {
public "report multiple metric with same name"(): Promise<any> {
const gauge1 = new SimpleGauge("myValue");
const gauge2 = new SimpleGauge("myValue");

Expand All @@ -104,32 +104,26 @@ export class LoggerReporterTest {

expect(this.schedulerSpy).to.not.have.been.called;

this.reporter.start();

expect(this.schedulerSpy).to.have.been.called;

if (!!this.internalCallback) {
this.internalCallback()
.then(() => {
expect(this.logger.calls.length).to.equal(2);

let logMetadata = this.logger.calls[0];
expect(logMetadata.measurement).to.equal("myValue");
expect(logMetadata.measurement_type).to.equal("gauge");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags["type"]).to.equal("abc");

logMetadata = this.logger.calls[1];
expect(logMetadata.measurement).to.equal("myValue");
expect(logMetadata.measurement_type).to.equal("gauge");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags["type"]).to.equal("def");
})
.then(() => callback())
.catch((e) => callback(e));
} else {
callback(new Error("internalCallback is null / undefined"));
}
return this.reporter.start()
.then(() => {
expect(this.schedulerSpy).to.have.been.called;
})
.then(() => this.internalCallback())
.then(() => {
expect(this.logger.calls.length).to.equal(2);

let logMetadata = this.logger.calls[0];
expect(logMetadata.measurement).to.equal("myValue");
expect(logMetadata.measurement_type).to.equal("gauge");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags["type"]).to.equal("abc");

logMetadata = this.logger.calls[1];
expect(logMetadata.measurement).to.equal("myValue");
expect(logMetadata.measurement_type).to.equal("gauge");
expect(logMetadata.timestamp.getTime()).to.equal(0);
expect(logMetadata.tags["type"]).to.equal("def");
});
}

}

0 comments on commit 279cce5

Please sign in to comment.