@azure/core-lro 3.0.0-beta.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/browser/http/models.d.ts +2 -2
  2. package/dist/browser/http/models.d.ts.map +1 -1
  3. package/dist/browser/http/models.js.map +1 -1
  4. package/dist/browser/http/operation.d.ts +11 -12
  5. package/dist/browser/http/operation.d.ts.map +1 -1
  6. package/dist/browser/http/operation.js +22 -16
  7. package/dist/browser/http/operation.js.map +1 -1
  8. package/dist/browser/http/poller.d.ts +2 -2
  9. package/dist/browser/http/poller.d.ts.map +1 -1
  10. package/dist/browser/http/poller.js +1 -15
  11. package/dist/browser/http/poller.js.map +1 -1
  12. package/dist/browser/index.d.ts +1 -1
  13. package/dist/browser/index.d.ts.map +1 -1
  14. package/dist/browser/index.js.map +1 -1
  15. package/dist/browser/poller/models.d.ts +15 -39
  16. package/dist/browser/poller/models.d.ts.map +1 -1
  17. package/dist/browser/poller/models.js.map +1 -1
  18. package/dist/browser/poller/operation.d.ts +12 -14
  19. package/dist/browser/poller/operation.d.ts.map +1 -1
  20. package/dist/browser/poller/operation.js +25 -29
  21. package/dist/browser/poller/operation.js.map +1 -1
  22. package/dist/browser/poller/poller.d.ts +1 -1
  23. package/dist/browser/poller/poller.d.ts.map +1 -1
  24. package/dist/browser/poller/poller.js +9 -34
  25. package/dist/browser/poller/poller.js.map +1 -1
  26. package/dist/commonjs/http/models.d.ts +2 -2
  27. package/dist/commonjs/http/models.d.ts.map +1 -1
  28. package/dist/commonjs/http/models.js.map +1 -1
  29. package/dist/commonjs/http/operation.d.ts +11 -12
  30. package/dist/commonjs/http/operation.d.ts.map +1 -1
  31. package/dist/commonjs/http/operation.js +22 -16
  32. package/dist/commonjs/http/operation.js.map +1 -1
  33. package/dist/commonjs/http/poller.d.ts +2 -2
  34. package/dist/commonjs/http/poller.d.ts.map +1 -1
  35. package/dist/commonjs/http/poller.js +1 -15
  36. package/dist/commonjs/http/poller.js.map +1 -1
  37. package/dist/commonjs/index.d.ts +1 -1
  38. package/dist/commonjs/index.d.ts.map +1 -1
  39. package/dist/commonjs/index.js.map +1 -1
  40. package/dist/commonjs/poller/models.d.ts +15 -39
  41. package/dist/commonjs/poller/models.d.ts.map +1 -1
  42. package/dist/commonjs/poller/models.js.map +1 -1
  43. package/dist/commonjs/poller/operation.d.ts +12 -14
  44. package/dist/commonjs/poller/operation.d.ts.map +1 -1
  45. package/dist/commonjs/poller/operation.js +25 -29
  46. package/dist/commonjs/poller/operation.js.map +1 -1
  47. package/dist/commonjs/poller/poller.d.ts +1 -1
  48. package/dist/commonjs/poller/poller.d.ts.map +1 -1
  49. package/dist/commonjs/poller/poller.js +9 -34
  50. package/dist/commonjs/poller/poller.js.map +1 -1
  51. package/dist/commonjs/tsdoc-metadata.json +1 -1
  52. package/dist/core-lro.d.ts +28 -32
  53. package/dist/esm/http/models.d.ts +2 -2
  54. package/dist/esm/http/models.d.ts.map +1 -1
  55. package/dist/esm/http/models.js.map +1 -1
  56. package/dist/esm/http/operation.d.ts +11 -12
  57. package/dist/esm/http/operation.d.ts.map +1 -1
  58. package/dist/esm/http/operation.js +22 -16
  59. package/dist/esm/http/operation.js.map +1 -1
  60. package/dist/esm/http/poller.d.ts +2 -2
  61. package/dist/esm/http/poller.d.ts.map +1 -1
  62. package/dist/esm/http/poller.js +1 -15
  63. package/dist/esm/http/poller.js.map +1 -1
  64. package/dist/esm/index.d.ts +1 -1
  65. package/dist/esm/index.d.ts.map +1 -1
  66. package/dist/esm/index.js.map +1 -1
  67. package/dist/esm/poller/models.d.ts +15 -39
  68. package/dist/esm/poller/models.d.ts.map +1 -1
  69. package/dist/esm/poller/models.js.map +1 -1
  70. package/dist/esm/poller/operation.d.ts +12 -14
  71. package/dist/esm/poller/operation.d.ts.map +1 -1
  72. package/dist/esm/poller/operation.js +25 -29
  73. package/dist/esm/poller/operation.js.map +1 -1
  74. package/dist/esm/poller/poller.d.ts +1 -1
  75. package/dist/esm/poller/poller.d.ts.map +1 -1
  76. package/dist/esm/poller/poller.js +9 -34
  77. package/dist/esm/poller/poller.js.map +1 -1
  78. package/dist/react-native/http/models.d.ts +2 -2
  79. package/dist/react-native/http/models.d.ts.map +1 -1
  80. package/dist/react-native/http/models.js.map +1 -1
  81. package/dist/react-native/http/operation.d.ts +11 -12
  82. package/dist/react-native/http/operation.d.ts.map +1 -1
  83. package/dist/react-native/http/operation.js +22 -16
  84. package/dist/react-native/http/operation.js.map +1 -1
  85. package/dist/react-native/http/poller.d.ts +2 -2
  86. package/dist/react-native/http/poller.d.ts.map +1 -1
  87. package/dist/react-native/http/poller.js +1 -15
  88. package/dist/react-native/http/poller.js.map +1 -1
  89. package/dist/react-native/index.d.ts +1 -1
  90. package/dist/react-native/index.d.ts.map +1 -1
  91. package/dist/react-native/index.js.map +1 -1
  92. package/dist/react-native/poller/models.d.ts +15 -39
  93. package/dist/react-native/poller/models.d.ts.map +1 -1
  94. package/dist/react-native/poller/models.js.map +1 -1
  95. package/dist/react-native/poller/operation.d.ts +12 -14
  96. package/dist/react-native/poller/operation.d.ts.map +1 -1
  97. package/dist/react-native/poller/operation.js +25 -29
  98. package/dist/react-native/poller/operation.js.map +1 -1
  99. package/dist/react-native/poller/poller.d.ts +1 -1
  100. package/dist/react-native/poller/poller.d.ts.map +1 -1
  101. package/dist/react-native/poller/poller.js +9 -34
  102. package/dist/react-native/poller/poller.js.map +1 -1
  103. package/package.json +26 -20
  104. package/.rush/temp/operation/build/state.json +0 -3
  105. package/.rush/temp/operation/build_samples/all.log +0 -2
  106. package/.rush/temp/operation/build_samples/state.json +0 -3
  107. package/.rush/temp/shrinkwrap-deps.json +0 -510
  108. package/.tshy/browser.json +0 -12
  109. package/.tshy/build.json +0 -9
  110. package/.tshy/commonjs.json +0 -14
  111. package/.tshy/esm.json +0 -12
  112. package/.tshy/react-native.json +0 -12
  113. package/CHANGELOG.md +0 -179
  114. package/api-extractor.json +0 -31
  115. package/config/rush-project.json +0 -3
  116. package/core-lro.build.cache.error.log +0 -1
  117. package/core-lro.build_samples.cache.log +0 -1
  118. package/core-lro.build_samples.log +0 -2
  119. package/core-lro.pack.cache.log +0 -1
  120. package/core-lro.pack.log +0 -1
  121. package/docs/LROEngine.md +0 -158
  122. package/review/core-lro.api.md +0 -106
  123. package/samples/README.md +0 -284
  124. package/samples/typescript/samplesClient.ts +0 -254
  125. package/src/http/models.ts +0 -119
  126. package/src/http/operation.ts +0 -343
  127. package/src/http/poller.ts +0 -83
  128. package/src/index.ts +0 -21
  129. package/src/logger.ts +0 -10
  130. package/src/poller/constants.ts +0 -11
  131. package/src/poller/models.ts +0 -251
  132. package/src/poller/operation.ts +0 -315
  133. package/src/poller/poller.ts +0 -250
  134. package/temp/core-lro.api.json +0 -1892
  135. package/temp/core-lro.api.md +0 -106
  136. package/test/getYieldedValue.ts +0 -16
  137. package/test/lro.spec.ts +0 -3141
  138. package/test/matrix.ts +0 -46
  139. package/test/utils/coreRestPipelineLro.ts +0 -25
  140. package/test/utils/router.ts +0 -231
  141. package/test/utils/utils.ts +0 -144
  142. package/tsconfig.browser.config.json +0 -10
  143. package/tsconfig.json +0 -13
  144. package/tsdoc.json +0 -4
  145. package/tslint.json +0 -47
  146. package/vitest.browser.config.ts +0 -34
  147. package/vitest.config.ts +0 -31
