Skip to content

[core-lro] merge azureAsync and location strategies#20656

Merged
deyaaeldeen merged 10 commits intoAzure:mainfrom
deyaaeldeen:core-lro/fix-20647
Mar 5, 2022
Merged

[core-lro] merge azureAsync and location strategies#20656
deyaaeldeen merged 10 commits intoAzure:mainfrom
deyaaeldeen:core-lro/fix-20647

Conversation

@deyaaeldeen
Copy link
Member

Packages impacted by this PR

@azure/core-lro

Issues associated with this PR

Fixes #20647

Describe the problem that is addressed by this PR

The vNext draft of the REST guidelines retires the use of Azure-AsyncOperation header in favor of Operation-Location. For context, Azure-AsyncOperation is mainly used for scenarios where there are two URLs, one for polling (returned in the Azure-AsyncOperation header) and another to retrieve the resource being created (returned in the Location header).

What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?

This PR enables clients to use Operation-Location for scenarios where Azure-AsyncOperation was used before by merging the logic for handling both into one. The merging was done by augmenting the existing logic for handling Azure-AsyncOperation as follows: To check if the polling was done (in isPollingDone), also check if the response status code was 202 or an unexpected one:

if (isUnexpectedPollingResponse(rawResponse) || rawResponse.statusCode === 202) {
    return false;
  }

The new merged logic is moved to locationPolling.ts and the old separate logic for handling Operation-Location was deleted.

I am open for alternative approaches, but I believe this is the simplest thing we can do.

Are there test cases added in this PR? (If not, why?)

Yes

Provide a list of related PRs (if any)

N/A

Command used to generate this PR:**(Applicable only to SDK release request PRs)

N/A

Checklists

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

@deyaaeldeen deyaaeldeen requested review from joheredi and xirzec March 4, 2022 02:54
@deyaaeldeen deyaaeldeen requested a review from jeremymeng as a code owner March 4, 2022 02:54
@ghost ghost added the Azure.Core label Mar 4, 2022
@check-enforcer
Copy link

check-enforcer bot commented Mar 4, 2022

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run js - [service] - ci

Copy link
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@deyaaeldeen
Copy link
Member Author

@jeremymeng Thanks for the approval! Also, FYI I did more work on tests in d8d592d to basically unify the tests for Azure-AsyncOperation and Operation-Location since polling in these cases should behave exactly the same. The diff again is bad and you do not have to review it. You can take a look at the final result in

