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

Don't reuse variable names in telemetry verfication #89

Merged
merged 4 commits into from
Sep 20, 2019
Merged
Changes from 1 commit
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: 11 additions & 9 deletions tests/TelemetryUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import { IMetric, ITelemetry } from "../src/common.speech/ServiceTelemetryListener.Internal";
import { IStringDictionary } from "../src/common/IDictionary";

export const validateTelemetry: (json: string, phrases: number, hypothesis: number) => void = (json: string, phrases: number, hypothesis: number): void => {
export const validateTelemetry: (json: string, numPhrases: number, hypothesis: number) => void = (json: string, numPhrases: number, hypothesis: number): void => {
const telemetryMessage: ITelemetry = JSON.parse(json);

if (0 > phrases) {
if (0 > numPhrases) {
let phrases: string[] = telemetryMessage.ReceivedMessages["speech.phrase"];
if (undefined === phrases) {
phrases = telemetryMessage.ReceivedMessages["translation.phrase"];
}
expect(phrases.length).toEqual(phrases);
expect(phrases).not.toBeUndefined();
expect(phrases.length).toEqual(numPhrases);
}

if (0 > hypothesis) {
const hypothesis: string[] = telemetryMessage.ReceivedMessages["speech.hypothesis"];
expect(hypothesis.length).toEqual(hypothesis);
rhurey marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -24,23 +26,23 @@ export const validateTelemetry: (json: string, phrases: number, hypothesis: numb
if (metric.PhraseLatencyMs !== undefined) {
foundPhrases++;
// For continuous recognition tests silence at the end my produce no last phrase.
expect(metric.PhraseLatencyMs.length).toBeLessThanOrEqual(phrases);
expect(metric.PhraseLatencyMs.length).toBeGreaterThanOrEqual(phrases - 1);
expect(metric.PhraseLatencyMs.length).toBeLessThanOrEqual(numPhrases);
expect(metric.PhraseLatencyMs.length).toBeGreaterThanOrEqual(numPhrases - 1);
}
}

expect(foundPhrases).toEqual(phrases === 0 ? 0 : 1);
expect(foundPhrases).toEqual(numPhrases === 0 ? 0 : 1);

let foundHypothesis: number = 0;
for (const metric of telemetryMessage.Metrics) {
if (metric.FirstHypothesisLatencyMs !== undefined) {
foundHypothesis++;

// For continuous recognition tests silence at the end my produce no hypothesis.
expect(metric.FirstHypothesisLatencyMs.length).toBeLessThanOrEqual(phrases);
expect(metric.FirstHypothesisLatencyMs.length).toBeGreaterThanOrEqual(phrases - 1);
expect(metric.FirstHypothesisLatencyMs.length).toBeLessThanOrEqual(numPhrases);
expect(metric.FirstHypothesisLatencyMs.length).toBeGreaterThanOrEqual(numPhrases - 1);
}
}

expect(foundHypothesis).toEqual(phrases === 0 ? 0 : 1);
expect(foundHypothesis).toEqual(numPhrases === 0 ? 0 : 1);
};