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

Update all uses of next to check done before consuming value #19637

Merged
merged 2 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { assert } from "chai";
import { Context } from "mocha";

import { matrix } from "@azure/test-utils";
import { matrix, getYieldedValue } from "@azure/test-utils";

import { env, Recorder } from "@azure-tools/test-recorder";

Expand Down Expand Up @@ -190,9 +190,9 @@ matrix([[true, false]] as const, async (useAad) => {

it("old-style iteration with next model info", async () => {
const iter = client.listModels();
const item = await iter.next();
const item = getYieldedValue(await iter.next());
assert.ok(item, `Expecting a model but got ${item}`);
assert.ok(item.value.modelId, `Expecting a model id but got ${item.value.modelId}`);
assert.ok(item.modelId, `Expecting a model id but got ${item.modelId}`);
});

it("delete models from the account", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import chai, { assert } from "chai";
import chaiAsPromised from "chai-as-promised";
chai.use(chaiAsPromised);
import { env, Recorder } from "@azure-tools/test-recorder";
import { getYieldedValue } from "@azure/test-utils";

import {
KeyVaultAccessControlClient,
Expand Down Expand Up @@ -70,7 +71,9 @@ describe("KeyVaultAccessControlClient", () => {

describe("getRoleDefinition", function () {
it("returns a role definition by name", async function () {
const anyRoleDefinition = (await client.listRoleDefinitions(globalScope).next()).value;
const anyRoleDefinition = getYieldedValue(
await client.listRoleDefinitions(globalScope).next()
);

const roleDefinition = await client.getRoleDefinition(globalScope, anyRoleDefinition.name);

Expand Down
1 change: 1 addition & 0 deletions sdk/metricsadvisor/ai-metrics-advisor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^2.0.1",
"@azure/test-utils": "^1.0.0",
"@azure-tools/test-recorder": "^1.0.0",
"@microsoft/api-extractor": "^7.18.11",
"@types/chai": "^4.1.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "../../src";
import { createRecordedAdminClient, makeCredential, testEnv } from "./util/recordedClients";
import { Recorder } from "@azure-tools/test-recorder";
import { matrix } from "./util/matrix";
import { matrix, getYieldedValue } from "@azure/test-utils";

matrix([[true, false]] as const, async (useAad) => {
describe(`[${useAad ? "AAD" : "API Key"}]`, () => {
Expand All @@ -37,10 +37,10 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2020, 9, 30)),
new Date(Date.UTC(2021, 10, 1))
);
let result = await iterator.next();
assert.ok(result.value.status, "Expecting first status");
result = await iterator.next();
assert.ok(result.value.status, "Expecting second status");
let result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting first status");
result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting second status");
});

it("lists ingestion status with datetime strings", async function () {
Expand All @@ -49,10 +49,10 @@ matrix([[true, false]] as const, async (useAad) => {
"2020-08-30T00:00:00.000Z",
"2021-11-01T00:00:00.000Z"
);
let result = await iterator.next();
assert.ok(result.value.status, "Expecting first status");
result = await iterator.next();
assert.ok(result.value.status, "Expecting second status");
let result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting first status");
result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting second status");
});

it("lists ingestion status by page", async function () {
Expand Down Expand Up @@ -84,9 +84,9 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2020, 9, 30)),
new Date(Date.UTC(2020, 10, 1))
);
const result = await iterator.next();
const result = getYieldedValue(await iterator.next());

if (result.value.status === "Succeeded") {
if (result.status === "Succeeded") {
await client.refreshDataFeedIngestion(
testEnv.METRICS_ADVISOR_AZURE_SQLSERVER_DATAFEED_ID,
new Date(Date.UTC(2020, 9, 30)),
Expand All @@ -98,8 +98,8 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2020, 9, 30)),
new Date(Date.UTC(2020, 10, 1))
);
const result2 = await iterator2.next();
assert.notEqual(result2.value.status, "Succeeded");
const result2 = getYieldedValue(await iterator2.next());
assert.notEqual(result2.status, "Succeeded");
} else {
this.skip();
}
Expand Down Expand Up @@ -246,11 +246,10 @@ matrix([[true, false]] as const, async (useAad) => {
const iterator = client.listDetectionConfigs(
testEnv.METRICS_ADVISOR_AZURE_SQLSERVER_METRIC_ID_1
);
let result = await iterator.next();

assert.ok(result.value.id, "Expecting first detection config");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second detection config");
let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first detection config");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second detection config");
});

it("lists detection configurations by page", async function () {
Expand Down Expand Up @@ -356,12 +355,10 @@ matrix([[true, false]] as const, async (useAad) => {
});
try {
const iterator = client.listAlertConfigs(createdDetectionConfigId);
let result = await iterator.next();

assert.ok(result.value.id, "Expecting first alert config");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second alert config");

let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first alert config");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second alert config");
const pageIterator = client.listAlertConfigs(createdDetectionConfigId).byPage();
const pageResult = await pageIterator.next();
assert.isTrue(pageResult.value.length > 1, "Expecting more than one entries in page");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "../../src";
import { createRecordedAdvisorClient, makeCredential, testEnv } from "./util/recordedClients";
import { Recorder } from "@azure-tools/test-recorder";
import { matrix } from "./util/matrix";
import { matrix, getYieldedValue } from "@azure/test-utils";

matrix([[true, false]] as const, async (useAad) => {
describe(`[${useAad ? "AAD" : "API Key"}]`, () => {
Expand All @@ -37,10 +37,10 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2021, 4, 5)),
new Date(Date.UTC(2021, 10, 1))
);
let result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting first anomaly");
result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting second anomaly");
let result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting first anomaly");
result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting second anomaly");
});

it("listAnomaliesForDetectionConfiguration() by page", async function () {
Expand All @@ -63,10 +63,10 @@ matrix([[true, false]] as const, async (useAad) => {
"2021-05-05T00:00:00.000Z",
"2021-11-01T00:00:00.000Z"
);
let result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting first anomaly");
result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting second anomaly");
let result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting first anomaly");
result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting second anomaly");
});

it("listAnomaliesForDetectionConfiguration() throws for invalid datetime strings", async function () {
Expand All @@ -89,10 +89,10 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2021, 4, 5)),
new Date(Date.UTC(2021, 10, 1))
);
let result = await iterator.next();
assert.ok(result.value.rootDimensionKey, "Expecting first incident");
result = await iterator.next();
assert.ok(result.value.rootDimensionKey, "Expecting second incident");
let result = getYieldedValue(await iterator.next());
assert.ok(result.rootDimensionKey, "Expecting first incident");
result = getYieldedValue(await iterator.next());
assert.ok(result.rootDimensionKey, "Expecting second incident");
});

it("listIncidentsForDetectionConfiguration() by page", async function () {
Expand All @@ -115,10 +115,10 @@ matrix([[true, false]] as const, async (useAad) => {
"2021-05-05T00:00:00.000Z",
"2021-11-01T00:00:00.000Z"
);
let result = await iterator.next();
assert.ok(result.value.rootDimensionKey, "Expecting first incident");
result = await iterator.next();
assert.ok(result.value.rootDimensionKey, "Expecting second incident");
let result = getYieldedValue(await iterator.next());
assert.ok(result.rootDimensionKey, "Expecting first incident");
result = getYieldedValue(await iterator.next());
assert.ok(result.rootDimensionKey, "Expecting second incident");
});

it("listIncidentsForDetectionConfiguration() throws for invalid datetime string", async function () {
Expand Down Expand Up @@ -183,10 +183,10 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2021, 10, 1)),
"AnomalyTime"
);
let result = await iterator.next();
assert.ok(result.value.id, "Expecting first alert");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second alert");
let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first alert");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second alert");
});

it("lists alerts for alert configuration with datetime strings", async function () {
Expand All @@ -196,10 +196,10 @@ matrix([[true, false]] as const, async (useAad) => {
"2021-11-01T00:00:00.000Z",
"AnomalyTime"
);
let result = await iterator.next();
assert.ok(result.value.id, "Expecting first alert");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second alert");
let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first alert");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second alert");
});

it("lists alerts for alert configuration by page", async function () {
Expand All @@ -222,10 +222,10 @@ matrix([[true, false]] as const, async (useAad) => {
alertConfigId: testEnv.METRICS_ADVISOR_ALERT_CONFIG_ID,
id: testEnv.METRICS_ADVISOR_ALERT_ID,
});
let result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting first anomaly");
result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting second anomaly");
let result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting first anomaly");
result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting second anomaly");
});

it("lists anomalies for alert by page", async function () {
Expand All @@ -246,10 +246,10 @@ matrix([[true, false]] as const, async (useAad) => {
alertConfigId: testEnv.METRICS_ADVISOR_ALERT_CONFIG_ID,
id: testEnv.METRICS_ADVISOR_ALERT_ID,
});
let result = await iterator.next();
assert.ok(result.value.id, "Expecting first incident");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second incident");
let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first incident");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second incident");
});

it("lists incidents for alert by page", async function () {
Expand All @@ -270,21 +270,21 @@ matrix([[true, false]] as const, async (useAad) => {
testEnv.METRICS_ADVISOR_AZURE_SQLSERVER_METRIC_ID_1,
new Date(Date.UTC(2021, 7, 5))
);
let result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting first definition");
result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting second definition");
let result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting first definition");
result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting second definition");
});

it("listMetricSeriesDefinitions() with datetime string", async function () {
const iterator = client.listMetricSeriesDefinitions(
testEnv.METRICS_ADVISOR_AZURE_SQLSERVER_METRIC_ID_1,
"2021-08-05T00:00:00.000Z"
);
let result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting first definition");
result = await iterator.next();
assert.ok(result.value.seriesKey, "Expecting second definition");
let result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting first definition");
result = getYieldedValue(await iterator.next());
assert.ok(result.seriesKey, "Expecting second definition");
});

it("listMetricSeriesDefinitions() by page", async function () {
Expand Down Expand Up @@ -467,10 +467,10 @@ matrix([[true, false]] as const, async (useAad) => {
new Date(Date.UTC(2021, 0, 1)),
new Date(Date.UTC(2021, 8, 18))
);
let result = await iterator.next();
assert.ok(result.value.status, "Expecting first status");
result = await iterator.next();
assert.ok(result.value.status, "Expecting second status");
let result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting first status");
result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting second status");
});

it("list metric enrichment status with datetime strings", async function () {
Expand All @@ -479,10 +479,10 @@ matrix([[true, false]] as const, async (useAad) => {
"2021-01-01T00:00:00.000Z",
"2021-09-18T00:00:00.000Z"
);
let result = await iterator.next();
assert.ok(result.value.status, "Expecting first status");
result = await iterator.next();
assert.ok(result.value.status, "Expecting second status");
let result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting first status");
result = getYieldedValue(await iterator.next());
assert.ok(result.status, "Expecting second status");
});

it("list metric enrichment status by page", async function () {
Expand Down Expand Up @@ -617,10 +617,10 @@ matrix([[true, false]] as const, async (useAad) => {
},
}
);
let result = await iterator.next();
assert.ok(result.value.id, "Expecting first status");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second status");
let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first status");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second status");
});

it("lists Anomaly feedbacks with datetime strings", async function () {
Expand All @@ -634,10 +634,10 @@ matrix([[true, false]] as const, async (useAad) => {
},
}
);
let result = await iterator.next();
assert.ok(result.value.id, "Expecting first status");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second status");
let result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting first status");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second status");
});

it("lists Anomaly feedbacks by page", async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "../../src";
import { createRecordedAdminClient, makeCredential } from "./util/recordedClients";
import { Recorder } from "@azure-tools/test-recorder";
import { getYieldedValue } from "@azure/test-utils";

describe("DataSourceCredential", () => {
let client: MetricsAdvisorAdministrationClient;
Expand Down Expand Up @@ -240,11 +241,11 @@ describe("DataSourceCredential", () => {

it("lists dataSource credentials one by one and by pages", async function () {
const iterator = client.listDataSourceCredential();
let result = await iterator.next();
let result = getYieldedValue(await iterator.next());

assert.ok(result.value.id, "Expecting first dataSource credential");
result = await iterator.next();
assert.ok(result.value.id, "Expecting second dataSource credential");
assert.ok(result.id, "Expecting first dataSource credential");
result = getYieldedValue(await iterator.next());
assert.ok(result.id, "Expecting second dataSource credential");

const pageIterator = client.listDataSourceCredential().byPage({ maxPageSize: 2 });
let pageResult = await pageIterator.next();
Expand Down
Loading