matrix([["async", "location"]] as const, async function (rootPrefix: string) {
describe(`Polling from ${
rootPrefix === "async" ? "Azure-AsyncOperation" : "Operation-Location"
}`, function () {
const rootPrefix1 =
rootPrefix === "location" ? rootPrefix.charAt(0).toUpperCase() + rootPrefix.slice(1) : "";
it("should handle postDoubleHeadersFinalLocationGet", async () => {
const result = await runMockedLro(
"POST",
`/LROPost${rootPrefix1}DoubleHeadersFinalLocationGet`
);
assert.equal(result.id, "100");
assert.equal(result.name, "foo");
});
it("should handle postDoubleHeadersFinalAzureHeaderGet", async () => {
const result = await runMockedLro(
"POST",
`/LRO${rootPrefix1}PostDoubleHeadersFinalAzureHeaderGet`,
undefined,
"azure-async-operation"
);
assert.equal(result.id, "100");
});
it("should handle postDoubleHeadersFinalAzureHeaderGetDefault", async () => {
const result = await runMockedLro(
"POST",
`/LRO${rootPrefix1}PostDoubleHeadersFinalAzureHeaderGetDefault`
);
assert.equal(result.id, "100");
assert.equal(result.statusCode, 200);
});
it("should handle deleteAsyncRetrySucceeded", async () => {
const response = await runMockedLro("DELETE", `/delete${rootPrefix}/retry/succeeded`);
assert.equal(response.statusCode, 200);
});
it("should handle deleteAsyncNoRetrySucceeded", async () => {
const response = await runMockedLro("DELETE", `/delete${rootPrefix}/noretry/succeeded`);
assert.equal(response.statusCode, 200);
});
it("should handle deleteAsyncRetrycanceled", async () => {
try {
await runMockedLro("DELETE", `/delete${rootPrefix}/retry/canceled`);
throw new Error("should have thrown instead");
} catch (e) {
assert.equal(
e.message,
"The long running operation has failed. The provisioning state: canceled."
);
}
});
it("should handle DeleteAsyncRetryFailed", async () => {
try {
await runMockedLro("DELETE", `/delete${rootPrefix}/retry/failed`);
throw new Error("should have thrown instead");
} catch (e) {
assert.equal(
e.message,
"The long running operation has failed. The provisioning state: failed."
);
}
});
it("should handle putAsyncRetrySucceeded", async () => {
const result = await runMockedLro("PUT", `/put${rootPrefix}/noretry/succeeded`);
assert.equal(result.id, "100");
assert.equal(result.name, "foo");
assert.equal(result.properties?.provisioningState, "Succeeded");
});
it("should handle post202List", async () => {
const result = await runMockedLro(
"POST",
`/list${rootPrefix === "location" ? "location" : ""}`
);
assert.equal((result as any)[0].id, "100");
assert.equal((result as any)[0].name, "foo");
});
it("should handle putAsyncRetryFailed", async () => {
try {
await runMockedLro("PUT", `/put${rootPrefix}/retry/failed`);
throw new Error("should have thrown instead");
} catch (e) {
assert.equal(
e.message,
"The long running operation has failed. The provisioning state: failed."
);
}
});
it("should handle putAsyncNonResource", async () => {
const result = await runMockedLro("PUT", `/putnonresource${rootPrefix}/202/200`);
assert.equal(result.name, "sku");
assert.equal(result.id, "100");
});
it("should handle patchAsync", async () => {
const result = await runMockedLro("PATCH", `/patch${rootPrefix}/202/200`);
assert.equal(result.name, "sku");
assert.equal(result.id, "100");
});
it("should handle putAsyncNoHeaderInRetry", async () => {
const result = await runMockedLro("PUT", `/put${rootPrefix}/noheader/201/200`);
assert.equal(result.name, "foo");
assert.equal(result.id, "100");
assert.deepEqual(result.properties?.provisioningState, "Succeeded");
});
it("should handle putAsyncNoRetrySucceeded", async () => {
const result = await runMockedLro("PUT", `/put${rootPrefix}/noretry/succeeded`);
assert.equal(result.name, "foo");
assert.equal(result.id, "100");
});
it("should handle putAsyncNoRetrycanceled", async () => {
try {
await runMockedLro("PUT", `/put${rootPrefix}/noretry/canceled`);
throw new Error("should have thrown instead");
} catch (e) {
assert.equal(
e.message,
"The long running operation has failed. The provisioning state: canceled."
);
}
});
it("should handle putAsyncSubResource", async () => {
const result = await runMockedLro("PUT", `/putsubresource${rootPrefix}/202/200`);
assert.equal(result.id, "100");
assert.equal(result.properties?.provisioningState, "Succeeded");
});
it("should handle deleteAsyncNoHeaderInRetry", async () => {
const response = await runMockedLro("DELETE", `/delete${rootPrefix}/noheader/202/204`);
assert.equal(response.statusCode, 200);
});
it("should handle postAsyncNoRetrySucceeded", async () => {
const result = await runMockedLro("POST", `/post${rootPrefix}/noretry/succeeded`);
assert.deepInclude(result, { id: "100", name: "foo" });
});
it("should handle postAsyncRetryFailed", async () => {
try {
await runMockedLro("POST", `/post${rootPrefix}/retry/failed`);
throw new Error("should have thrown instead");
} catch (e) {
assert.equal(
e.message,
"The long running operation has failed. The provisioning state: failed."
);
}
});
it("should handle postAsyncRetrySucceeded", async () => {
const result = await runMockedLro("POST", `/post${rootPrefix}/retry/succeeded`);
assert.deepInclude(result, { id: "100", name: "foo" });
});
it("should handle postAsyncRetrycanceled", async () => {
try {
await runMockedLro("POST", `/post${rootPrefix}/retry/canceled`);
throw new Error("should have thrown instead");
} catch (e) {
assert.equal(
e.message,
"The long running operation has failed. The provisioning state: canceled."
);
}
});
});
});

@deyaaeldeen deyaaeldeen enabled auto-merge (squash) March 5, 2022 01:29
@deyaaeldeen deyaaeldeen merged commit 46ae95c into Azure:main Mar 5, 2022
@deyaaeldeen deyaaeldeen deleted the core-lro/fix-20647 branch March 5, 2022 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AzureAsync polling strategy should also look for operation-location header

2 participants