package/test/lro.spec.ts DELETED
@@ -1,3141 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
-
4
- import {
5
- ImplementationName,
6
- assertDivergentBehavior,
7
- assertError,
8
- createDoubleHeaders,
9
- Result,
10
- } from "./utils/utils.js";
11
- import { describe, it, assert } from "vitest";
12
- import { createRunLroWith, createTestPoller } from "./utils/router.js";
13
- import { delay } from "@azure/core-util";
14
- import { matrix } from "./matrix.js";
15
- matrix(
16
- [["createPoller"], [true, false]] as const,
17
- async function (implName: ImplementationName, throwOnNon2xxResponse: boolean) {
18
- const runLro = createRunLroWith({ implName, throwOnNon2xxResponse });
19
- describe(`${implName} (throwOnNon2xxResponse = ${throwOnNon2xxResponse})`, function () {
20
- describe("No polling", () => {
21
- it("should handle delete204Succeeded", async () => {
22
- const response = await runLro({
23
- routes: [{ method: "DELETE", status: 204 }],
24
- });
25
- assert.equal(response.statusCode, 204);
26
- });
27
-
28
- it("put201Succeeded", async function () {
29
- const result = await runLro({
30
- routes: [
31
- {
32
- method: "PUT",
33
- status: 201,
34
- body: `{ "properties": { "provisioningState": "Succeeded"}, "id": "100", "name": "foo" }`,
35
- },
36
- ],
37
- });
38
- assert.equal(result.id, "100");
39
- assert.equal(result.name, "foo");
40
- assert.equal(result.properties?.provisioningState, "Succeeded");
41
- });
42
-
43
- it("should handle post202Retry200", async () => {
44
- const path = "/post/202/retry/200";
45
- const newPath = "/post/newuri/202/retry/200";
46
- const response = await runLro({
47
- routes: [
48
- {
49
- method: "POST",
50
- path,
51
- status: 202,
52
- headers: {
53
- location: path,
54
- "retry-after": "0",
55
- },
56
- },
57
- {
58
- method: "GET",
59
- path,
60
- status: 202,
61
- headers: {
62
- location: newPath,
63
- },
64
- },
65
- {
66
- method: "GET",
67
- path: newPath,
68
- status: 200,
69
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
70
- },
71
- ],
72
- });
73
- assert.equal(response.statusCode, 200);
74
- });
75
-
76
- it("should handle post202NoRetry204", async () => {
77
- const path = "/post/202/noretry/204";
78
- const pollingPath = "/post/newuri/202/noretry/204";
79
- const response = await runLro({
80
- routes: [
81
- {
82
- method: "POST",
83
- path,
84
- status: 202,
85
- headers: {
86
- location: path,
87
- },
88
- },
89
- {
90
- method: "GET",
91
- path,
92
- status: 202,
93
- headers: {
94
- location: pollingPath,
95
- },
96
- },
97
- {
98
- method: "GET",
99
- path: pollingPath,
100
- status: 204,
101
- },
102
- ],
103
- });
104
- assert.equal(response.statusCode, 204);
105
- });
106
-
107
- it("should handle deleteNoHeaderInRetry", async () => {
108
- const pollingPath = "/delete/noheader/operationresults/123";
109
- const response = await runLro({
110
- routes: [
111
- {
112
- method: "DELETE",
113
- status: 200,
114
- headers: { Location: pollingPath },
115
- },
116
- { method: "GET", path: pollingPath, status: 202 },
117
- { method: "GET", path: pollingPath, status: 204 },
118
- ],
119
- });
120
- assert.equal(response.statusCode, 204);
121
- });
122
-
123
- it("should handle put202Retry200", async () => {
124
- const pollingPath = "/put/202/retry/operationResults/200";
125
- const response = await runLro({
126
- routes: [
127
- {
128
- method: "PUT",
129
- status: 202,
130
- headers: { Location: pollingPath },
131
- },
132
- {
133
- method: "GET",
134
- path: pollingPath,
135
- status: 200,
136
- body: `{"id": "100", "name": "foo" }`,
137
- },
138
- ],
139
- });
140
- assert.equal(response.statusCode, 200);
141
- });
142
-
143
- it("should handle putNoHeaderInRetry", async () => {
144
- const pollingPath = "/put/noheader/operationresults";
145
- const result = await runLro({
146
- routes: [
147
- {
148
- method: "PUT",
149
- status: 202,
150
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "name": "foo" }`,
151
- headers: { Location: pollingPath },
152
- },
153
- { method: "GET", path: pollingPath, status: 202 },
154
- {
155
- method: "GET",
156
- path: pollingPath,
157
- status: 200,
158
- body: `{ "properties": { "provisioningState": "Succeeded"}, "id": "100", "name": "foo" }`,
159
- },
160
- ],
161
- });
162
- assert.equal(result.id, "100");
163
- assert.equal(result.name, "foo");
164
- assert.equal(result.properties?.provisioningState, "Succeeded");
165
- });
166
-
167
- it("should handle putSubResource", async () => {
168
- const pollingPath = "/putsubresource/operationresults";
169
- const result = await runLro({
170
- routes: [
171
- {
172
- method: "PUT",
173
- status: 202,
174
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "subresource": "sub1" }`,
175
- headers: { Location: pollingPath },
176
- },
177
- { method: "GET", path: pollingPath, status: 202 },
178
- {
179
- method: "GET",
180
- path: pollingPath,
181
- status: 200,
182
- body: `{ "properties": { "provisioningState": "Succeeded"}, "id": "100", "subresource": "sub1" }`,
183
- },
184
- ],
185
- });
186
- assert.equal(result.id, "100");
187
- assert.equal(result.properties?.provisioningState, "Succeeded");
188
- });
189
-
190
- it("should handle putNonResource", async () => {
191
- const pollingPath = "/putnonresource/operationresults";
192
- const result = await runLro({
193
- routes: [
194
- {
195
- method: "PUT",
196
- status: 202,
197
- headers: { Location: pollingPath },
198
- },
199
- { method: "GET", path: pollingPath, status: 202 },
200
- {
201
- method: "GET",
202
- path: pollingPath,
203
- status: 200,
204
- body: `{ "name": "sku" , "id": "100" }`,
205
- },
206
- ],
207
- });
208
- assert.equal(result.id, "100");
209
- assert.equal(result.name, "sku");
210
- });
211
-
212
- it("should handle delete202Retry200", async () => {
213
- const path = "/delete/202/retry/200";
214
- const pollingPath = "/delete/newuri/202/retry/200";
215
- const response = await runLro({
216
- routes: [
217
- {
218
- method: "DELETE",
219
- path,
220
- status: 202,
221
- headers: {
222
- location: path,
223
- "retry-after": "0",
224
- },
225
- },
226
- {
227
- method: "GET",
228
- path,
229
- status: 202,
230
- headers: {
231
- location: pollingPath,
232
- "retry-after": "0",
233
- },
234
- },
235
- {
236
- method: "GET",
237
- path: pollingPath,
238
- status: 200,
239
- },
240
- ],
241
- });
242
- assert.equal(response.statusCode, 200);
243
- });
244
-
245
- it("should handle delete202NoRetry204", async () => {
246
- const path = "/delete/202/noretry/204";
247
- const newPath = "/delete/newuri/202/noretry/204";
248
- const response = await runLro({
249
- routes: [
250
- {
251
- method: "DELETE",
252
- path,
253
- status: 202,
254
- headers: {
255
- location: path,
256
- },
257
- },
258
- {
259
- method: "GET",
260
- path,
261
- status: 202,
262
- headers: {
263
- location: newPath,
264
- },
265
- },
266
- {
267
- method: "GET",
268
- path: newPath,
269
- status: 204,
270
- },
271
- ],
272
- });
273
- assert.equal(response.statusCode, 204);
274
- });
275
-
276
- it("should handle deleteProvisioning202Accepted200Succeeded", async () => {
277
- const pollingPath = "/delete/provisioning/202/accepted/200/succeeded";
278
- const response = await runLro({
279
- routes: [
280
- {
281
- method: "DELETE",
282
- status: 202,
283
- headers: {
284
- location: pollingPath,
285
- "retry-after": "0",
286
- },
287
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
288
- },
289
- {
290
- method: "GET",
291
- path: pollingPath,
292
- status: 200,
293
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
294
- },
295
- ],
296
- });
297
- assert.equal(response.statusCode, 200);
298
- });
299
-
300
- it("should handle deleteProvisioning202DeletingFailed200", async () => {
301
- const path = "/delete/provisioning/202/deleting/200/failed";
302
- const response = await runLro({
303
- routes: [
304
- {
305
- method: "DELETE",
306
- path,
307
- status: 202,
308
- headers: {
309
- location: path,
310
- "retry-after": "0",
311
- },
312
- body: `{"properties":{"provisioningState":"Deleting"},"id":"100","name":"foo"}`,
313
- },
314
- {
315
- method: "GET",
316
- path,
317
- status: 200,
318
- body: `{"properties":{"provisioningState":"Failed"},"id":"100","name":"foo"}`,
319
- },
320
- ],
321
- });
322
- assert.equal(response.statusCode, 200);
323
- assert.equal(response.properties?.provisioningState, "Failed");
324
- });
325
-
326
- it("should handle deleteProvisioning202Deletingcanceled200", async () => {
327
- const path = "/delete/provisioning/202/deleting/200/canceled";
328
- const response = await runLro({
329
- routes: [
330
- {
331
- method: "DELETE",
332
- path,
333
- status: 202,
334
- headers: {
335
- location: path,
336
- "retry-after": "0",
337
- },
338
- body: `{"properties":{"provisioningState":"Deleting"},"id":"100","name":"foo"}`,
339
- },
340
- {
341
- method: "GET",
342
- path,
343
- status: 200,
344
- body: `{"properties":{"provisioningState":"Canceled"},"id":"100","name":"foo"}`,
345
- },
346
- ],
347
- });
348
- assert.equal(response.statusCode, 200);
349
- assert.equal(response.properties?.provisioningState, "Canceled");
350
- });
351
- });
352
-
353
- describe("Polling from body", () => {
354
- it("put200Succeeded", async function () {
355
- const result = await runLro({
356
- routes: [
357
- {
358
- method: "PUT",
359
- status: 200,
360
- body: `{ "properties": { "provisioningState": "Succeeded"}, "id": "100", "name": "foo" }`,
361
- },
362
- ],
363
- });
364
- assert.equal(result.properties?.provisioningState, "Succeeded");
365
- });
366
-
367
- it("should handle initial response with terminal state without provisioning State", async () => {
368
- const result = await runLro({
369
- routes: [
370
- {
371
- method: "PUT",
372
- status: 200,
373
- body: `{"id": "100", "name": "foo" }`,
374
- },
375
- ],
376
- });
377
- assert.deepEqual(result.id, "100");
378
- assert.deepEqual(result.name, "foo");
379
- });
380
-
381
- it("should handle initial response creating followed by success through an Azure Resource", async () => {
382
- const path = "/put/201/creating/succeeded/200";
383
- const result = await runLro({
384
- routes: [
385
- {
386
- method: "PUT",
387
- path,
388
- status: 201,
389
- body: `{"properties":{"provisioningState":"Creating"},"id":"100","name":"foo"}`,
390
- },
391
- {
392
- method: "GET",
393
- path,
394
- status: 200,
395
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
396
- },
397
- ],
398
- });
399
- assert.deepEqual(result.properties?.provisioningState, "Succeeded");
400
- assert.deepEqual(result.id, "100");
401
- assert.deepEqual(result.name, "foo");
402
- });
403
-
404
- it("should handle put200Acceptedcanceled200", async () => {
405
- const path = "/put/200/accepted/canceled/200";
406
- const body = { properties: { provisioningState: "Canceled" } };
407
- await assertDivergentBehavior({
408
- op: runLro({
409
- routes: [
410
- {
411
- method: "PUT",
412
- path,
413
- status: 200,
414
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
415
- },
416
- {
417
- method: "GET",
418
- path,
419
- status: 200,
420
- body: JSON.stringify(body),
421
- },
422
- ],
423
- }),
424
- throwOnNon2xxResponse,
425
- throwing: {
426
- messagePattern: /Operation was canceled/,
427
- },
428
- notThrowing: {
429
- result: {
430
- ...body,
431
- statusCode: 200,
432
- },
433
- },
434
- });
435
- });
436
-
437
- it("should handle put200UpdatingSucceeded204", async () => {
438
- const path = "/put/200/updating/succeeded/200";
439
- const result = await runLro({
440
- routes: [
441
- {
442
- method: "PUT",
443
- path,
444
- status: 200,
445
- body: `{"properties":{"provisioningState":"Updating"},"id":"100","name":"foo"}`,
446
- },
447
- {
448
- method: "GET",
449
- path,
450
- status: 200,
451
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
452
- },
453
- ],
454
- });
455
- assert.deepEqual(result.properties?.provisioningState, "Succeeded");
456
- assert.deepEqual(result.id, "100");
457
- assert.deepEqual(result.name, "foo");
458
- });
459
-
460
- it("should handle put201CreatingFailed200", async () => {
461
- const path = "/put/201/created/failed/200";
462
- const body = {
463
- properties: {
464
- provisioningState: "Failed",
465
- },
466
- };
467
- await assertDivergentBehavior({
468
- op: runLro({
469
- routes: [
470
- {
471
- method: "PUT",
472
- path,
473
- status: 201,
474
- body: `{"properties":{"provisioningState":"Created"},"id":"100","name":"foo"}`,
475
- },
476
- {
477
- method: "GET",
478
- path,
479
- status: 200,
480
- body: JSON.stringify(body),
481
- },
482
- ],
483
- }),
484
- throwOnNon2xxResponse,
485
- throwing: {
486
- messagePattern: /The long-running operation has failed/,
487
- },
488
- notThrowing: {
489
- result: { ...body, statusCode: 200 },
490
- },
491
- });
492
- });
493
-
494
- it("should handle post200WithPayload", async () => {
495
- const path = `/post/payload/200`;
496
- const result = await runLro({
497
- routes: [
498
- {
499
- method: "POST",
500
- path,
501
- status: 202,
502
- headers: { Location: path, "Retry-After": "0" },
503
- },
504
- { method: "GET", path, status: 200, body: `{"id":"1", "name":"product"}` },
505
- ],
506
- });
507
- assert.equal(result.id, "1");
508
- assert.equal(result.name, "product");
509
- });
510
- });
511
-
512
- matrix(
513
- [["Azure-AsyncOperation", "Operation-Location"]] as const,
514
- async function (headerName: string) {
515
- describe(`Polling from ${headerName}`, function () {
516
- it("should handle postDoubleHeadersFinalLocationGet", async () => {
517
- const operationLocationPath =
518
- "/LROPostDoubleHeadersFinalLocationGet/asyncOperationUrl";
519
- const resourceLocationPath = `/LROPostDoubleHeadersFinalLocationGet/location`;
520
- const result = await runLro({
521
- routes: [
522
- {
523
- method: "POST",
524
- status: 202,
525
- headers: {
526
- Location: resourceLocationPath,
527
- [headerName]: operationLocationPath,
528
- },
529
- },
530
- {
531
- method: "GET",
532
- path: operationLocationPath,
533
- status: 200,
534
- body: `{ "status": "succeeded" }`,
535
- },
536
- {
537
- method: "GET",
538
- path: resourceLocationPath,
539
- status: 200,
540
- body: `{ "id": "100", "name": "foo" }`,
541
- },
542
- ],
543
- });
544
- assert.equal(result.id, "100");
545
- assert.equal(result.name, "foo");
546
- });
547
-
548
- it("should handle getDoubleHeadersFinalLocationGet", async () => {
549
- const operationLocationPath =
550
- "/LROPostDoubleHeadersFinalLocationGet/asyncOperationUrl";
551
- const resourceLocationPath = `/LROPostDoubleHeadersFinalLocationGet/location`;
552
- const result = await runLro({
553
- routes: [
554
- {
555
- method: "GET",
556
- status: 202,
557
- headers: {
558
- Location: resourceLocationPath,
559
- [headerName]: operationLocationPath,
560
- },
561
- },
562
- {
563
- method: "GET",
564
- path: operationLocationPath,
565
- status: 200,
566
- body: `{ "status": "running" }`,
567
- },
568
- {
569
- method: "GET",
570
- path: operationLocationPath,
571
- status: 200,
572
- body: `{ "status": "succeeded" }`,
573
- },
574
- {
575
- method: "GET",
576
- path: resourceLocationPath,
577
- status: 200,
578
- body: `{ "id": "100", "name": "foo" }`,
579
- },
580
- ],
581
- });
582
- assert.equal(result.id, "100");
583
- assert.equal(result.name, "foo");
584
- });
585
-
586
- it("should handle getDoubleHeaders", async () => {
587
- const operationLocationPath =
588
- "/LROPostDoubleHeadersFinalLocationGet/asyncOperationUrl";
589
- const result = await runLro({
590
- routes: [
591
- {
592
- method: "GET",
593
- status: 202,
594
- headers: {
595
- [headerName]: operationLocationPath,
596
- },
597
- },
598
- {
599
- method: "GET",
600
- path: operationLocationPath,
601
- status: 200,
602
- body: `{ "status": "running" }`,
603
- },
604
- {
605
- method: "GET",
606
- path: operationLocationPath,
607
- status: 200,
608
- body: `{ "status": "succeeded", "id": "100", "name": "foo" }`,
609
- },
610
- ],
611
- });
612
- assert.equal(result.id, "100");
613
- assert.equal(result.name, "foo");
614
- });
615
-
616
- it("should handle get200", async () => {
617
- const result = await runLro({
618
- routes: [
619
- {
620
- method: "GET",
621
- status: 200,
622
- body: `{ "id": "100", "name": "foo" }`,
623
- },
624
- ],
625
- });
626
- assert.equal(result.id, "100");
627
- assert.equal(result.name, "foo");
628
- });
629
-
630
- it("should handle postUpdatedPollingUrl", async () => {
631
- const operationLocationPath1 = "path1";
632
- const operationLocationPath2 = "path2";
633
- const result = await runLro({
634
- routes: [
635
- {
636
- method: "POST",
637
- status: 200,
638
- headers: {
639
- [headerName]: operationLocationPath1,
640
- },
641
- },
642
- {
643
- method: "GET",
644
- path: operationLocationPath1,
645
- status: 200,
646
- body: `{ "status": "running" }`,
647
- headers: {
648
- [headerName]: operationLocationPath2,
649
- },
650
- },
651
- {
652
- method: "GET",
653
- path: operationLocationPath2,
654
- status: 200,
655
- body: `{ "status": "succeeded", "id": "100", "name": "foo" }`,
656
- },
657
- ],
658
- });
659
- assert.equal(result.id, "100");
660
- assert.equal(result.name, "foo");
661
- });
662
-
663
- it("should handle postDoubleHeadersFinalAzureHeaderGet", async () => {
664
- const locationPath = `/LROPostDoubleHeadersFinalAzureHeaderGet/location`;
665
- const operationLocationPath = `/LROPostDoubleHeadersFinalAzureHeaderGet/asyncOperationUrl`;
666
- const result = await runLro({
667
- routes: [
668
- {
669
- method: "POST",
670
- status: 202,
671
- body: "",
672
- headers: {
673
- Location: locationPath,
674
- [headerName]: operationLocationPath,
675
- },
676
- },
677
- {
678
- method: "GET",
679
- path: operationLocationPath,
680
- status: 200,
681
- body: `{ "status": "succeeded", "id": "100"}`,
682
- },
683
- {
684
- method: "GET",
685
- path: locationPath,
686
- status: 400,
687
- },
688
- ],
689
- resourceLocationConfig: "azure-async-operation",
690
- });
691
- assert.equal(result.statusCode, 200);
692
- assert.equal(result.id, "100");
693
- });
694
-
695
- it("should handle postDoubleHeadersFinalAzureHeaderGetDefault", async () => {
696
- const resourceLocationPath =
697
- "/LROPostDoubleHeadersFinalAzureHeaderGetDefault/location";
698
- const pollingPath =
699
- "/LROPostDoubleHeadersFinalAzureHeaderGetDefault/asyncOperationUrl";
700
- const result = await runLro({
701
- routes: [
702
- {
703
- method: "POST",
704
- status: 202,
705
- body: "",
706
- headers: {
707
- Location: resourceLocationPath,
708
- [headerName]: pollingPath,
709
- },
710
- },
711
- {
712
- method: "GET",
713
- path: pollingPath,
714
- status: 200,
715
- body: `{ "status": "succeeded"}`,
716
- },
717
- {
718
- method: "GET",
719
- path: resourceLocationPath,
720
- status: 200,
721
- body: `{ "id": "100", "name": "foo" }`,
722
- },
723
- ],
724
- });
725
- assert.equal(result.id, "100");
726
- assert.equal(result.statusCode, 200);
727
- });
728
-
729
- it("should handle deleteAsyncRetrySucceeded", async () => {
730
- const pollingPath = "/deleteasync/retry/succeeded/operationResults/200/";
731
- const response = await runLro({
732
- routes: [
733
- {
734
- method: "DELETE",
735
- status: 202,
736
- headers: {
737
- location: pollingPath,
738
- [headerName]: pollingPath,
739
- "retry-after": "0",
740
- },
741
- },
742
- {
743
- method: "GET",
744
- path: pollingPath,
745
- status: 202,
746
- headers: {
747
- location: pollingPath,
748
- [headerName]: pollingPath,
749
- "retry-after": "0",
750
- },
751
- body: `{"status":"Accepted"}`,
752
- },
753
- {
754
- method: "GET",
755
- path: pollingPath,
756
- status: 200,
757
- body: `{"status":"Succeeded"}`,
758
- },
759
- ],
760
- });
761
- assert.equal(response.statusCode, 200);
762
- });
763
-
764
- it("should handle deleteAsyncNoRetrySucceeded", async () => {
765
- const pollingPath = "/deleteasync/noretry/succeeded/operationResults/200/";
766
- const response = await runLro({
767
- routes: [
768
- {
769
- method: "DELETE",
770
- status: 202,
771
- headers: {
772
- location: pollingPath,
773
- [headerName]: pollingPath,
774
- },
775
- },
776
- {
777
- method: "GET",
778
- path: pollingPath,
779
- status: 202,
780
- headers: {
781
- location: pollingPath,
782
- [headerName]: pollingPath,
783
- },
784
- body: `{"status":"Accepted"}`,
785
- },
786
- {
787
- method: "GET",
788
- path: pollingPath,
789
- status: 200,
790
- body: `{"status":"Succeeded"}`,
791
- },
792
- ],
793
- });
794
- assert.equal(response.statusCode, 200);
795
- });
796
-
797
- it("should handle deleteAsyncRetrycanceled", async () => {
798
- const pollingPath = "/deletelocation/retry/canceled/operationResults/200/";
799
- const body = { status: "Canceled" };
800
- await assertDivergentBehavior({
801
- op: runLro({
802
- routes: [
803
- {
804
- method: "DELETE",
805
- status: 202,
806
- headers: {
807
- location: pollingPath,
808
- [headerName]: pollingPath,
809
- "retry-after": "0",
810
- },
811
- },
812
- {
813
- method: "GET",
814
- path: pollingPath,
815
- status: 202,
816
- body: `{"status":"Accepted"}`,
817
- },
818
- {
819
- method: "GET",
820
- path: pollingPath,
821
- status: 200,
822
- body: JSON.stringify(body),
823
- },
824
- ],
825
- }),
826
- throwOnNon2xxResponse,
827
- throwing: {
828
- messagePattern: /Operation was canceled/,
829
- },
830
- notThrowing: {
831
- result: { ...body, statusCode: 200 },
832
- },
833
- });
834
- });
835
-
836
- it("should handle DeleteAsyncRetryFailed", async () => {
837
- const pollingPath = "/deleteasync/retry/failed/operationResults/200/";
838
- const body = { status: "Failed" };
839
- await assertDivergentBehavior({
840
- op: runLro({
841
- routes: [
842
- {
843
- method: "DELETE",
844
- status: 202,
845
- headers: {
846
- location: pollingPath,
847
- [headerName]: pollingPath,
848
- "retry-after": "0",
849
- },
850
- },
851
- {
852
- method: "GET",
853
- path: pollingPath,
854
- status: 202,
855
- headers: {
856
- location: pollingPath,
857
- [headerName]: pollingPath,
858
- "retry-after": "0",
859
- },
860
- body: `{"status":"Accepted"}`,
861
- },
862
- {
863
- method: "GET",
864
- path: pollingPath,
865
- status: 200,
866
- body: JSON.stringify(body),
867
- },
868
- ],
869
- }),
870
- throwOnNon2xxResponse,
871
- throwing: {
872
- messagePattern: /The long-running operation has failed/,
873
- },
874
- notThrowing: {
875
- result: { ...body, statusCode: 200 },
876
- },
877
- });
878
- });
879
-
880
- it("should handle putAsyncRetrySucceeded", async () => {
881
- const path = `/put/noretry/succeeded`;
882
- const pollingPath = "/putasync/noretry/succeeded/operationResults/200/";
883
- const result = await runLro({
884
- routes: [
885
- {
886
- method: "PUT",
887
- path,
888
- status: 200,
889
- headers: {
890
- location: pollingPath,
891
- [headerName]: pollingPath,
892
- },
893
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
894
- },
895
- {
896
- method: "GET",
897
- path: pollingPath,
898
- status: 202,
899
- headers: {
900
- location: pollingPath,
901
- [headerName]: pollingPath,
902
- },
903
- body: `{"status":"Accepted"}`,
904
- },
905
- {
906
- method: "GET",
907
- path: pollingPath,
908
- status: 200,
909
- body: `{"status":"Succeeded"}`,
910
- },
911
- {
912
- method: "GET",
913
- path,
914
- status: 200,
915
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
916
- },
917
- ],
918
- });
919
- assert.equal(result.id, "100");
920
- assert.equal(result.name, "foo");
921
- assert.equal(result.properties?.provisioningState, "Succeeded");
922
- });
923
-
924
- it("should handle post202List", async () => {
925
- const resourceLocationPath = `/list/finalGet`;
926
- const pollingPath = `/list/pollingGet`;
927
- const result = await runLro({
928
- routes: [
929
- {
930
- method: "POST",
931
- status: 200,
932
- headers: {
933
- Location: resourceLocationPath,
934
- [headerName]: pollingPath,
935
- },
936
- },
937
- {
938
- method: "GET",
939
- path: pollingPath,
940
- status: 200,
941
- body: `{ "status": "Succeeded" }`,
942
- },
943
- {
944
- method: "GET",
945
- path: resourceLocationPath,
946
- status: 200,
947
- body: `[{ "id": "100", "name": "foo" }]`,
948
- },
949
- ],
950
- });
951
- assert.equal((result as any)[0].id, "100");
952
- assert.equal((result as any)[0].name, "foo");
953
- });
954
-
955
- it("should handle putAsyncRetryFailed", async () => {
956
- const pollingPath = "/putlocation/retry/failed/operationResults/200/";
957
- const body = { status: "Failed" };
958
- await assertDivergentBehavior({
959
- op: runLro({
960
- routes: [
961
- {
962
- method: "PUT",
963
- status: 200,
964
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
965
- headers: {
966
- location: pollingPath,
967
- [headerName]: pollingPath,
968
- "retry-after": "0",
969
- },
970
- },
971
- {
972
- method: "GET",
973
- path: pollingPath,
974
- status: 202,
975
- headers: {
976
- location: pollingPath,
977
- [headerName]: pollingPath,
978
- "retry-after": "0",
979
- },
980
- body: `{"status":"Accepted"}`,
981
- },
982
- {
983
- method: "GET",
984
- path: pollingPath,
985
- status: 200,
986
- body: JSON.stringify(body),
987
- },
988
- ],
989
- }),
990
- throwOnNon2xxResponse,
991
- throwing: {
992
- messagePattern: /The long-running operation has failed/,
993
- },
994
- notThrowing: {
995
- result: { ...body, statusCode: 200 },
996
- },
997
- });
998
- });
999
-
1000
- it("should handle putAsyncNonResource", async () => {
1001
- const path = `/putnonresource/202/200`;
1002
- const pollingUrl = `/putnonresourceasync/operationresults/123`;
1003
- const result = await runLro({
1004
- routes: [
1005
- {
1006
- method: "PUT",
1007
- path,
1008
- status: 202,
1009
- headers: {
1010
- Location: `somethingBadWhichShouldNotBeUsed`,
1011
- [headerName]: pollingUrl,
1012
- },
1013
- },
1014
- {
1015
- method: "GET",
1016
- path: pollingUrl,
1017
- status: 200,
1018
- body: `{ "status": "InProgress"}`,
1019
- },
1020
- {
1021
- method: "GET",
1022
- path: pollingUrl,
1023
- status: 200,
1024
- body: `{ "status": "Succeeded"}`,
1025
- },
1026
- {
1027
- method: "GET",
1028
- path,
1029
- status: 200,
1030
- body: `{ "name": "sku" , "id": "100" }`,
1031
- },
1032
- ],
1033
- });
1034
- assert.equal(result.name, "sku");
1035
- assert.equal(result.id, "100");
1036
- });
1037
-
1038
- it("should handle patchAsyncLocationHeader", async () => {
1039
- const resourceLocationPath = `/patchasynclocationheader/succeeded`;
1040
- const pollingPath = `/patchasynclocationheader/operationresults/123`;
1041
- const result = await runLro({
1042
- routes: [
1043
- {
1044
- method: "PATCH",
1045
- status: 202,
1046
- headers: {
1047
- Location: resourceLocationPath,
1048
- [headerName]: pollingPath,
1049
- },
1050
- },
1051
- {
1052
- method: "GET",
1053
- path: pollingPath,
1054
- status: 200,
1055
- body: `{ "status": "InProgress"}`,
1056
- headers: {
1057
- "Azure-AsyncOperation": pollingPath,
1058
- },
1059
- },
1060
- {
1061
- method: "GET",
1062
- path: pollingPath,
1063
- status: 200,
1064
- body: `{ "status": "Succeeded"}`,
1065
- },
1066
- {
1067
- method: "GET",
1068
- path: resourceLocationPath,
1069
- status: 200,
1070
- body: `{ "name": "sku" , "id": "100" }`,
1071
- },
1072
- ],
1073
- });
1074
- assert.equal(result.name, "sku");
1075
- assert.equal(result.id, "100");
1076
- });
1077
-
1078
- it("should handle patchAsyncNoLocationHeader", async () => {
1079
- const initialResourcePath = `/patchasyncnolocationheader/succeeded`;
1080
- const pollingPath = `/patchasyncnolocationheader/operationresults/123`;
1081
- const result = await runLro({
1082
- routes: [
1083
- {
1084
- method: "PATCH",
1085
- status: 201,
1086
- path: initialResourcePath,
1087
- headers: {
1088
- [headerName]: pollingPath,
1089
- },
1090
- body: `{ "properties": { "provisioningState": "Updating" } }`,
1091
- },
1092
- {
1093
- method: "GET",
1094
- path: pollingPath,
1095
- status: 200,
1096
- body: `{ "status": "InProgress"}`,
1097
- },
1098
- {
1099
- method: "GET",
1100
- path: pollingPath,
1101
- status: 200,
1102
- body: `{ "status": "Succeeded"}`,
1103
- },
1104
- {
1105
- method: "GET",
1106
- path: initialResourcePath,
1107
- status: 200,
1108
- body: `{ "name": "sku" , "id": "100" }`,
1109
- },
1110
- ],
1111
- });
1112
- assert.equal(result.name, "sku");
1113
- assert.equal(result.id, "100");
1114
- });
1115
-
1116
- it("should handle putAsyncNoHeaderInRetry", async () => {
1117
- const path = `/put/noheader/201/200`;
1118
- const pollingPath = `/putasync/noheader/operationresults/123`;
1119
- const result = await runLro({
1120
- routes: [
1121
- {
1122
- method: "PUT",
1123
- path,
1124
- status: 201,
1125
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "name": "foo" }`,
1126
- headers: {
1127
- Location: `somethingBadWhichShouldNotBeUsed`,
1128
- [headerName]: pollingPath,
1129
- },
1130
- },
1131
- {
1132
- method: "GET",
1133
- path: pollingPath,
1134
- status: 200,
1135
- body: `{ "status": "InProgress"}`,
1136
- },
1137
- {
1138
- method: "GET",
1139
- path: pollingPath,
1140
- status: 200,
1141
- body: `{ "status": "Succeeded"}`,
1142
- },
1143
- {
1144
- method: "GET",
1145
- path,
1146
- status: 200,
1147
- body: `{ "properties": { "provisioningState": "Succeeded"}, "id": "100", "name": "foo" }`,
1148
- },
1149
- ],
1150
- });
1151
- assert.equal(result.name, "foo");
1152
- assert.equal(result.id, "100");
1153
- assert.deepEqual(result.properties?.provisioningState, "Succeeded");
1154
- });
1155
-
1156
- it("should handle putAsyncNoRetrySucceeded", async () => {
1157
- const path = `/put/noretry/succeeded`;
1158
- const pollingPath = "/putlocation/noretry/succeeded/operationResults/200/";
1159
- const result = await runLro({
1160
- routes: [
1161
- {
1162
- method: "PUT",
1163
- path,
1164
- status: 200,
1165
- headers: {
1166
- location: pollingPath,
1167
- [headerName]: pollingPath,
1168
- },
1169
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
1170
- },
1171
- {
1172
- method: "GET",
1173
- path: pollingPath,
1174
- status: 202,
1175
- headers: {
1176
- location: pollingPath,
1177
- [headerName]: pollingPath,
1178
- },
1179
- body: `{"status":"Accepted"}`,
1180
- },
1181
- {
1182
- method: "GET",
1183
- path: pollingPath,
1184
- status: 200,
1185
- body: `{"status":"Succeeded"}`,
1186
- },
1187
- {
1188
- method: "GET",
1189
- path,
1190
- status: 200,
1191
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
1192
- },
1193
- ],
1194
- });
1195
- assert.equal(result.name, "foo");
1196
- assert.equal(result.id, "100");
1197
- });
1198
-
1199
- it("should handle putAsyncNoRetrycanceled", async () => {
1200
- const pollingPath = "/putlocation/noretry/canceled/operationResults/200/";
1201
- const body = { status: "Canceled" };
1202
- await assertDivergentBehavior({
1203
- op: runLro({
1204
- routes: [
1205
- {
1206
- method: "PUT",
1207
- status: 200,
1208
- headers: {
1209
- location: pollingPath,
1210
- [headerName]: pollingPath,
1211
- },
1212
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
1213
- },
1214
- {
1215
- method: "GET",
1216
- path: pollingPath,
1217
- status: 202,
1218
- headers: {
1219
- location: pollingPath,
1220
- [headerName]: pollingPath,
1221
- },
1222
- body: `{"status":"Accepted"}`,
1223
- },
1224
- {
1225
- method: "GET",
1226
- path: pollingPath,
1227
- status: 200,
1228
- headers: {
1229
- location: pollingPath,
1230
- [headerName]: pollingPath,
1231
- },
1232
- body: JSON.stringify(body),
1233
- },
1234
- ],
1235
- }),
1236
- throwOnNon2xxResponse,
1237
- throwing: {
1238
- messagePattern: /Operation was canceled/,
1239
- },
1240
- notThrowing: {
1241
- result: {
1242
- ...body,
1243
- location: pollingPath,
1244
- [headerName.toLocaleLowerCase()]: pollingPath,
1245
- statusCode: 200,
1246
- },
1247
- },
1248
- });
1249
- });
1250
-
1251
- it("should handle putAsyncSubResource", async () => {
1252
- const pollingPath = `/putsubresourceasync/operationresults/123`;
1253
- const path = `/putsubresource/202/200`;
1254
- const result = await runLro({
1255
- routes: [
1256
- {
1257
- method: "PUT",
1258
- path,
1259
- status: 202,
1260
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "subresource": "sub1" }`,
1261
- headers: {
1262
- Location: `somethingBadWhichShouldNotBeUsed`,
1263
- [headerName]: pollingPath,
1264
- },
1265
- },
1266
- {
1267
- method: "GET",
1268
- path: pollingPath,
1269
- status: 200,
1270
- body: `{ "status": "InProgress"}`,
1271
- },
1272
- {
1273
- method: "GET",
1274
- path: pollingPath,
1275
- status: 200,
1276
- body: `{ "status": "Succeeded"}`,
1277
- },
1278
- {
1279
- method: "GET",
1280
- path: path,
1281
- status: 200,
1282
- body: `{ "properties": { "provisioningState": "Succeeded"}, "id": "100", "subresource": "sub1" }`,
1283
- },
1284
- ],
1285
- });
1286
- assert.equal(result.id, "100");
1287
- assert.equal(result.properties?.provisioningState, "Succeeded");
1288
- });
1289
-
1290
- it("should handle deleteAsyncNoHeaderInRetry", async () => {
1291
- const pollingPath = `/deleteasync/noheader/operationresults/123`;
1292
- const response = await runLro({
1293
- routes: [
1294
- {
1295
- method: "DELETE",
1296
- status: 202,
1297
- headers: {
1298
- Location: `somethingBadWhichShouldNotBeUsed`,
1299
- [headerName]: pollingPath,
1300
- },
1301
- },
1302
- {
1303
- method: "GET",
1304
- path: pollingPath,
1305
- status: 200,
1306
- body: `{ "status": "InProgress"}`,
1307
- },
1308
- {
1309
- method: "GET",
1310
- path: pollingPath,
1311
- status: 200,
1312
- body: `{ "status": "Succeeded"}`,
1313
- },
1314
- ],
1315
- });
1316
- assert.equal(response.statusCode, 200);
1317
- });
1318
-
1319
- it("should handle postAsyncNoRetrySucceeded", async () => {
1320
- const locationPath = "/postlocation/noretry/succeeded/operationResults/foo/200/";
1321
- const pollingPath = "/postasync/noretry/succeeded/operationResults/foo/200/";
1322
- const result = await runLro({
1323
- routes: [
1324
- {
1325
- method: "POST",
1326
- status: 202,
1327
- headers: {
1328
- location: locationPath,
1329
- [headerName]: pollingPath,
1330
- },
1331
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
1332
- },
1333
- {
1334
- method: "GET",
1335
- path: pollingPath,
1336
- status: 202,
1337
- body: `{"status":"Accepted"}`,
1338
- headers: {
1339
- location: locationPath,
1340
- [headerName]: pollingPath,
1341
- },
1342
- },
1343
- {
1344
- method: "GET",
1345
- path: pollingPath,
1346
- status: 200,
1347
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
1348
- },
1349
- {
1350
- method: "GET",
1351
- path: locationPath,
1352
- status: 200,
1353
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
1354
- },
1355
- ],
1356
- });
1357
- assert.deepInclude(result, { id: "100", name: "foo" });
1358
- });
1359
-
1360
- it("should handle postAsyncRetryFailed", async () => {
1361
- const pollingPath = "/postlocation/retry/succeeded/operationResults/200/";
1362
- const body = { status: "Failed" };
1363
- await assertDivergentBehavior({
1364
- op: runLro({
1365
- routes: [
1366
- {
1367
- method: "POST",
1368
- status: 202,
1369
- headers: {
1370
- location: "/postlocation/retry/succeeded/operationResults/foo/200/",
1371
- [headerName]: pollingPath,
1372
- "retry-after": "0",
1373
- },
1374
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
1375
- },
1376
- {
1377
- method: "GET",
1378
- path: pollingPath,
1379
- status: 200,
1380
- body: JSON.stringify(body),
1381
- },
1382
- ],
1383
- }),
1384
- throwOnNon2xxResponse,
1385
- throwing: {
1386
- messagePattern: /The long-running operation has failed/,
1387
- },
1388
- notThrowing: {
1389
- result: { ...body, statusCode: 200 },
1390
- },
1391
- });
1392
- });
1393
-
1394
- it("should handle postAsyncRetrySucceeded", async () => {
1395
- const locationPath = "/postlocation/retry/succeeded/operationResults/foo/200/";
1396
- const pollingPath = "/postlocation/retry/succeeded/operationResults/200/";
1397
- const result = await runLro({
1398
- routes: [
1399
- {
1400
- method: "POST",
1401
- status: 202,
1402
- headers: {
1403
- location: locationPath,
1404
- [headerName]: pollingPath,
1405
- "retry-after": "0",
1406
- },
1407
- body: `{"properties":{"provisioningState":"Accepted"},"id":"100","name":"foo"}`,
1408
- },
1409
- {
1410
- method: "GET",
1411
- path: pollingPath,
1412
- status: 202,
1413
- headers: {
1414
- location: locationPath,
1415
- [headerName]: pollingPath,
1416
- "retry-after": "0",
1417
- },
1418
- body: `{"status":"Accepted"}`,
1419
- },
1420
- {
1421
- method: "GET",
1422
- path: pollingPath,
1423
- status: 200,
1424
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
1425
- },
1426
- {
1427
- method: "GET",
1428
- path: locationPath,
1429
- status: 200,
1430
- body: `{"properties":{"provisioningState":"Succeeded"},"id":"100","name":"foo"}`,
1431
- },
1432
- ],
1433
- });
1434
- assert.deepInclude(result, { id: "100", name: "foo" });
1435
- });
1436
-
1437
- it("should handle postAsyncResourceLocation", async () => {
1438
- const locationPath = "/postlocation/retry/succeeded/operationResults/foo/200/";
1439
- const pollingPath = "/postlocation/retry/succeeded/operationResults/200/";
1440
- const result = await runLro({
1441
- routes: [
1442
- {
1443
- method: "POST",
1444
- status: 202,
1445
- headers: {
1446
- [headerName]: pollingPath,
1447
- "retry-after": "0",
1448
- },
1449
- body: `{"status":"Accepted"}`,
1450
- },
1451
- {
1452
- method: "GET",
1453
- path: pollingPath,
1454
- status: 202,
1455
- headers: {
1456
- location: locationPath,
1457
- [headerName]: pollingPath,
1458
- "retry-after": "0",
1459
- },
1460
- body: `{"status":"Accepted"}`,
1461
- },
1462
- {
1463
- method: "GET",
1464
- path: pollingPath,
1465
- status: 200,
1466
- body: `{"status":"Succeeded", "resourceLocation": "${locationPath}"}`,
1467
- },
1468
- {
1469
- method: "GET",
1470
- path: locationPath,
1471
- status: 200,
1472
- body: `{"id":"100","name":"foo"}`,
1473
- },
1474
- ],
1475
- });
1476
- assert.deepInclude(result, { id: "100", name: "foo" });
1477
- });
1478
-
1479
- it("should handle resourceLocation being null", async () => {
1480
- const locationPath = "/postlocation/retry/succeeded/operationResults/foo/200/";
1481
- const pollingPath = "/postlocation/retry/succeeded/operationResults/200/";
1482
- const result = await runLro({
1483
- routes: [
1484
- {
1485
- method: "POST",
1486
- status: 202,
1487
- headers: {
1488
- [headerName]: pollingPath,
1489
- "retry-after": "0",
1490
- },
1491
- body: `{"status":"Accepted"}`,
1492
- },
1493
- {
1494
- method: "GET",
1495
- path: pollingPath,
1496
- status: 202,
1497
- headers: {
1498
- location: locationPath,
1499
- [headerName]: pollingPath,
1500
- "retry-after": "0",
1501
- },
1502
- body: `{"status":"Accepted"}`,
1503
- },
1504
- {
1505
- method: "GET",
1506
- path: pollingPath,
1507
- status: 200,
1508
- body: `{"status":"Succeeded", "resourceLocation": null}`,
1509
- },
1510
- ],
1511
- });
1512
- assert.deepInclude(result, { status: "Succeeded" });
1513
- });
1514
-
1515
- it("should handle postAsyncRetrycanceled", async () => {
1516
- const pollingPath = "/postasync/retry/canceled/operationResults/200/";
1517
- const body = { status: "Canceled" };
1518
- await assertDivergentBehavior({
1519
- op: runLro({
1520
- routes: [
1521
- {
1522
- method: "POST",
1523
- status: 202,
1524
- headers: {
1525
- location: "/postasync/retry/succeeded/operationResults/foo/200/",
1526
- [headerName]: pollingPath,
1527
- "retry-after": "0",
1528
- },
1529
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "name": "foo"}`,
1530
- },
1531
- {
1532
- method: "GET",
1533
- path: pollingPath,
1534
- status: 200,
1535
- body: JSON.stringify(body),
1536
- },
1537
- ],
1538
- }),
1539
- throwOnNon2xxResponse,
1540
- throwing: {
1541
- messagePattern: /Operation was canceled/,
1542
- },
1543
- notThrowing: {
1544
- result: { ...body, statusCode: 200 },
1545
- },
1546
- });
1547
- });
1548
- });
1549
- },
1550
- );
1551
-
1552
- describe("LRO Sad scenarios", () => {
1553
- it("should handle PutNonRetry400 ", async () => {
1554
- await assertDivergentBehavior({
1555
- op: runLro({ routes: [{ method: "PUT", status: 400 }] }),
1556
- throwOnNon2xxResponse,
1557
- throwing: {
1558
- statusCode: 400,
1559
- },
1560
- notThrowing: {
1561
- result: { statusCode: 400 },
1562
- },
1563
- });
1564
- });
1565
-
1566
- it("should handle putNonRetry201Creating400 ", async () => {
1567
- const path = "/nonretryerror/put/201/creating/400";
1568
- const body = { message: "Error from the server" };
1569
- const statusCode = 400;
1570
- await assertDivergentBehavior({
1571
- op: runLro({
1572
- routes: [
1573
- {
1574
- method: "PUT",
1575
- path,
1576
- status: 201,
1577
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1578
- },
1579
- {
1580
- method: "GET",
1581
- path,
1582
- status: statusCode,
1583
- body: JSON.stringify(body),
1584
- },
1585
- ],
1586
- }),
1587
- throwOnNon2xxResponse,
1588
- throwing: {
1589
- statusCode,
1590
- },
1591
- notThrowing: {
1592
- result: { ...body, statusCode },
1593
- },
1594
- });
1595
- });
1596
-
1597
- it("should throw with putNonRetry201Creating400InvalidJson ", async () => {
1598
- const path = "/nonretryerror/put/201/creating/400/invalidjson";
1599
- const body = { message: "Error from the server" };
1600
- const statusCode = 400;
1601
- await assertDivergentBehavior({
1602
- op: runLro({
1603
- routes: [
1604
- {
1605
- method: "PUT",
1606
- path,
1607
- status: 201,
1608
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1609
- },
1610
- {
1611
- method: "GET",
1612
- path,
1613
- status: statusCode,
1614
- body: JSON.stringify(body),
1615
- },
1616
- ],
1617
- }),
1618
- throwOnNon2xxResponse,
1619
- throwing: {
1620
- statusCode,
1621
- },
1622
- notThrowing: {
1623
- result: { ...body, statusCode },
1624
- },
1625
- });
1626
- });
1627
-
1628
- it("should handle putAsyncRelativeRetry400 ", async () => {
1629
- const pollingPath = `/nonretryerror/putasync/retry/failed/operationResults/400`;
1630
- const statusCode = 400;
1631
- await assertDivergentBehavior({
1632
- op: runLro({
1633
- routes: [
1634
- {
1635
- method: "PUT",
1636
- status: 200,
1637
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1638
- headers: createDoubleHeaders({
1639
- pollingPath,
1640
- headers: { "Retry-After": "0" },
1641
- }),
1642
- },
1643
- {
1644
- method: "GET",
1645
- path: pollingPath,
1646
- status: statusCode,
1647
- },
1648
- ],
1649
- }),
1650
- throwOnNon2xxResponse,
1651
- throwing: {
1652
- statusCode,
1653
- },
1654
- notThrowing: {
1655
- result: { statusCode },
1656
- },
1657
- });
1658
- });
1659
-
1660
- it("should handle delete202NonRetry400 ", async () => {
1661
- const path = "/nonretryerror/delete/202/retry/400";
1662
- const body = { message: "Expected bad request message" };
1663
- const statusCode = 400;
1664
- await assertDivergentBehavior({
1665
- op: runLro({
1666
- routes: [
1667
- {
1668
- method: "DELETE",
1669
- path,
1670
- status: 202,
1671
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1672
- headers: {
1673
- Location: path,
1674
- "Retry-After": "0",
1675
- },
1676
- },
1677
- {
1678
- method: "GET",
1679
- path,
1680
- status: statusCode,
1681
- body: JSON.stringify(body),
1682
- },
1683
- ],
1684
- }),
1685
- throwOnNon2xxResponse,
1686
- throwing: {
1687
- statusCode,
1688
- },
1689
- notThrowing: {
1690
- result: { ...body, statusCode },
1691
- },
1692
- });
1693
- });
1694
-
1695
- it("should handle deleteNonRetry400 ", async () => {
1696
- const body = { message: "Expected bad request message" };
1697
- const statusCode = 400;
1698
- await assertDivergentBehavior({
1699
- op: runLro({
1700
- routes: [
1701
- {
1702
- method: "DELETE",
1703
- status: statusCode,
1704
- body: JSON.stringify(body),
1705
- },
1706
- ],
1707
- }),
1708
- throwOnNon2xxResponse,
1709
- throwing: {
1710
- statusCode,
1711
- },
1712
- notThrowing: {
1713
- result: { ...body, statusCode },
1714
- },
1715
- });
1716
- });
1717
-
1718
- it("should handle deleteAsyncRelativeRetry400 ", async () => {
1719
- const pollingPath = `/nonretryerror/deleteasync/retry/failed/operationResults/400`;
1720
- await assertDivergentBehavior({
1721
- op: runLro({
1722
- routes: [
1723
- {
1724
- method: "DELETE",
1725
- status: 202,
1726
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1727
- headers: createDoubleHeaders({
1728
- pollingPath,
1729
- headers: { "Retry-After": "0" },
1730
- }),
1731
- },
1732
- {
1733
- method: "GET",
1734
- path: pollingPath,
1735
- status: 400,
1736
- body: `{ "message" : "Expected bad request message", "status": 200 }`,
1737
- },
1738
- ],
1739
- }),
1740
- throwOnNon2xxResponse,
1741
- throwing: {
1742
- statusCode: 400,
1743
- },
1744
- notThrowing: {
1745
- messagePattern: /Polling was unsuccessful/,
1746
- },
1747
- });
1748
- });
1749
-
1750
- it("should handle postNonRetry400 ", async () => {
1751
- const body = { message: "Expected bad request message" };
1752
- const statusCode = 400;
1753
- await assertDivergentBehavior({
1754
- op: runLro({
1755
- routes: [
1756
- {
1757
- method: "POST",
1758
- status: statusCode,
1759
- body: JSON.stringify(body),
1760
- },
1761
- ],
1762
- }),
1763
- throwOnNon2xxResponse,
1764
- throwing: {
1765
- statusCode,
1766
- },
1767
- notThrowing: {
1768
- result: { ...body, statusCode },
1769
- },
1770
- });
1771
- });
1772
-
1773
- it("should handle post202NonRetry400 ", async () => {
1774
- const path = `/nonretryerror/post/202/retry/400`;
1775
- const body = { message: "Expected bad request message" };
1776
- const statusCode = 400;
1777
- await assertDivergentBehavior({
1778
- op: runLro({
1779
- routes: [
1780
- {
1781
- method: "POST",
1782
- path,
1783
- status: 202,
1784
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1785
- headers: {
1786
- Location: path,
1787
- "Retry-After": "0",
1788
- },
1789
- },
1790
- {
1791
- method: "GET",
1792
- path,
1793
- status: statusCode,
1794
- body: JSON.stringify(body),
1795
- },
1796
- ],
1797
- }),
1798
- throwOnNon2xxResponse,
1799
- throwing: {
1800
- statusCode,
1801
- },
1802
- notThrowing: {
1803
- result: { ...body, statusCode },
1804
- },
1805
- });
1806
- });
1807
-
1808
- it("should handle postAsyncRelativeRetry400 ", async () => {
1809
- const pollingPath = `/nonretryerror/postasync/retry/failed/operationResults/400`;
1810
- await assertDivergentBehavior({
1811
- op: runLro({
1812
- routes: [
1813
- {
1814
- method: "POST",
1815
- status: 202,
1816
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1817
- headers: createDoubleHeaders({
1818
- pollingPath,
1819
- headers: { "Retry-After": "0" },
1820
- }),
1821
- },
1822
- {
1823
- method: "GET",
1824
- path: pollingPath,
1825
- status: 400,
1826
- body: `{ "message" : "Expected bad request message", "status": 400 }`,
1827
- },
1828
- ],
1829
- }),
1830
- throwOnNon2xxResponse,
1831
- throwing: {
1832
- statusCode: 400,
1833
- },
1834
- notThrowing: {
1835
- messagePattern: /Polling was unsuccessful/,
1836
- },
1837
- });
1838
- });
1839
-
1840
- it("should handle PutError201NoProvisioningStatePayload ", async () => {
1841
- const response = await runLro({
1842
- routes: [
1843
- {
1844
- method: "PUT",
1845
- status: 201,
1846
- },
1847
- ],
1848
- });
1849
- assert.equal(response.statusCode, 201); // weird!
1850
- });
1851
-
1852
- it("should handle putAsyncRelativeRetryNoStatusPayload ", async () => {
1853
- const pollingPath = `/error/putasync/retry/failed/operationResults/nostatuspayload`;
1854
- const path = "/error/putasync/retry/nostatuspayload";
1855
- const response = await runLro({
1856
- routes: [
1857
- {
1858
- method: "PUT",
1859
- path,
1860
- status: 200,
1861
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1862
- headers: createDoubleHeaders({
1863
- pollingPath,
1864
- headers: { "Retry-After": "0" },
1865
- }),
1866
- },
1867
- {
1868
- method: "GET",
1869
- path: pollingPath,
1870
- status: 200,
1871
- },
1872
- {
1873
- method: "GET",
1874
- path: path,
1875
- status: 200,
1876
- },
1877
- ],
1878
- });
1879
- assert.equal(response.statusCode, 200);
1880
- });
1881
-
1882
- it("should handle putAsyncRelativeRetryNoStatus ", async () => {
1883
- const path = "/error/putasync/retry/nostatus";
1884
- const pollingPath = `/error/putasync/retry/failed/operationResults/nostatus`;
1885
- const response = await runLro({
1886
- routes: [
1887
- {
1888
- method: "PUT",
1889
- path,
1890
- status: 200,
1891
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
1892
- headers: createDoubleHeaders({
1893
- pollingPath,
1894
- headers: { "Retry-After": "0" },
1895
- }),
1896
- },
1897
- {
1898
- method: "GET",
1899
- path,
1900
- status: 200,
1901
- body: `{ }`,
1902
- },
1903
- {
1904
- method: "GET",
1905
- path: pollingPath,
1906
- status: 200,
1907
- body: `{ }`,
1908
- },
1909
- ],
1910
- });
1911
- assert.equal(response.statusCode, 200);
1912
- });
1913
-
1914
- it("should handle delete204Succeeded ", async () => {
1915
- const response = await runLro({
1916
- routes: [
1917
- {
1918
- method: "DELETE",
1919
- status: 204,
1920
- },
1921
- ],
1922
- });
1923
- assert.equal(response.statusCode, 204);
1924
- });
1925
-
1926
- it("should handle deleteAsyncRelativeRetryNoStatus ", async () => {
1927
- const pollingPath = `/error/deleteasync/retry/failed/operationResults/nostatus`;
1928
- const response = await runLro({
1929
- routes: [
1930
- {
1931
- method: "DELETE",
1932
- status: 202,
1933
- headers: createDoubleHeaders({
1934
- pollingPath,
1935
- headers: { "Retry-After": "0" },
1936
- }),
1937
- },
1938
- {
1939
- method: "GET",
1940
- path: pollingPath,
1941
- status: 200,
1942
- body: `{ }`,
1943
- },
1944
- ],
1945
- });
1946
- assert.equal(response.statusCode, 200);
1947
- });
1948
-
1949
- it("should handle post202NoLocation ", async () => {
1950
- const response = await runLro({
1951
- routes: [
1952
- {
1953
- method: "POST",
1954
- status: 202,
1955
- },
1956
- ],
1957
- });
1958
- assert.equal(response.statusCode, 202);
1959
- });
1960
-
1961
- it("should handle postAsyncRelativeRetryNoPayload ", async () => {
1962
- const pollingPath = `/error/postasync/retry/failed/operationResults/nopayload`;
1963
- const response = await runLro({
1964
- routes: [
1965
- {
1966
- method: "POST",
1967
- status: 202,
1968
- headers: createDoubleHeaders({
1969
- pollingPath,
1970
- headers: { "Retry-After": "0" },
1971
- }),
1972
- },
1973
- {
1974
- method: "GET",
1975
- path: pollingPath,
1976
- status: 200,
1977
- },
1978
- {
1979
- method: "GET",
1980
- path: pollingPath,
1981
- status: 200,
1982
- },
1983
- ],
1984
- });
1985
- assert.equal(response.statusCode, 200);
1986
- });
1987
-
1988
- it("should handle put200InvalidJson ", async () => {
1989
- await assertError(
1990
- runLro({
1991
- routes: [
1992
- {
1993
- method: "PUT",
1994
- status: 200,
1995
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo"`,
1996
- },
1997
- ],
1998
- }),
1999
- {
2000
- name: "SyntaxError",
2001
- },
2002
- );
2003
- });
2004
-
2005
- it("should handle putAsyncRelativeRetryInvalidHeader ", async () => {
2006
- await assertDivergentBehavior({
2007
- op: runLro({
2008
- routes: [
2009
- {
2010
- method: "PUT",
2011
- status: 200,
2012
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
2013
- headers: createDoubleHeaders({
2014
- pollingPath: "/foo",
2015
- headers: { "Retry-After": "/bar" },
2016
- }),
2017
- },
2018
- ],
2019
- }),
2020
- throwOnNon2xxResponse,
2021
- throwing: {
2022
- statusCode: 404,
2023
- },
2024
- notThrowing: {
2025
- partResult: {
2026
- statusCode: 404,
2027
- },
2028
- },
2029
- });
2030
- });
2031
-
2032
- it("should handle putAsyncRelativeRetryInvalidJsonPolling ", async () => {
2033
- const pollingPath = `/error/putasync/retry/failed/operationResults/invalidjsonpolling`;
2034
- await assertError(
2035
- runLro({
2036
- routes: [
2037
- {
2038
- method: "PUT",
2039
- status: 200,
2040
- body: `{ "properties": { "provisioningState": "Creating"}, "id": "100", "name": "foo" }`,
2041
- headers: createDoubleHeaders({
2042
- pollingPath,
2043
- headers: { "Retry-After": "0" },
2044
- }),
2045
- },
2046
- {
2047
- method: "GET",
2048
- path: pollingPath,
2049
- status: 200,
2050
- body: `{ "status": "Accepted"`,
2051
- },
2052
- ],
2053
- }),
2054
- {
2055
- name: "SyntaxError",
2056
- },
2057
- );
2058
- });
2059
-
2060
- it("should handle delete202RetryInvalidHeader ", async () => {
2061
- await assertDivergentBehavior({
2062
- op: runLro({
2063
- routes: [
2064
- {
2065
- method: "DELETE",
2066
- status: 202,
2067
- headers: {
2068
- Location: `/foo`,
2069
- "Retry-After": "/bar",
2070
- },
2071
- },
2072
- ],
2073
- }),
2074
- throwOnNon2xxResponse,
2075
- throwing: {
2076
- statusCode: 404,
2077
- },
2078
- notThrowing: {
2079
- partResult: {
2080
- statusCode: 404,
2081
- },
2082
- },
2083
- });
2084
- });
2085
-
2086
- it("should handle deleteAsyncRelativeRetryInvalidHeader ", async () => {
2087
- await assertDivergentBehavior({
2088
- op: runLro({
2089
- routes: [
2090
- {
2091
- method: "DELETE",
2092
- status: 202,
2093
- headers: createDoubleHeaders({
2094
- pollingPath: "/foo",
2095
- headers: { "Retry-After": "/bar" },
2096
- }),
2097
- },
2098
- ],
2099
- }),
2100
- throwOnNon2xxResponse,
2101
- throwing: {
2102
- statusCode: 404,
2103
- },
2104
- notThrowing: {
2105
- partResult: {
2106
- statusCode: 404,
2107
- },
2108
- },
2109
- });
2110
- });
2111
-
2112
- it("should handle DeleteAsyncRelativeRetryInvalidJsonPolling ", async () => {
2113
- const pollingPath = `/error/deleteasync/retry/failed/operationResults/invalidjsonpolling`;
2114
- await assertError(
2115
- runLro({
2116
- routes: [
2117
- {
2118
- method: "DELETE",
2119
- status: 202,
2120
- headers: createDoubleHeaders({
2121
- pollingPath,
2122
- headers: { "Retry-After": "0" },
2123
- }),
2124
- },
2125
- {
2126
- method: "GET",
2127
- path: pollingPath,
2128
- status: 200,
2129
- body: `{ "status": "Accepted"`,
2130
- },
2131
- ],
2132
- }),
2133
- {
2134
- name: "SyntaxError",
2135
- },
2136
- );
2137
- });
2138
-
2139
- it("should handle post202RetryInvalidHeader ", async () => {
2140
- await assertDivergentBehavior({
2141
- op: runLro({
2142
- routes: [
2143
- {
2144
- method: "POST",
2145
- status: 202,
2146
- headers: {
2147
- Location: `/foo`,
2148
- "Retry-After": "/bar",
2149
- },
2150
- },
2151
- ],
2152
- }),
2153
- throwOnNon2xxResponse,
2154
- throwing: {
2155
- statusCode: 404,
2156
- },
2157
- notThrowing: {
2158
- partResult: {
2159
- statusCode: 404,
2160
- },
2161
- },
2162
- });
2163
- });
2164
-
2165
- it("should handle postAsyncRelativeRetryInvalidHeader ", async () => {
2166
- await assertDivergentBehavior({
2167
- op: runLro({
2168
- routes: [
2169
- {
2170
- method: "POST",
2171
- status: 202,
2172
- headers: createDoubleHeaders({
2173
- pollingPath: "/foo",
2174
- headers: { "Retry-After": "/bar" },
2175
- }),
2176
- },
2177
- ],
2178
- }),
2179
- throwOnNon2xxResponse,
2180
- throwing: {
2181
- statusCode: 404,
2182
- },
2183
- notThrowing: {
2184
- partResult: {
2185
- statusCode: 404,
2186
- },
2187
- },
2188
- });
2189
- });
2190
-
2191
- it("should handle postAsyncRelativeRetryInvalidJsonPolling ", async () => {
2192
- const pollingPath = `/error/postasync/retry/failed/operationResults/invalidjsonpolling`;
2193
- await assertError(
2194
- runLro({
2195
- routes: [
2196
- {
2197
- method: "POST",
2198
- status: 202,
2199
- headers: createDoubleHeaders({
2200
- pollingPath,
2201
- headers: { "Retry-After": "/bar" },
2202
- }),
2203
- },
2204
- {
2205
- method: "GET",
2206
- path: pollingPath,
2207
- status: 200,
2208
- body: `{ "status": "Accepted"`,
2209
- },
2210
- ],
2211
- }),
2212
- {
2213
- name: "SyntaxError",
2214
- },
2215
- );
2216
- });
2217
- });
2218
-
2219
- describe("rehydration LRO", () => {
2220
- // fake LRO which means no polling and the initial response would returnt the result directly
2221
- it("could handle rehydration for fake LRO", async () => {
2222
- const bodyObj = {
2223
- properties: { provisioningState: "Succeeded" },
2224
- id: "100",
2225
- name: "foo",
2226
- };
2227
- const retResult = {
2228
- ...bodyObj,
2229
- statusCode: 200,
2230
- };
2231
-
2232
- const poller = createTestPoller({
2233
- routes: [
2234
- {
2235
- method: "PUT",
2236
- status: 200,
2237
- body: JSON.stringify(bodyObj),
2238
- },
2239
- ],
2240
- implName,
2241
- throwOnNon2xxResponse,
2242
- });
2243
- assert.isUndefined(poller.operationState);
2244
- const serialized = await poller.serialize();
2245
- const expectedSerialized = JSON.stringify({
2246
- state: {
2247
- status: "succeeded",
2248
- config: {
2249
- metadata: { mode: "Body" },
2250
- operationLocation: "path",
2251
- initialUrl: "path",
2252
- requestMethod: "PUT",
2253
- },
2254
- result: retResult,
2255
- },
2256
- });
2257
- assert.equal(serialized, expectedSerialized);
2258
- assert.equal(poller.operationState.status, "succeeded");
2259
- const restoredPoller = createTestPoller({
2260
- routes: [],
2261
- restoreFrom: serialized,
2262
- implName,
2263
- throwOnNon2xxResponse,
2264
- });
2265
- assert.equal(serialized, await restoredPoller.serialize());
2266
- assert.equal(poller.operationState.status, "succeeded");
2267
- assert.deepEqual(poller.result, retResult);
2268
- });
2269
-
2270
- it("could handle rehydration for real LRO", async () => {
2271
- const bodyObj = {
2272
- properties: { provisioningState: "Succeeded" },
2273
- id: "100",
2274
- name: "foo",
2275
- };
2276
- const retResult: Result = {
2277
- ...bodyObj,
2278
- statusCode: 200,
2279
- };
2280
- const pollingPath = `pollingPath`;
2281
- let pollCount = 0;
2282
- const pollingRoutes = [
2283
- ...Array(10).fill({
2284
- method: "GET",
2285
- path: pollingPath,
2286
- body: `{ "status": "running" }`,
2287
- status: 200,
2288
- }),
2289
- {
2290
- method: "GET",
2291
- path: pollingPath,
2292
- body: JSON.stringify(bodyObj),
2293
- status: 200,
2294
- },
2295
- ];
2296
- const poller = createTestPoller({
2297
- routes: [
2298
- {
2299
- method: "POST",
2300
- status: 202,
2301
- headers: {
2302
- "Operation-Location": pollingPath,
2303
- },
2304
- },
2305
- ],
2306
- throwOnNon2xxResponse,
2307
- implName,
2308
- updateState: () => {
2309
- pollCount++;
2310
- },
2311
- });
2312
- assert.isUndefined(poller.operationState);
2313
- const serialized = await poller.serialize();
2314
- assert.equal(pollCount, 0);
2315
- const expectedSerialized = JSON.stringify({
2316
- state: {
2317
- status: "running",
2318
- config: {
2319
- metadata: { mode: "OperationLocation" },
2320
- operationLocation: "pollingPath",
2321
- initialUrl: "path",
2322
- requestMethod: "POST",
2323
- },
2324
- },
2325
- });
2326
- assert.equal(serialized, expectedSerialized);
2327
- assert.equal(poller.operationState.status, "running");
2328
- pollCount = 0;
2329
- const restoredPoller = createTestPoller({
2330
- routes: pollingRoutes,
2331
- restoreFrom: serialized,
2332
- implName,
2333
- throwOnNon2xxResponse,
2334
- updateState: () => {
2335
- pollCount++;
2336
- },
2337
- });
2338
- assert.equal(pollCount, 0);
2339
- assert.deepEqual(retResult, await restoredPoller);
2340
- assert.equal(pollCount, 11);
2341
- assert.equal(restoredPoller.operationState.status, "succeeded");
2342
- assert.deepEqual(restoredPoller.result, retResult);
2343
- assert.isUndefined(poller.result);
2344
- // duplicate awaitting would not trigger extra pollings
2345
- await restoredPoller;
2346
- assert.equal(pollCount, 11);
2347
- });
2348
- });
2349
-
2350
- describe("mutate state", () => {
2351
- it("The state can be mutated in onProgress", async () => {
2352
- let setState = false;
2353
- let check = false;
2354
- const pollingPath = `pollingPath`;
2355
- await runLro({
2356
- routes: [
2357
- {
2358
- method: "POST",
2359
- status: 202,
2360
- headers: {
2361
- "Operation-Location": pollingPath,
2362
- },
2363
- },
2364
- {
2365
- method: "GET",
2366
- path: pollingPath,
2367
- status: 200,
2368
- body: `{ "status": "running" }`,
2369
- },
2370
- {
2371
- method: "GET",
2372
- path: pollingPath,
2373
- status: 200,
2374
- body: `{ "status": "running" }`,
2375
- },
2376
- {
2377
- method: "GET",
2378
- path: pollingPath,
2379
- status: 200,
2380
- body: `{ "status": "succeeded" }`,
2381
- },
2382
- ],
2383
- onProgress: (state) => {
2384
- if (!setState) {
2385
- (state as any).x = 1;
2386
- setState = true;
2387
- } else {
2388
- assert.ok((state as any).x);
2389
- check = true;
2390
- }
2391
- },
2392
- });
2393
- assert.isTrue(check);
2394
- });
2395
-
2396
- it("The state can be mutated in updateState", async () => {
2397
- let setState = false;
2398
- let check = false;
2399
- const pollingPath = `pollingPath`;
2400
- await runLro({
2401
- routes: [
2402
- {
2403
- method: "POST",
2404
- status: 202,
2405
- headers: {
2406
- "Operation-Location": pollingPath,
2407
- },
2408
- },
2409
- {
2410
- method: "GET",
2411
- path: pollingPath,
2412
- status: 200,
2413
- body: `{ "status": "running" }`,
2414
- },
2415
- {
2416
- method: "GET",
2417
- path: pollingPath,
2418
- status: 200,
2419
- body: `{ "status": "running" }`,
2420
- },
2421
- {
2422
- method: "GET",
2423
- path: pollingPath,
2424
- status: 200,
2425
- body: `{ "status": "succeeded" }`,
2426
- },
2427
- ],
2428
- updateState: (state: any) => {
2429
- if (!setState) {
2430
- (state as any).x = 1;
2431
- setState = true;
2432
- } else {
2433
- assert.ok((state as any).x);
2434
- check = true;
2435
- }
2436
- },
2437
- });
2438
- assert.isTrue(check);
2439
- });
2440
- });
2441
-
2442
- describe("process result", () => {
2443
- it("From a location response", async () => {
2444
- const locationPath = "/postlocation/noretry/succeeded/operationResults/foo/200/";
2445
- const pollingPath = "/postasync/noretry/succeeded/operationResults/foo/200/";
2446
- const headerName = "Operation-Location";
2447
- const result = await runLro({
2448
- routes: [
2449
- {
2450
- method: "POST",
2451
- status: 202,
2452
- headers: {
2453
- location: locationPath,
2454
- [headerName]: pollingPath,
2455
- },
2456
- body: `{ "properties": { "provisioningState": "Accepted" }, "id": "100", "name": "foo" }`,
2457
- },
2458
- {
2459
- method: "GET",
2460
- path: pollingPath,
2461
- status: 202,
2462
- body: `{ "status": "Accepted" }`,
2463
- headers: {
2464
- location: locationPath,
2465
- [headerName]: pollingPath,
2466
- },
2467
- },
2468
- {
2469
- method: "GET",
2470
- path: pollingPath,
2471
- status: 200,
2472
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2473
- },
2474
- {
2475
- method: "GET",
2476
- path: locationPath,
2477
- status: 200,
2478
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2479
- },
2480
- ],
2481
- processResult: (res: unknown) => {
2482
- assert.equal((res as any).id, "100");
2483
- return { ...(res as any), id: "200" };
2484
- },
2485
- });
2486
- assert.deepInclude(result, { id: "200", name: "foo" });
2487
- });
2488
-
2489
- it("From the initial response", async () => {
2490
- const result = await runLro({
2491
- routes: [
2492
- {
2493
- method: "PUT",
2494
- status: 200,
2495
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2496
- },
2497
- ],
2498
- processResult: (res: unknown) => {
2499
- assert.equal((res as any).id, "100");
2500
- return { ...(res as any), id: "200" };
2501
- },
2502
- });
2503
- assert.deepInclude(result, { id: "200", name: "foo" });
2504
- });
2505
- });
2506
-
2507
- describe("poller cancellation", () => {
2508
- it("cancelled poller gives access to partial results", async () => {
2509
- const body = { status: "canceled", results: [1, 2] };
2510
- const pollingPath = "/LROPostDoubleHeadersFinalAzureHeaderGetDefault/asyncOperationUrl";
2511
- const poller = createTestPoller({
2512
- routes: [
2513
- {
2514
- method: "POST",
2515
- status: 202,
2516
- body: "",
2517
- headers: {
2518
- "Operation-Location": pollingPath,
2519
- },
2520
- },
2521
- {
2522
- method: "GET",
2523
- path: pollingPath,
2524
- status: 200,
2525
- body: `{ "status": "running" }`,
2526
- },
2527
- {
2528
- method: "GET",
2529
- path: pollingPath,
2530
- status: 200,
2531
- body: JSON.stringify(body),
2532
- },
2533
- ],
2534
- throwOnNon2xxResponse,
2535
- implName,
2536
- });
2537
- await assertDivergentBehavior({
2538
- op: poller.pollUntilDone(),
2539
- throwOnNon2xxResponse,
2540
- throwing: {
2541
- messagePattern: /Operation was canceled/,
2542
- },
2543
- notThrowing: {
2544
- result: { ...body, statusCode: 200 },
2545
- },
2546
- });
2547
- assert.deepEqual(poller.result!.results, [1, 2]);
2548
- });
2549
- });
2550
- describe("abort signals", function () {
2551
- it("poll can be aborted", async () => {
2552
- let pollCount = 0;
2553
- const pollingPath = "pollingPath";
2554
- const poller = createTestPoller({
2555
- routes: [
2556
- {
2557
- method: "POST",
2558
- status: 202,
2559
- headers: {
2560
- "Operation-Location": pollingPath,
2561
- },
2562
- },
2563
- ...Array(10).fill({
2564
- method: "GET",
2565
- path: pollingPath,
2566
- body: `{ "status": "running" }`,
2567
- status: 200,
2568
- }),
2569
- {
2570
- method: "GET",
2571
- path: pollingPath,
2572
- body: `{ "status": "succeeded" }`,
2573
- status: 200,
2574
- },
2575
- ],
2576
- implName,
2577
- throwOnNon2xxResponse,
2578
- updateState: () => {
2579
- pollCount++;
2580
- },
2581
- });
2582
- const abortController = new AbortController();
2583
- await poller.poll();
2584
- abortController.abort();
2585
- assert.equal(pollCount, 1);
2586
- await assertError(
2587
- poller.poll({
2588
- abortSignal: abortController.signal,
2589
- }),
2590
- {
2591
- messagePattern: /The operation was aborted/,
2592
- },
2593
- );
2594
- assert.isFalse(poller.isDone);
2595
- });
2596
-
2597
- it("pollUntilDone can be aborted", async () => {
2598
- let pollCount = 0;
2599
- const pollingPath = "pollingPath";
2600
- const poller = createTestPoller({
2601
- routes: [
2602
- {
2603
- method: "POST",
2604
- status: 202,
2605
- headers: {
2606
- "Operation-Location": pollingPath,
2607
- },
2608
- },
2609
- ...Array(10).fill({
2610
- method: "GET",
2611
- path: pollingPath,
2612
- body: `{ "status": "running" }`,
2613
- status: 200,
2614
- }),
2615
- {
2616
- method: "GET",
2617
- path: pollingPath,
2618
- body: `{ "status": "succeeded" }`,
2619
- status: 200,
2620
- },
2621
- ],
2622
- throwOnNon2xxResponse,
2623
- implName,
2624
- updateState: () => {
2625
- pollCount++;
2626
- },
2627
- });
2628
- const abortController = new AbortController();
2629
- await poller.poll();
2630
- abortController.abort();
2631
- assert.equal(pollCount, 1);
2632
- await assertError(
2633
- poller.pollUntilDone({
2634
- abortSignal: abortController.signal,
2635
- }),
2636
- {
2637
- messagePattern: /The operation was aborted/,
2638
- },
2639
- );
2640
- assert.equal(pollCount, 1);
2641
- assert.isFalse(poller.isDone);
2642
- });
2643
-
2644
- it("pollUntilDone is aborted when pollCount = 10", async () => {
2645
- let pollCount = 0;
2646
- const pollingPath = "pollingPath";
2647
- const abortController = new AbortController();
2648
- const poller = createTestPoller({
2649
- routes: [
2650
- {
2651
- method: "POST",
2652
- status: 202,
2653
- headers: {
2654
- "Operation-Location": pollingPath,
2655
- },
2656
- },
2657
- ...Array(20).fill({
2658
- method: "GET",
2659
- path: pollingPath,
2660
- body: `{ "status": "running" }`,
2661
- status: 200,
2662
- }),
2663
- {
2664
- method: "GET",
2665
- path: pollingPath,
2666
- body: `{ "status": "succeeded" }`,
2667
- status: 200,
2668
- },
2669
- ],
2670
- throwOnNon2xxResponse,
2671
- implName,
2672
- updateState: () => {
2673
- pollCount++;
2674
- if (pollCount === 10) {
2675
- abortController.abort();
2676
- }
2677
- },
2678
- });
2679
- await poller.poll();
2680
- assert.equal(pollCount, 1);
2681
- const promise = poller.pollUntilDone({
2682
- abortSignal: abortController.signal,
2683
- });
2684
- await assertError(promise);
2685
- assert.equal(pollCount, 10);
2686
- assert.isFalse(poller.isDone);
2687
- });
2688
- });
2689
- describe("general behavior", function () {
2690
- it("awaitting poller would return result directly", async () => {
2691
- const bodyObj = {
2692
- properties: { provisioningState: "Succeeded" },
2693
- id: "100",
2694
- name: "foo",
2695
- };
2696
- const retResult: Result = {
2697
- ...bodyObj,
2698
- statusCode: 200,
2699
- };
2700
- const pollingPath = `pollingPath`;
2701
- let pollCount = 0;
2702
- const pollingRoutes = [
2703
- {
2704
- method: "POST",
2705
- status: 202,
2706
- headers: {
2707
- "Operation-Location": pollingPath,
2708
- },
2709
- },
2710
- ...Array(10).fill({
2711
- method: "GET",
2712
- path: pollingPath,
2713
- body: `{ "status": "running" }`,
2714
- status: 200,
2715
- }),
2716
- {
2717
- method: "GET",
2718
- path: pollingPath,
2719
- body: JSON.stringify(bodyObj),
2720
- status: 200,
2721
- },
2722
- ];
2723
- const poller = createTestPoller({
2724
- routes: pollingRoutes,
2725
- throwOnNon2xxResponse,
2726
- implName,
2727
- updateState: () => {
2728
- pollCount++;
2729
- },
2730
- });
2731
- assert.isUndefined(poller.operationState);
2732
- assert.isUndefined(poller.result);
2733
- assert.equal(pollCount, 0);
2734
- const result = await poller;
2735
- assert.deepEqual(retResult, result);
2736
- assert.equal(pollCount, 11);
2737
- assert.equal(poller.operationState.status, "succeeded");
2738
- assert.deepEqual(poller.result, retResult);
2739
- assert.equal(poller.result, result);
2740
- // duplicate awaitting would not trigger extra pollings
2741
- await poller;
2742
- assert.equal(pollCount, 11);
2743
- });
2744
- it("poll() doesn't poll after the poller is in a succeed status", async function () {
2745
- const poller = createTestPoller({
2746
- routes: [
2747
- {
2748
- method: "PUT",
2749
- status: 200,
2750
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2751
- },
2752
- ],
2753
- throwOnNon2xxResponse,
2754
- });
2755
- await poller.poll(); // This will fail if a polling request is sent
2756
- const result = await poller.pollUntilDone();
2757
- assert.equal(result.properties?.provisioningState, "Succeeded");
2758
- });
2759
- it("poll() doesn't poll after the poller is in a failed status", async function () {
2760
- const bodyObj = { properties: { provisioningState: "Failed" }, id: "100", name: "foo" };
2761
- const poller = createTestPoller({
2762
- routes: [
2763
- {
2764
- method: "PUT",
2765
- status: 200,
2766
- body: JSON.stringify(bodyObj),
2767
- },
2768
- ],
2769
- throwOnNon2xxResponse,
2770
- });
2771
- const pollerState = {
2772
- status: "failed",
2773
- config: {
2774
- metadata: { mode: "Body" },
2775
- operationLocation: "path",
2776
- resourceLocation: undefined,
2777
- initialUrl: "path",
2778
- requestMethod: "PUT",
2779
- },
2780
- result: {
2781
- ...bodyObj,
2782
- statusCode: 200,
2783
- },
2784
- };
2785
- await assertDivergentBehavior({
2786
- op: poller.poll(),
2787
- notThrowing: {
2788
- partResult: pollerState,
2789
- },
2790
- throwing: {
2791
- messagePattern: /failed/,
2792
- },
2793
- throwOnNon2xxResponse,
2794
- });
2795
- await assertDivergentBehavior({
2796
- op: poller.pollUntilDone(),
2797
- notThrowing: {
2798
- result: { ...bodyObj, statusCode: 200 },
2799
- },
2800
- throwing: {
2801
- messagePattern: /failed/,
2802
- },
2803
- throwOnNon2xxResponse,
2804
- });
2805
- });
2806
- it("poll() doesn't poll after the poller is in a canceled status", async function () {
2807
- const bodyObj = { properties: { provisioningState: "Canceled" }, id: "100", name: "foo" };
2808
- const poller = createTestPoller({
2809
- routes: [
2810
- {
2811
- method: "PUT",
2812
- status: 200,
2813
- body: JSON.stringify(bodyObj),
2814
- },
2815
- ],
2816
- throwOnNon2xxResponse,
2817
- });
2818
- await assertDivergentBehavior({
2819
- op: poller.poll(),
2820
- notThrowing: {
2821
- partResult: {
2822
- result: {
2823
- ...bodyObj,
2824
- statusCode: 200,
2825
- },
2826
- },
2827
- },
2828
- throwing: {
2829
- messagePattern: /canceled/,
2830
- },
2831
- throwOnNon2xxResponse,
2832
- });
2833
- await assertDivergentBehavior({
2834
- op: poller.pollUntilDone(),
2835
- notThrowing: {
2836
- result: { ...bodyObj, statusCode: 200 },
2837
- },
2838
- throwing: {
2839
- messagePattern: /canceled/,
2840
- },
2841
- throwOnNon2xxResponse,
2842
- });
2843
- assert.equal(poller.result?.properties?.provisioningState, "Canceled");
2844
- });
2845
- it("prints an error message based on the error in the status monitor", async () => {
2846
- const pollingPath = "/postlocation/retry/succeeded/operationResults/200/";
2847
- const code = "InvalidRequest";
2848
- const message = "Bad Request";
2849
- const body = { status: "Failed", error: { code, message } };
2850
- await assertDivergentBehavior({
2851
- op: runLro({
2852
- routes: [
2853
- {
2854
- method: "POST",
2855
- status: 202,
2856
- headers: {
2857
- "Operation-Location": pollingPath,
2858
- },
2859
- body: `{ "status": "Running" }`,
2860
- },
2861
- {
2862
- method: "GET",
2863
- path: pollingPath,
2864
- status: 200,
2865
- body: JSON.stringify(body),
2866
- },
2867
- ],
2868
- }),
2869
- throwOnNon2xxResponse,
2870
- throwing: {
2871
- messagePattern: new RegExp(
2872
- `The long-running operation has failed. ${code}. ${message}`,
2873
- ),
2874
- },
2875
- notThrowing: {
2876
- result: { ...body, statusCode: 200 },
2877
- },
2878
- });
2879
- });
2880
- it("processResult() could be asynchronized", async () => {
2881
- const processResult = async (res: unknown): Promise<Result> => {
2882
- await delay(1);
2883
- return { statusCode: (res as Result).statusCode } as Result;
2884
- };
2885
- const poller = createTestPoller({
2886
- routes: [
2887
- {
2888
- method: "PUT",
2889
- status: 200,
2890
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2891
- },
2892
- ],
2893
- throwOnNon2xxResponse,
2894
- processResult,
2895
- });
2896
- const result = await poller.pollUntilDone();
2897
- assert.equal(result.statusCode, 200);
2898
- assert.isUndefined(result.properties?.provisioningState);
2899
- });
2900
- it("processResult() could be synchronized", async () => {
2901
- const processResult = async (res: unknown): Promise<Result> => {
2902
- return { statusCode: (res as Result).statusCode } as Result;
2903
- };
2904
- const poller = createTestPoller({
2905
- routes: [
2906
- {
2907
- method: "PUT",
2908
- status: 200,
2909
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2910
- },
2911
- ],
2912
- throwOnNon2xxResponse,
2913
- processResult,
2914
- });
2915
- const result = await poller.pollUntilDone();
2916
- assert.equal(result.statusCode, 200);
2917
- assert.isUndefined(result.properties?.provisioningState);
2918
- });
2919
- it("submitted() is resolved once the initial response is back and poller state is ready", async () => {
2920
- let pollCount = 0;
2921
- const pollingPath = "pollingPath";
2922
- const poller = createTestPoller({
2923
- routes: [
2924
- {
2925
- method: "POST",
2926
- status: 202,
2927
- headers: {
2928
- "Operation-Location": pollingPath,
2929
- },
2930
- },
2931
- ...Array(10).fill({
2932
- method: "GET",
2933
- path: pollingPath,
2934
- body: `{ "status": "running" }`,
2935
- status: 200,
2936
- }),
2937
- {
2938
- method: "GET",
2939
- path: pollingPath,
2940
- body: `{ "status": "succeeded" }`,
2941
- status: 200,
2942
- },
2943
- ],
2944
- implName,
2945
- throwOnNon2xxResponse,
2946
- updateState: () => {
2947
- pollCount++;
2948
- },
2949
- });
2950
- assert.isUndefined(poller.operationState);
2951
- await poller.submitted();
2952
- assert.equal(pollCount, 0);
2953
- assert.equal(poller.operationState.status, "running");
2954
- });
2955
-
2956
- it("readonly attributes would throw errors if trying to override the value", async () => {
2957
- try {
2958
- const poller = createTestPoller({
2959
- routes: [
2960
- {
2961
- method: "PUT",
2962
- status: 200,
2963
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2964
- },
2965
- ],
2966
- throwOnNon2xxResponse,
2967
- });
2968
- (poller as any).operationState = "foostatus";
2969
- assert.fail("should throw error");
2970
- } catch (e: any) {
2971
- assert.equal(
2972
- e.message,
2973
- "Cannot set property operationState of #<Object> which has only a getter",
2974
- );
2975
- }
2976
- });
2977
- });
2978
-
2979
- describe("promise poller", () => {
2980
- describe("await the same poller in multiple times", () => {
2981
- it("should be the same result", async () => {
2982
- const poller = createTestPoller({
2983
- routes: [
2984
- {
2985
- method: "PUT",
2986
- status: 200,
2987
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
2988
- },
2989
- ],
2990
- throwOnNon2xxResponse,
2991
- });
2992
- const await1 = await poller;
2993
- const await2 = await poller;
2994
- const await3 = await poller;
2995
- assert.equal(await1.statusCode, 200);
2996
- assert.isTrue(await1 === await2);
2997
- assert.isTrue(await1 === await3);
2998
- });
2999
- it("thenable should return the same result", async () => {
3000
- const poller = createTestPoller({
3001
- routes: [
3002
- {
3003
- method: "PUT",
3004
- status: 200,
3005
- body: `{ "properties": { "provisioningState": "Succeeded" }, "id": "100", "name": "foo" }`,
3006
- },
3007
- ],
3008
- throwOnNon2xxResponse,
3009
- });
3010
- const await1 = await poller.then((result) => {
3011
- assert.equal(result.statusCode, 200);
3012
- return result;
3013
- });
3014
- const await2 = await poller.then((result) => {
3015
- assert.equal(result.statusCode, 200);
3016
- return result;
3017
- });
3018
- assert.isTrue(await1 === await2);
3019
- });
3020
- it("should trigger the whole polling process to server side only once", async () => {
3021
- let pollCount = 0;
3022
- const pollingPath = "pollingPath";
3023
- const poller = createTestPoller({
3024
- routes: [
3025
- {
3026
- method: "POST",
3027
- status: 202,
3028
- headers: {
3029
- "Operation-Location": pollingPath,
3030
- },
3031
- },
3032
- ...Array(10).fill({
3033
- method: "GET",
3034
- path: pollingPath,
3035
- body: `{ "status": "running" }`,
3036
- status: 200,
3037
- }),
3038
- {
3039
- method: "GET",
3040
- path: pollingPath,
3041
- body: `{ "status": "succeeded" }`,
3042
- status: 200,
3043
- },
3044
- ],
3045
- implName,
3046
- throwOnNon2xxResponse,
3047
- updateState: () => {
3048
- pollCount++;
3049
- },
3050
- });
3051
- await poller;
3052
- await poller;
3053
- await poller;
3054
- assert.equal(pollCount, 11);
3055
- });
3056
- it("should catch the same error in multiple times", async () => {
3057
- const body = { status: "canceled", results: [1, 2] };
3058
- const errMsg = "Operation was canceled";
3059
- const pollingPath = "/LROPostDoubleHeadersFinalAzureHeaderGetDefault/asyncOperationUrl";
3060
- const poller = createTestPoller({
3061
- routes: [
3062
- {
3063
- method: "POST",
3064
- status: 202,
3065
- headers: {
3066
- location: "/postasync/retry/succeeded/operationResults/foo/200/",
3067
- ["Operation-Location"]: pollingPath,
3068
- "retry-after": "0",
3069
- },
3070
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "name": "foo"}`,
3071
- },
3072
- {
3073
- method: "GET",
3074
- path: pollingPath,
3075
- status: 200,
3076
- body: JSON.stringify(body),
3077
- },
3078
- ],
3079
- implName,
3080
- throwOnNon2xxResponse: true,
3081
- });
3082
- try {
3083
- await poller;
3084
- assert.fail("should throw error");
3085
- } catch (e: any) {
3086
- assert.equal(e.message, errMsg);
3087
- }
3088
- try {
3089
- await poller;
3090
- assert.fail("should throw error");
3091
- } catch (e: any) {
3092
- assert.equal(e.message, errMsg);
3093
- }
3094
- });
3095
- it("should work properly when mixing catch and await", async () => {
3096
- const body = { status: "canceled", results: [1, 2] };
3097
- const errMsg = "Operation was canceled";
3098
- const pollingPath = "/LROPostDoubleHeadersFinalAzureHeaderGetDefault/asyncOperationUrl";
3099
- const poller = createTestPoller({
3100
- routes: [
3101
- {
3102
- method: "POST",
3103
- status: 202,
3104
- headers: {
3105
- location: "/postasync/retry/succeeded/operationResults/foo/200/",
3106
- ["Operation-Location"]: pollingPath,
3107
- "retry-after": "0",
3108
- },
3109
- body: `{ "properties": { "provisioningState": "Accepted"}, "id": "100", "name": "foo"}`,
3110
- },
3111
- {
3112
- method: "GET",
3113
- path: pollingPath,
3114
- status: 200,
3115
- body: JSON.stringify(body),
3116
- },
3117
- ],
3118
- implName,
3119
- throwOnNon2xxResponse: true,
3120
- });
3121
- let err: any;
3122
- try {
3123
- await poller.catch((e) => {
3124
- err = e;
3125
- });
3126
- assert.equal(err.message, errMsg);
3127
- } catch (e: any) {
3128
- assert.fail("should not throw error");
3129
- }
3130
- try {
3131
- await poller;
3132
- assert.fail("should throw error");
3133
- } catch (e: any) {
3134
- assert.equal(e.message, errMsg);
3135
- }
3136
- });
3137
- });
3138
- });
3139
- });
3140
- },
3141
- );