@fluidframework/driver-utils 2.0.0-rc.2.0.2 → 2.0.0-rc.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.
- package/CHANGELOG.md +23 -0
- package/api-report/driver-utils.api.md +18 -18
- package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts +1 -1
- package/dist/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -1
- package/dist/adapters/compression/documentServiceCompressionAdapter.js.map +1 -1
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +1 -1
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -1
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js +1 -1
- package/dist/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -1
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +2 -2
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -1
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +7 -7
- package/dist/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -1
- package/dist/adapters/predefinedAdapters.d.ts +1 -1
- package/dist/adapters/predefinedAdapters.d.ts.map +1 -1
- package/dist/adapters/predefinedAdapters.js +2 -2
- package/dist/adapters/predefinedAdapters.js.map +1 -1
- package/dist/blob.d.ts +1 -1
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js.map +1 -1
- package/dist/buildSnapshotTree.d.ts.map +1 -1
- package/dist/buildSnapshotTree.js +3 -3
- package/dist/buildSnapshotTree.js.map +1 -1
- package/dist/documentServiceFactoryProxy.d.ts +1 -1
- package/dist/documentServiceFactoryProxy.d.ts.map +1 -1
- package/dist/documentServiceFactoryProxy.js.map +1 -1
- package/dist/documentServiceProxy.d.ts +1 -1
- package/dist/documentServiceProxy.d.ts.map +1 -1
- package/dist/documentServiceProxy.js.map +1 -1
- package/dist/documentStorageServiceProxy.d.ts +1 -1
- package/dist/documentStorageServiceProxy.d.ts.map +1 -1
- package/dist/documentStorageServiceProxy.js +2 -2
- package/dist/documentStorageServiceProxy.js.map +1 -1
- package/dist/error.d.ts +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -2
- package/dist/error.js.map +1 -1
- package/dist/insecureUrlResolver.d.ts +1 -1
- package/dist/insecureUrlResolver.d.ts.map +1 -1
- package/dist/insecureUrlResolver.js +5 -5
- package/dist/insecureUrlResolver.js.map +1 -1
- package/dist/legacy.d.ts +18 -0
- package/dist/messageRecognition.d.ts.map +1 -1
- package/dist/messageRecognition.js +2 -2
- package/dist/messageRecognition.js.map +1 -1
- package/dist/network.d.ts +3 -2
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +8 -8
- package/dist/network.js.map +1 -1
- package/dist/networkUtils.d.ts +1 -1
- package/dist/networkUtils.d.ts.map +1 -1
- package/dist/networkUtils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/parallelRequests.d.ts +6 -2
- package/dist/parallelRequests.d.ts.map +1 -1
- package/dist/parallelRequests.js +31 -31
- package/dist/parallelRequests.js.map +1 -1
- package/dist/prefetchDocumentStorageService.d.ts +1 -1
- package/dist/prefetchDocumentStorageService.d.ts.map +1 -1
- package/dist/prefetchDocumentStorageService.js +4 -4
- package/dist/prefetchDocumentStorageService.js.map +1 -1
- package/dist/public.d.ts +15 -0
- package/dist/rateLimiter.js +2 -2
- package/dist/rateLimiter.js.map +1 -1
- package/dist/readAndParse.d.ts +1 -1
- package/dist/readAndParse.d.ts.map +1 -1
- package/dist/readAndParse.js.map +1 -1
- package/dist/runWithRetry.d.ts.map +1 -1
- package/dist/runWithRetry.js +4 -4
- package/dist/runWithRetry.js.map +1 -1
- package/dist/storageUtils.d.ts +1 -1
- package/dist/storageUtils.d.ts.map +1 -1
- package/dist/storageUtils.js.map +1 -1
- package/dist/summaryForCreateNew.d.ts +1 -1
- package/dist/summaryForCreateNew.d.ts.map +1 -1
- package/dist/summaryForCreateNew.js.map +1 -1
- package/dist/treeConversions.d.ts.map +1 -1
- package/dist/treeConversions.js +2 -2
- package/dist/treeConversions.js.map +1 -1
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts +1 -1
- package/lib/adapters/compression/documentServiceCompressionAdapter.d.ts.map +1 -1
- package/lib/adapters/compression/documentServiceCompressionAdapter.js.map +1 -1
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts +1 -1
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.d.ts.map +1 -1
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js +1 -1
- package/lib/adapters/compression/documentServiceFactoryCompressionAdapter.js.map +1 -1
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts +2 -2
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.d.ts.map +1 -1
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js +2 -2
- package/lib/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.js.map +1 -1
- package/lib/adapters/predefinedAdapters.d.ts +1 -1
- package/lib/adapters/predefinedAdapters.d.ts.map +1 -1
- package/lib/adapters/predefinedAdapters.js +2 -2
- package/lib/adapters/predefinedAdapters.js.map +1 -1
- package/lib/blob.d.ts +1 -1
- package/lib/blob.d.ts.map +1 -1
- package/lib/blob.js.map +1 -1
- package/lib/buildSnapshotTree.d.ts.map +1 -1
- package/lib/buildSnapshotTree.js +2 -2
- package/lib/buildSnapshotTree.js.map +1 -1
- package/lib/documentServiceFactoryProxy.d.ts +1 -1
- package/lib/documentServiceFactoryProxy.d.ts.map +1 -1
- package/lib/documentServiceFactoryProxy.js.map +1 -1
- package/lib/documentServiceProxy.d.ts +1 -1
- package/lib/documentServiceProxy.d.ts.map +1 -1
- package/lib/documentServiceProxy.js.map +1 -1
- package/lib/documentStorageServiceProxy.d.ts +1 -1
- package/lib/documentStorageServiceProxy.d.ts.map +1 -1
- package/lib/documentStorageServiceProxy.js +1 -1
- package/lib/documentStorageServiceProxy.js.map +1 -1
- package/lib/error.d.ts +1 -1
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js +1 -1
- package/lib/error.js.map +1 -1
- package/lib/insecureUrlResolver.d.ts +1 -1
- package/lib/insecureUrlResolver.d.ts.map +1 -1
- package/lib/insecureUrlResolver.js +2 -2
- package/lib/insecureUrlResolver.js.map +1 -1
- package/lib/legacy.d.ts +18 -0
- package/lib/messageRecognition.d.ts.map +1 -1
- package/lib/messageRecognition.js.map +1 -1
- package/lib/network.d.ts +3 -2
- package/lib/network.d.ts.map +1 -1
- package/lib/network.js +2 -2
- package/lib/network.js.map +1 -1
- package/lib/networkUtils.d.ts +1 -1
- package/lib/networkUtils.d.ts.map +1 -1
- package/lib/networkUtils.js +1 -1
- package/lib/networkUtils.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/parallelRequests.d.ts +6 -2
- package/lib/parallelRequests.d.ts.map +1 -1
- package/lib/parallelRequests.js +3 -3
- package/lib/parallelRequests.js.map +1 -1
- package/lib/prefetchDocumentStorageService.d.ts +1 -1
- package/lib/prefetchDocumentStorageService.d.ts.map +1 -1
- package/lib/prefetchDocumentStorageService.js +1 -1
- package/lib/prefetchDocumentStorageService.js.map +1 -1
- package/lib/public.d.ts +15 -0
- package/lib/rateLimiter.js +1 -1
- package/lib/rateLimiter.js.map +1 -1
- package/lib/readAndParse.d.ts +1 -1
- package/lib/readAndParse.d.ts.map +1 -1
- package/lib/readAndParse.js.map +1 -1
- package/lib/runWithRetry.d.ts.map +1 -1
- package/lib/runWithRetry.js +3 -3
- package/lib/runWithRetry.js.map +1 -1
- package/lib/storageUtils.d.ts +1 -1
- package/lib/storageUtils.d.ts.map +1 -1
- package/lib/storageUtils.js.map +1 -1
- package/lib/summaryForCreateNew.d.ts +1 -1
- package/lib/summaryForCreateNew.d.ts.map +1 -1
- package/lib/summaryForCreateNew.js.map +1 -1
- package/lib/treeConversions.d.ts.map +1 -1
- package/lib/treeConversions.js +1 -1
- package/lib/treeConversions.js.map +1 -1
- package/package.json +29 -50
- package/src/adapters/compression/documentServiceCompressionAdapter.ts +7 -2
- package/src/adapters/compression/documentServiceFactoryCompressionAdapter.ts +4 -2
- package/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts +7 -3
- package/src/adapters/predefinedAdapters.ts +4 -3
- package/src/blob.ts +1 -1
- package/src/buildSnapshotTree.ts +2 -2
- package/src/documentServiceFactoryProxy.ts +1 -1
- package/src/documentServiceProxy.ts +1 -1
- package/src/documentStorageServiceProxy.ts +2 -2
- package/src/error.ts +1 -1
- package/src/insecureUrlResolver.ts +6 -2
- package/src/messageRecognition.ts +1 -0
- package/src/network.ts +5 -6
- package/src/networkUtils.ts +3 -2
- package/src/packageVersion.ts +1 -1
- package/src/parallelRequests.ts +11 -4
- package/src/prefetchDocumentStorageService.ts +3 -1
- package/src/rateLimiter.ts +1 -1
- package/src/readAndParse.ts +1 -1
- package/src/runWithRetry.ts +5 -3
- package/src/storageUtils.ts +1 -1
- package/src/summaryForCreateNew.ts +3 -3
- package/src/treeConversions.ts +2 -1
- package/api-extractor-cjs.json +0 -8
- package/dist/driver-utils-alpha.d.ts +0 -167
- package/dist/driver-utils-beta.d.ts +0 -186
- package/dist/driver-utils-public.d.ts +0 -186
- package/dist/driver-utils-untrimmed.d.ts +0 -603
- package/lib/driver-utils-alpha.d.ts +0 -167
- package/lib/driver-utils-beta.d.ts +0 -186
- package/lib/driver-utils-public.d.ts +0 -186
- package/lib/driver-utils-untrimmed.d.ts +0 -603
- package/lib/test/insecureUrlResolverTest.spec.js +0 -101
- package/lib/test/insecureUrlResolverTest.spec.js.map +0 -1
- package/lib/test/parallelRequests.spec.js +0 -186
- package/lib/test/parallelRequests.spec.js.map +0 -1
- package/lib/test/rateLimiter.spec.js +0 -85
- package/lib/test/rateLimiter.spec.js.map +0 -1
- package/lib/test/runWithRetry.spec.js +0 -180
- package/lib/test/runWithRetry.spec.js.map +0 -1
- package/lib/test/summaryCompressionData.js +0 -170
- package/lib/test/summaryCompressionData.js.map +0 -1
- package/lib/test/summaryCompresssionTester.spec.js +0 -429
- package/lib/test/summaryCompresssionTester.spec.js.map +0 -1
- package/lib/test/types/validateDriverUtilsPrevious.generated.js +0 -108
- package/lib/test/types/validateDriverUtilsPrevious.generated.js.map +0 -1
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { strict as assert } from "assert";
|
|
6
|
-
import { DriverHeader } from "@fluidframework/driver-definitions";
|
|
7
|
-
import { InsecureUrlResolver } from "../insecureUrlResolver.js";
|
|
8
|
-
describe("Insecure Url Resolver Test", () => {
|
|
9
|
-
const deltaStreamUrl = "https://localhost.deltaStream";
|
|
10
|
-
const hostUrl = "https://localhost";
|
|
11
|
-
const ordererUrl = "https://localhost.orderer";
|
|
12
|
-
const storageUrl = "https://localhost.storage";
|
|
13
|
-
const tenantId = "tenantId";
|
|
14
|
-
const bearer = "bearer";
|
|
15
|
-
const fileName = "fileName";
|
|
16
|
-
let resolver;
|
|
17
|
-
let request;
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
resolver = new InsecureUrlResolver(hostUrl, ordererUrl, storageUrl, deltaStreamUrl, tenantId, bearer);
|
|
20
|
-
request = resolver.createCreateNewRequest(fileName);
|
|
21
|
-
// Mocking window since the resolver depends on window.location.host
|
|
22
|
-
if (typeof window === "undefined" && typeof global === "object") {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
24
|
-
global["window"] = {
|
|
25
|
-
location: { host: "localhost" },
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
it("Create New Request", async () => {
|
|
30
|
-
assert(
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
32
|
-
!!request.headers?.[DriverHeader.createNew], "Request should contain create new header");
|
|
33
|
-
const url = `${hostUrl}?fileName=${fileName}`;
|
|
34
|
-
assert.strictEqual(request.url, url, "Request url should match");
|
|
35
|
-
});
|
|
36
|
-
it("Resolved CreateNew Request", async () => {
|
|
37
|
-
const resolvedUrl = (await resolver.resolve(request));
|
|
38
|
-
const documentUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}`;
|
|
39
|
-
assert.strictEqual(resolvedUrl.endpoints.ordererUrl, ordererUrl, "Orderer url should match");
|
|
40
|
-
assert.strictEqual(resolvedUrl.url, documentUrl, "Document url should match");
|
|
41
|
-
});
|
|
42
|
-
it("Test RequestUrl for a data store", async () => {
|
|
43
|
-
const resolvedUrl = await resolver.resolve(request);
|
|
44
|
-
const expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}`;
|
|
45
|
-
assert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, "resolved url is wrong");
|
|
46
|
-
const dataStoreId = "dataStore";
|
|
47
|
-
const absoluteUrl = await resolver.getAbsoluteUrl(resolvedUrl, dataStoreId);
|
|
48
|
-
const expectedUrl = `${hostUrl}/${tenantId}/${fileName}/${dataStoreId}`;
|
|
49
|
-
assert.strictEqual(absoluteUrl, expectedUrl, "Url should match");
|
|
50
|
-
});
|
|
51
|
-
it("Test RequestUrl for url with only document id", async () => {
|
|
52
|
-
const testRequest = {
|
|
53
|
-
url: `https://localhost/${fileName}`,
|
|
54
|
-
headers: {},
|
|
55
|
-
};
|
|
56
|
-
const resolvedUrl = await resolver.resolve(testRequest);
|
|
57
|
-
const expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}`;
|
|
58
|
-
assert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, "resolved url is wrong");
|
|
59
|
-
});
|
|
60
|
-
it("Test RequestUrl for url with data store ids", async () => {
|
|
61
|
-
const testRequest = {
|
|
62
|
-
url: `https://localhost/${fileName}/dataStore1/dataStore2`,
|
|
63
|
-
headers: {},
|
|
64
|
-
};
|
|
65
|
-
const resolvedUrl = await resolver.resolve(testRequest);
|
|
66
|
-
const expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}/dataStore1/dataStore2`;
|
|
67
|
-
assert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, "resolved url is wrong");
|
|
68
|
-
const dataStoreId = "dataStore";
|
|
69
|
-
const absoluteUrl = await resolver.getAbsoluteUrl(resolvedUrl, dataStoreId);
|
|
70
|
-
const expectedResponseUrl = `${hostUrl}/${tenantId}/${fileName}/${dataStoreId}`;
|
|
71
|
-
assert.strictEqual(absoluteUrl, expectedResponseUrl, "response url is wrong");
|
|
72
|
-
});
|
|
73
|
-
it("Test RequestUrl for url with a slash at the end", async () => {
|
|
74
|
-
const testRequest = {
|
|
75
|
-
url: `https://localhost/${fileName}/`,
|
|
76
|
-
headers: {},
|
|
77
|
-
};
|
|
78
|
-
const resolvedUrl = await resolver.resolve(testRequest);
|
|
79
|
-
const expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}/`;
|
|
80
|
-
assert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, "resolved url is wrong");
|
|
81
|
-
});
|
|
82
|
-
it("Test RequestUrl for url with 2 slashes at the end", async () => {
|
|
83
|
-
const testRequest = {
|
|
84
|
-
url: `https://localhost/${fileName}//`,
|
|
85
|
-
headers: {},
|
|
86
|
-
};
|
|
87
|
-
const resolvedUrl = await resolver.resolve(testRequest);
|
|
88
|
-
const expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}//`;
|
|
89
|
-
assert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, "resolved url is wrong");
|
|
90
|
-
});
|
|
91
|
-
it("Test RequestUrl for url with special characters", async () => {
|
|
92
|
-
const testRequest = {
|
|
93
|
-
url: `https://localhost/${fileName}/!@$123/dataStore!@$`,
|
|
94
|
-
headers: {},
|
|
95
|
-
};
|
|
96
|
-
const resolvedUrl = await resolver.resolve(testRequest);
|
|
97
|
-
const expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}/!@$123/dataStore!@$`;
|
|
98
|
-
assert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, "resolved url is wrong");
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
//# sourceMappingURL=insecureUrlResolverTest.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"insecureUrlResolverTest.spec.js","sourceRoot":"","sources":["../../src/test/insecureUrlResolverTest.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAgB,MAAM,oCAAoC,CAAC;AAEhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC3C,MAAM,cAAc,GAAG,+BAA+B,CAAC;IACvD,MAAM,OAAO,GAAG,mBAAmB,CAAC;IACpC,MAAM,UAAU,GAAG,2BAA2B,CAAC;IAC/C,MAAM,UAAU,GAAG,2BAA2B,CAAC;IAC/C,MAAM,QAAQ,GAAG,UAAU,CAAC;IAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC;IACxB,MAAM,QAAQ,GAAG,UAAU,CAAC;IAC5B,IAAI,QAA6B,CAAC;IAClC,IAAI,OAAiB,CAAC;IAEtB,UAAU,CAAC,GAAG,EAAE;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OAAO,CAAC,WAAW,CAAC,CAAC;QAExD,MAAM,mBAAmB,GAAG,WAAW,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,QAAQ,IAAI,QAAQ,IAAI,CAAC;QAC5F,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE,mBAAmB,EAAE,uBAAuB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,WAAW,GAAa;YAC7B,GAAG,EAAE,qBAAqB,QAAQ,sBAAsB;YACxD,OAAO,EAAE,EAAE;SACX,CAAC;QACF,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExD,MAAM,mBAAmB,GAAG,WAC3B,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,IACrB,IAAI,QAAQ,IAAI,QAAQ,sBAAsB,CAAC;QAC/C,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE,mBAAmB,EAAE,uBAAuB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport { DriverHeader, IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport { InsecureUrlResolver } from \"../insecureUrlResolver.js\";\n\ndescribe(\"Insecure Url Resolver Test\", () => {\n\tconst deltaStreamUrl = \"https://localhost.deltaStream\";\n\tconst hostUrl = \"https://localhost\";\n\tconst ordererUrl = \"https://localhost.orderer\";\n\tconst storageUrl = \"https://localhost.storage\";\n\tconst tenantId = \"tenantId\";\n\tconst bearer = \"bearer\";\n\tconst fileName = \"fileName\";\n\tlet resolver: InsecureUrlResolver;\n\tlet request: IRequest;\n\n\tbeforeEach(() => {\n\t\tresolver = new InsecureUrlResolver(\n\t\t\thostUrl,\n\t\t\tordererUrl,\n\t\t\tstorageUrl,\n\t\t\tdeltaStreamUrl,\n\t\t\ttenantId,\n\t\t\tbearer,\n\t\t);\n\t\trequest = resolver.createCreateNewRequest(fileName);\n\n\t\t// Mocking window since the resolver depends on window.location.host\n\t\tif (typeof window === \"undefined\" && typeof global === \"object\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/dot-notation\n\t\t\tglobal[\"window\"] = {\n\t\t\t\tlocation: { host: \"localhost\" } as unknown as Location,\n\t\t\t} as unknown as Window & typeof globalThis;\n\t\t}\n\t});\n\n\tit(\"Create New Request\", async () => {\n\t\tassert(\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\t!!request.headers?.[DriverHeader.createNew],\n\t\t\t\"Request should contain create new header\",\n\t\t);\n\t\tconst url = `${hostUrl}?fileName=${fileName}`;\n\t\tassert.strictEqual(request.url, url, \"Request url should match\");\n\t});\n\n\tit(\"Resolved CreateNew Request\", async () => {\n\t\tconst resolvedUrl = (await resolver.resolve(request)) as IResolvedUrl;\n\t\tconst documentUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}`;\n\t\tassert.strictEqual(\n\t\t\tresolvedUrl.endpoints.ordererUrl,\n\t\t\tordererUrl,\n\t\t\t\"Orderer url should match\",\n\t\t);\n\t\tassert.strictEqual(resolvedUrl.url, documentUrl, \"Document url should match\");\n\t});\n\n\tit(\"Test RequestUrl for a data store\", async () => {\n\t\tconst resolvedUrl = await resolver.resolve(request);\n\n\t\tconst expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}`;\n\t\tassert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, \"resolved url is wrong\");\n\n\t\tconst dataStoreId = \"dataStore\";\n\t\tconst absoluteUrl = await resolver.getAbsoluteUrl(resolvedUrl, dataStoreId);\n\n\t\tconst expectedUrl = `${hostUrl}/${tenantId}/${fileName}/${dataStoreId}`;\n\t\tassert.strictEqual(absoluteUrl, expectedUrl, \"Url should match\");\n\t});\n\n\tit(\"Test RequestUrl for url with only document id\", async () => {\n\t\tconst testRequest: IRequest = {\n\t\t\turl: `https://localhost/${fileName}`,\n\t\t\theaders: {},\n\t\t};\n\t\tconst resolvedUrl = await resolver.resolve(testRequest);\n\n\t\tconst expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}`;\n\t\tassert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, \"resolved url is wrong\");\n\t});\n\n\tit(\"Test RequestUrl for url with data store ids\", async () => {\n\t\tconst testRequest: IRequest = {\n\t\t\turl: `https://localhost/${fileName}/dataStore1/dataStore2`,\n\t\t\theaders: {},\n\t\t};\n\t\tconst resolvedUrl = await resolver.resolve(testRequest);\n\n\t\tconst expectedResolvedUrl = `https://${\n\t\t\tnew URL(ordererUrl).host\n\t\t}/${tenantId}/${fileName}/dataStore1/dataStore2`;\n\t\tassert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, \"resolved url is wrong\");\n\n\t\tconst dataStoreId = \"dataStore\";\n\t\tconst absoluteUrl = await resolver.getAbsoluteUrl(resolvedUrl, dataStoreId);\n\n\t\tconst expectedResponseUrl = `${hostUrl}/${tenantId}/${fileName}/${dataStoreId}`;\n\t\tassert.strictEqual(absoluteUrl, expectedResponseUrl, \"response url is wrong\");\n\t});\n\n\tit(\"Test RequestUrl for url with a slash at the end\", async () => {\n\t\tconst testRequest: IRequest = {\n\t\t\turl: `https://localhost/${fileName}/`,\n\t\t\theaders: {},\n\t\t};\n\t\tconst resolvedUrl = await resolver.resolve(testRequest);\n\n\t\tconst expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}/`;\n\t\tassert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, \"resolved url is wrong\");\n\t});\n\n\tit(\"Test RequestUrl for url with 2 slashes at the end\", async () => {\n\t\tconst testRequest: IRequest = {\n\t\t\turl: `https://localhost/${fileName}//`,\n\t\t\theaders: {},\n\t\t};\n\t\tconst resolvedUrl = await resolver.resolve(testRequest);\n\n\t\tconst expectedResolvedUrl = `https://${new URL(ordererUrl).host}/${tenantId}/${fileName}//`;\n\t\tassert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, \"resolved url is wrong\");\n\t});\n\n\tit(\"Test RequestUrl for url with special characters\", async () => {\n\t\tconst testRequest: IRequest = {\n\t\t\turl: `https://localhost/${fileName}/!@$123/dataStore!@$`,\n\t\t\theaders: {},\n\t\t};\n\t\tconst resolvedUrl = await resolver.resolve(testRequest);\n\n\t\tconst expectedResolvedUrl = `https://${\n\t\t\tnew URL(ordererUrl).host\n\t\t}/${tenantId}/${fileName}/!@$123/dataStore!@$`;\n\t\tassert.strictEqual(resolvedUrl?.url, expectedResolvedUrl, \"resolved url is wrong\");\n\t});\n});\n"]}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { strict as assert } from "assert";
|
|
6
|
-
import { MockLogger } from "@fluidframework/telemetry-utils";
|
|
7
|
-
import { unreachableCase } from "@fluidframework/core-utils";
|
|
8
|
-
import { ParallelRequests } from "../parallelRequests.js";
|
|
9
|
-
var HowMany;
|
|
10
|
-
(function (HowMany) {
|
|
11
|
-
HowMany[HowMany["Exact"] = 0] = "Exact";
|
|
12
|
-
HowMany[HowMany["Partial"] = 1] = "Partial";
|
|
13
|
-
HowMany[HowMany["TooMany"] = 2] = "TooMany";
|
|
14
|
-
})(HowMany || (HowMany = {}));
|
|
15
|
-
describe("Parallel Requests", () => {
|
|
16
|
-
async function test(concurrency, payloadSize, from, to, expectedRequests, knownTo, howMany = HowMany.Exact) {
|
|
17
|
-
let nextElement = from;
|
|
18
|
-
let requests = 0;
|
|
19
|
-
let dispatches = 0;
|
|
20
|
-
const logger = new MockLogger();
|
|
21
|
-
const manager = new ParallelRequests(from, knownTo ? to : undefined, payloadSize, logger.toTelemetryLogger(), async (request, _from, _to) => {
|
|
22
|
-
let length = _to - _from;
|
|
23
|
-
requests++;
|
|
24
|
-
assert(_from >= from);
|
|
25
|
-
assert(length <= payloadSize);
|
|
26
|
-
assert(requests <= request);
|
|
27
|
-
assert(!knownTo || _to <= to);
|
|
28
|
-
switch (howMany) {
|
|
29
|
-
case HowMany.Partial:
|
|
30
|
-
length = Math.min(length, payloadSize / 2 + 1);
|
|
31
|
-
break;
|
|
32
|
-
case HowMany.TooMany:
|
|
33
|
-
length = 2 * length + 2;
|
|
34
|
-
break;
|
|
35
|
-
case HowMany.Exact:
|
|
36
|
-
break;
|
|
37
|
-
default:
|
|
38
|
-
unreachableCase(howMany);
|
|
39
|
-
}
|
|
40
|
-
// covering knownTo === false case
|
|
41
|
-
const actualTo = Math.min(_from + length, to);
|
|
42
|
-
const payload = [];
|
|
43
|
-
for (let i = _from; i < actualTo; i++) {
|
|
44
|
-
payload.push(i);
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
partial: _from !== to && howMany === HowMany.Partial,
|
|
48
|
-
cancel: false,
|
|
49
|
-
payload,
|
|
50
|
-
};
|
|
51
|
-
}, (deltas) => {
|
|
52
|
-
dispatches++;
|
|
53
|
-
// Big chunks are broken into smaller ones
|
|
54
|
-
assert(dispatches <= requests || howMany === HowMany.TooMany);
|
|
55
|
-
for (const el of deltas) {
|
|
56
|
-
assert(el === nextElement);
|
|
57
|
-
nextElement++;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
await manager.run(concurrency);
|
|
61
|
-
assert(nextElement === to);
|
|
62
|
-
assert(!knownTo || dispatches === requests);
|
|
63
|
-
assert.equal(requests, expectedRequests, "expected requests");
|
|
64
|
-
logger.assertMatchNone([{ category: "error" }]);
|
|
65
|
-
}
|
|
66
|
-
async function testCancel(from, to, cancelAt, payloadSize, expectedRequests) {
|
|
67
|
-
let nextElement = from;
|
|
68
|
-
let requests = 0;
|
|
69
|
-
let dispatches = 0;
|
|
70
|
-
const logger = new MockLogger();
|
|
71
|
-
const manager = new ParallelRequests(from, to, payloadSize, logger.toTelemetryLogger(), async (request, _from, _to) => {
|
|
72
|
-
const length = _to - _from;
|
|
73
|
-
requests++;
|
|
74
|
-
assert(_from >= from);
|
|
75
|
-
assert(length <= payloadSize);
|
|
76
|
-
assert(requests <= request);
|
|
77
|
-
assert(to === undefined || _to <= to);
|
|
78
|
-
if (_to > cancelAt) {
|
|
79
|
-
return { partial: false, cancel: true, payload: [] };
|
|
80
|
-
}
|
|
81
|
-
const payload = [];
|
|
82
|
-
for (let i = _from; i < _to; i++) {
|
|
83
|
-
payload.push(i);
|
|
84
|
-
}
|
|
85
|
-
return { partial: false, cancel: false, payload };
|
|
86
|
-
}, (deltas) => {
|
|
87
|
-
dispatches++;
|
|
88
|
-
assert(dispatches <= requests);
|
|
89
|
-
for (const el of deltas) {
|
|
90
|
-
assert(el === nextElement);
|
|
91
|
-
nextElement++;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
await manager.run(10);
|
|
95
|
-
assert(dispatches <= requests);
|
|
96
|
-
assert(requests === expectedRequests);
|
|
97
|
-
logger.assertMatchNone([{ category: "error" }]);
|
|
98
|
-
}
|
|
99
|
-
it("no concurrency, single request, over", async () => {
|
|
100
|
-
await test(1, 100, 123, 156, 1, true);
|
|
101
|
-
await test(1, 100, 123, 156, 1, false);
|
|
102
|
-
await test(1, 100, 123, 156, 1, true, HowMany.TooMany);
|
|
103
|
-
await test(1, 100, 123, 156, 1, true, HowMany.Partial);
|
|
104
|
-
});
|
|
105
|
-
it("no concurrency, single request, exact", async () => {
|
|
106
|
-
await test(1, 156 - 123, 123, 156, 1, true);
|
|
107
|
-
await test(1, 156 - 123, 123, 156, 2, false);
|
|
108
|
-
await test(1, 156 - 123, 123, 156, 1, true, HowMany.TooMany);
|
|
109
|
-
await test(1, 156 - 123, 123, 156, 2, true, HowMany.Partial);
|
|
110
|
-
await test(1, 156 - 123, 123, 156, 2, false, HowMany.TooMany);
|
|
111
|
-
await test(1, 156 - 123, 123, 156, 3, false, HowMany.Partial);
|
|
112
|
-
});
|
|
113
|
-
it("concurrency, single request, exact", async () => {
|
|
114
|
-
await test(2, 156 - 123, 123, 156, 1, true);
|
|
115
|
-
await test(2, 156 - 123, 123, 156, 1, true, HowMany.TooMany);
|
|
116
|
-
await test(2, 156 - 123, 123, 156, 2, true, HowMany.Partial);
|
|
117
|
-
// here, the number of actual requests is Ok to be 2..3
|
|
118
|
-
await test(2, 156 - 123, 123, 156, 3, false);
|
|
119
|
-
await test(2, 156 - 123, 123, 156, 3, false, HowMany.TooMany);
|
|
120
|
-
await test(2, 156 - 123, 123, 156, 3, false, HowMany.Partial);
|
|
121
|
-
});
|
|
122
|
-
it("no concurrency, multiple requests", async () => {
|
|
123
|
-
await test(1, 10, 123, 156, 4, true);
|
|
124
|
-
await test(1, 10, 123, 156, 4, false);
|
|
125
|
-
await test(1, 10, 123, 156, 3, false, HowMany.TooMany);
|
|
126
|
-
});
|
|
127
|
-
it("two concurrent requests exact", async () => {
|
|
128
|
-
await test(2, 10, 123, 153, 3, true);
|
|
129
|
-
await test(2, 10, 123, 153, 3, true, HowMany.TooMany);
|
|
130
|
-
await test(2, 10, 123, 153, 6, true, HowMany.Partial);
|
|
131
|
-
await test(2, 10, 123, 153, 5, false);
|
|
132
|
-
await test(2, 10, 123, 153, 5, false, HowMany.TooMany);
|
|
133
|
-
await test(2, 10, 123, 153, 8, false, HowMany.Partial);
|
|
134
|
-
});
|
|
135
|
-
it("two concurrent requests one over", async () => {
|
|
136
|
-
await test(2, 10, 123, 154, 4, true);
|
|
137
|
-
// here, the number of actual requests is Ok to be 4..5
|
|
138
|
-
await test(2, 10, 123, 154, 5, false);
|
|
139
|
-
});
|
|
140
|
-
it("four concurrent requests", async () => {
|
|
141
|
-
await test(4, 10, 123, 156, 4, true);
|
|
142
|
-
// here, the number of actual requests is Ok to be 4..7
|
|
143
|
-
await test(4, 10, 123, 156, 7, false);
|
|
144
|
-
});
|
|
145
|
-
it("cancellation", async () => {
|
|
146
|
-
await testCancel(1, 1000, 502, 10, 60);
|
|
147
|
-
await testCancel(1, undefined, 502, 10, 60);
|
|
148
|
-
});
|
|
149
|
-
it("exception in request", async () => {
|
|
150
|
-
const logger = new MockLogger();
|
|
151
|
-
const manager = new ParallelRequests(1, 100, 10, logger.toTelemetryLogger(), async (request, _from, _to) => {
|
|
152
|
-
throw new Error("request");
|
|
153
|
-
}, (deltas) => {
|
|
154
|
-
throw new Error("response");
|
|
155
|
-
});
|
|
156
|
-
let success = true;
|
|
157
|
-
try {
|
|
158
|
-
await manager.run(10);
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
success = false;
|
|
162
|
-
assert(error.message === "request");
|
|
163
|
-
}
|
|
164
|
-
assert(!success);
|
|
165
|
-
logger.assertMatchNone([{ category: "error" }]);
|
|
166
|
-
});
|
|
167
|
-
it("exception in response", async () => {
|
|
168
|
-
const logger = new MockLogger();
|
|
169
|
-
const manager = new ParallelRequests(1, 100, 10, logger.toTelemetryLogger(), async (request, _from, _to) => {
|
|
170
|
-
return { cancel: false, partial: false, payload: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] };
|
|
171
|
-
}, (deltas) => {
|
|
172
|
-
throw new Error("response");
|
|
173
|
-
});
|
|
174
|
-
let success = true;
|
|
175
|
-
try {
|
|
176
|
-
await manager.run(10);
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
success = false;
|
|
180
|
-
assert(error.message === "response");
|
|
181
|
-
}
|
|
182
|
-
assert(!success);
|
|
183
|
-
logger.assertMatchNone([{ category: "error" }]);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
//# sourceMappingURL=parallelRequests.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parallelRequests.spec.js","sourceRoot":"","sources":["../../src/test/parallelRequests.spec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AAE,CAAC,EAAE,CAAC;QACpF,CAAC,EACD,CAAC,MAAgB,EAAE,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC,CACD,CAAC;QAEF,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI;YACH,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SACtB;QAAC,OAAO,KAAU,EAAE;YACpB,OAAO,GAAG,KAAK,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC;SACrC;QACD,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QACjB,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport { MockLogger } from \"@fluidframework/telemetry-utils\";\nimport { unreachableCase } from \"@fluidframework/core-utils\";\nimport { ParallelRequests } from \"../parallelRequests.js\";\n\nenum HowMany {\n\tExact,\n\tPartial,\n\tTooMany,\n}\n\ndescribe(\"Parallel Requests\", () => {\n\tasync function test(\n\t\tconcurrency: number,\n\t\tpayloadSize: number,\n\t\tfrom: number,\n\t\tto: number,\n\t\texpectedRequests: number,\n\t\tknownTo: boolean,\n\t\thowMany: HowMany = HowMany.Exact,\n\t) {\n\t\tlet nextElement = from;\n\t\tlet requests = 0;\n\t\tlet dispatches = 0;\n\n\t\tconst logger = new MockLogger();\n\n\t\tconst manager = new ParallelRequests<number>(\n\t\t\tfrom,\n\t\t\tknownTo ? to : undefined,\n\t\t\tpayloadSize,\n\t\t\tlogger.toTelemetryLogger(),\n\t\t\tasync (request: number, _from: number, _to: number) => {\n\t\t\t\tlet length = _to - _from;\n\t\t\t\trequests++;\n\n\t\t\t\tassert(_from >= from);\n\t\t\t\tassert(length <= payloadSize);\n\t\t\t\tassert(requests <= request);\n\t\t\t\tassert(!knownTo || _to <= to);\n\n\t\t\t\tswitch (howMany) {\n\t\t\t\t\tcase HowMany.Partial:\n\t\t\t\t\t\tlength = Math.min(length, payloadSize / 2 + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase HowMany.TooMany:\n\t\t\t\t\t\tlength = 2 * length + 2;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase HowMany.Exact:\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tunreachableCase(howMany);\n\t\t\t\t}\n\t\t\t\t// covering knownTo === false case\n\t\t\t\tconst actualTo = Math.min(_from + length, to);\n\n\t\t\t\tconst payload: number[] = [];\n\t\t\t\tfor (let i = _from; i < actualTo; i++) {\n\t\t\t\t\tpayload.push(i);\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tpartial: _from !== to && howMany === HowMany.Partial,\n\t\t\t\t\tcancel: false,\n\t\t\t\t\tpayload,\n\t\t\t\t};\n\t\t\t},\n\t\t\t(deltas: number[]) => {\n\t\t\t\tdispatches++;\n\t\t\t\t// Big chunks are broken into smaller ones\n\t\t\t\tassert(dispatches <= requests || howMany === HowMany.TooMany);\n\t\t\t\tfor (const el of deltas) {\n\t\t\t\t\tassert(el === nextElement);\n\t\t\t\t\tnextElement++;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tawait manager.run(concurrency);\n\n\t\tassert(nextElement === to);\n\t\tassert(!knownTo || dispatches === requests);\n\t\tassert.equal(requests, expectedRequests, \"expected requests\");\n\t\tlogger.assertMatchNone([{ category: \"error\" }]);\n\t}\n\n\tasync function testCancel(\n\t\tfrom: number,\n\t\tto: number | undefined,\n\t\tcancelAt: number,\n\t\tpayloadSize,\n\t\texpectedRequests: number,\n\t) {\n\t\tlet nextElement = from;\n\t\tlet requests = 0;\n\t\tlet dispatches = 0;\n\t\tconst logger = new MockLogger();\n\n\t\tconst manager = new ParallelRequests<number>(\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tpayloadSize,\n\t\t\tlogger.toTelemetryLogger(),\n\t\t\tasync (request: number, _from: number, _to: number) => {\n\t\t\t\tconst length = _to - _from;\n\t\t\t\trequests++;\n\n\t\t\t\tassert(_from >= from);\n\t\t\t\tassert(length <= payloadSize);\n\t\t\t\tassert(requests <= request);\n\t\t\t\tassert(to === undefined || _to <= to);\n\n\t\t\t\tif (_to > cancelAt) {\n\t\t\t\t\treturn { partial: false, cancel: true, payload: [] };\n\t\t\t\t}\n\n\t\t\t\tconst payload: number[] = [];\n\t\t\t\tfor (let i = _from; i < _to; i++) {\n\t\t\t\t\tpayload.push(i);\n\t\t\t\t}\n\n\t\t\t\treturn { partial: false, cancel: false, payload };\n\t\t\t},\n\t\t\t(deltas: number[]) => {\n\t\t\t\tdispatches++;\n\t\t\t\tassert(dispatches <= requests);\n\t\t\t\tfor (const el of deltas) {\n\t\t\t\t\tassert(el === nextElement);\n\t\t\t\t\tnextElement++;\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tawait manager.run(10);\n\n\t\tassert(dispatches <= requests);\n\t\tassert(requests === expectedRequests);\n\t\tlogger.assertMatchNone([{ category: \"error\" }]);\n\t}\n\n\tit(\"no concurrency, single request, over\", async () => {\n\t\tawait test(1, 100, 123, 156, 1, true);\n\t\tawait test(1, 100, 123, 156, 1, false);\n\t\tawait test(1, 100, 123, 156, 1, true, HowMany.TooMany);\n\t\tawait test(1, 100, 123, 156, 1, true, HowMany.Partial);\n\t});\n\n\tit(\"no concurrency, single request, exact\", async () => {\n\t\tawait test(1, 156 - 123, 123, 156, 1, true);\n\t\tawait test(1, 156 - 123, 123, 156, 2, false);\n\t\tawait test(1, 156 - 123, 123, 156, 1, true, HowMany.TooMany);\n\t\tawait test(1, 156 - 123, 123, 156, 2, true, HowMany.Partial);\n\t\tawait test(1, 156 - 123, 123, 156, 2, false, HowMany.TooMany);\n\t\tawait test(1, 156 - 123, 123, 156, 3, false, HowMany.Partial);\n\t});\n\n\tit(\"concurrency, single request, exact\", async () => {\n\t\tawait test(2, 156 - 123, 123, 156, 1, true);\n\t\tawait test(2, 156 - 123, 123, 156, 1, true, HowMany.TooMany);\n\t\tawait test(2, 156 - 123, 123, 156, 2, true, HowMany.Partial);\n\t\t// here, the number of actual requests is Ok to be 2..3\n\t\tawait test(2, 156 - 123, 123, 156, 3, false);\n\t\tawait test(2, 156 - 123, 123, 156, 3, false, HowMany.TooMany);\n\t\tawait test(2, 156 - 123, 123, 156, 3, false, HowMany.Partial);\n\t});\n\n\tit(\"no concurrency, multiple requests\", async () => {\n\t\tawait test(1, 10, 123, 156, 4, true);\n\t\tawait test(1, 10, 123, 156, 4, false);\n\t\tawait test(1, 10, 123, 156, 3, false, HowMany.TooMany);\n\t});\n\n\tit(\"two concurrent requests exact\", async () => {\n\t\tawait test(2, 10, 123, 153, 3, true);\n\t\tawait test(2, 10, 123, 153, 3, true, HowMany.TooMany);\n\t\tawait test(2, 10, 123, 153, 6, true, HowMany.Partial);\n\t\tawait test(2, 10, 123, 153, 5, false);\n\t\tawait test(2, 10, 123, 153, 5, false, HowMany.TooMany);\n\t\tawait test(2, 10, 123, 153, 8, false, HowMany.Partial);\n\t});\n\n\tit(\"two concurrent requests one over\", async () => {\n\t\tawait test(2, 10, 123, 154, 4, true);\n\t\t// here, the number of actual requests is Ok to be 4..5\n\t\tawait test(2, 10, 123, 154, 5, false);\n\t});\n\n\tit(\"four concurrent requests\", async () => {\n\t\tawait test(4, 10, 123, 156, 4, true);\n\t\t// here, the number of actual requests is Ok to be 4..7\n\t\tawait test(4, 10, 123, 156, 7, false);\n\t});\n\n\tit(\"cancellation\", async () => {\n\t\tawait testCancel(1, 1000, 502, 10, 60);\n\t\tawait testCancel(1, undefined, 502, 10, 60);\n\t});\n\n\tit(\"exception in request\", async () => {\n\t\tconst logger = new MockLogger();\n\n\t\tconst manager = new ParallelRequests<number>(\n\t\t\t1,\n\t\t\t100,\n\t\t\t10,\n\t\t\tlogger.toTelemetryLogger(),\n\t\t\tasync (request: number, _from: number, _to: number) => {\n\t\t\t\tthrow new Error(\"request\");\n\t\t\t},\n\t\t\t(deltas: number[]) => {\n\t\t\t\tthrow new Error(\"response\");\n\t\t\t},\n\t\t);\n\n\t\tlet success = true;\n\t\ttry {\n\t\t\tawait manager.run(10);\n\t\t} catch (error: any) {\n\t\t\tsuccess = false;\n\t\t\tassert(error.message === \"request\");\n\t\t}\n\t\tassert(!success);\n\t\tlogger.assertMatchNone([{ category: \"error\" }]);\n\t});\n\n\tit(\"exception in response\", async () => {\n\t\tconst logger = new MockLogger();\n\n\t\tconst manager = new ParallelRequests<number>(\n\t\t\t1,\n\t\t\t100,\n\t\t\t10,\n\t\t\tlogger.toTelemetryLogger(),\n\t\t\tasync (request: number, _from: number, _to: number) => {\n\t\t\t\treturn { cancel: false, partial: false, payload: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] };\n\t\t\t},\n\t\t\t(deltas: number[]) => {\n\t\t\t\tthrow new Error(\"response\");\n\t\t\t},\n\t\t);\n\n\t\tlet success = true;\n\t\ttry {\n\t\t\tawait manager.run(10);\n\t\t} catch (error: any) {\n\t\t\tsuccess = false;\n\t\t\tassert(error.message === \"response\");\n\t\t}\n\t\tassert(!success);\n\t\tlogger.assertMatchNone([{ category: \"error\" }]);\n\t});\n});\n"]}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { strict as assert } from "assert";
|
|
6
|
-
import { RateLimiter } from "../rateLimiter.js";
|
|
7
|
-
describe("Rate Limiter", () => {
|
|
8
|
-
let limiter;
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
limiter = new RateLimiter(3);
|
|
11
|
-
});
|
|
12
|
-
it("can run task", async () => {
|
|
13
|
-
let done = false;
|
|
14
|
-
assert(limiter.waitQueueLength === 0);
|
|
15
|
-
await limiter.schedule(async () => {
|
|
16
|
-
assert(limiter.waitQueueLength === 0);
|
|
17
|
-
done = true;
|
|
18
|
-
});
|
|
19
|
-
assert(done);
|
|
20
|
-
});
|
|
21
|
-
it("can run 3 tasks", async () => {
|
|
22
|
-
let done = false;
|
|
23
|
-
await limiter.schedule(async () => {
|
|
24
|
-
await limiter.schedule(async () => {
|
|
25
|
-
await limiter.schedule(async () => {
|
|
26
|
-
assert(limiter.waitQueueLength === 0);
|
|
27
|
-
done = true;
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
assert(done);
|
|
32
|
-
});
|
|
33
|
-
it("can run 4 tasks", async () => {
|
|
34
|
-
let done = false;
|
|
35
|
-
let promise;
|
|
36
|
-
await limiter.schedule(async () => {
|
|
37
|
-
await limiter.schedule(async () => {
|
|
38
|
-
await limiter.schedule(async () => {
|
|
39
|
-
promise = limiter.schedule(async () => {
|
|
40
|
-
done = true;
|
|
41
|
-
});
|
|
42
|
-
assert(limiter.waitQueueLength === 1);
|
|
43
|
-
});
|
|
44
|
-
assert(limiter.waitQueueLength === 0);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
assert(promise !== undefined);
|
|
48
|
-
await promise;
|
|
49
|
-
assert(done);
|
|
50
|
-
assert(limiter.waitQueueLength === 0);
|
|
51
|
-
});
|
|
52
|
-
it("can run a lot of tasks", async () => {
|
|
53
|
-
let counter = 0;
|
|
54
|
-
const tasks = 100;
|
|
55
|
-
const promises = [];
|
|
56
|
-
for (let i = 0; i < tasks; i++) {
|
|
57
|
-
promises.push(limiter.schedule(async () => {
|
|
58
|
-
counter++;
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
// This is implementation detail and may not be true in the future.
|
|
62
|
-
// I.e. RateLimiter may asynchronously pick up first 3 tasks.
|
|
63
|
-
assert(limiter.waitQueueLength === tasks - 3);
|
|
64
|
-
await Promise.all(promises);
|
|
65
|
-
assert(counter === tasks);
|
|
66
|
-
assert(limiter.waitQueueLength === 0);
|
|
67
|
-
});
|
|
68
|
-
it("can run many tasks sequentially", async () => {
|
|
69
|
-
let counter = 0;
|
|
70
|
-
const promises = [];
|
|
71
|
-
for (let i = 0; i < 3; i++) {
|
|
72
|
-
promises.push(limiter.schedule(async () => {
|
|
73
|
-
counter++;
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
await Promise.all(promises);
|
|
77
|
-
// Now check that we can schedule another task.
|
|
78
|
-
await limiter.schedule(async () => {
|
|
79
|
-
counter++;
|
|
80
|
-
});
|
|
81
|
-
assert(counter === 4);
|
|
82
|
-
assert(limiter.waitQueueLength === 0);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
//# sourceMappingURL=rateLimiter.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rateLimiter.spec.js","sourceRoot":"","sources":["../../src/test/rateLimiter.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC7B,IAAI,OAAoB,CAAC;IAEzB,UAAU,CAAC,GAAG,EAAE;QACf,OAAO,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,cAAc,EAAE,KAAK,IAAI,EAAE;QAC7B,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,MAAM,CAAC,OAAO,CAAC,eAAe,KAAK,CAAC,CAAC,CAAC;QACtC,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YACjC,MAAM,CAAC,OAAO,CAAC,eAAe,KAAK,CAAC,CAAC,CAAC;YACtC,IAAI,GAAG,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AQ,CAAC,KAAK,IAAI,EAAE;YACjC,OAAO,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,OAAO,CAAC,eAAe,KAAK,CAAC,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { strict as assert } from \"assert\";\nimport { RateLimiter } from \"../rateLimiter.js\";\n\ndescribe(\"Rate Limiter\", () => {\n\tlet limiter: RateLimiter;\n\n\tbeforeEach(() => {\n\t\tlimiter = new RateLimiter(3);\n\t});\n\n\tit(\"can run task\", async () => {\n\t\tlet done = false;\n\t\tassert(limiter.waitQueueLength === 0);\n\t\tawait limiter.schedule(async () => {\n\t\t\tassert(limiter.waitQueueLength === 0);\n\t\t\tdone = true;\n\t\t});\n\t\tassert(done);\n\t});\n\n\tit(\"can run 3 tasks\", async () => {\n\t\tlet done = false;\n\t\tawait limiter.schedule(async () => {\n\t\t\tawait limiter.schedule(async () => {\n\t\t\t\tawait limiter.schedule(async () => {\n\t\t\t\t\tassert(limiter.waitQueueLength === 0);\n\t\t\t\t\tdone = true;\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t\tassert(done);\n\t});\n\n\tit(\"can run 4 tasks\", async () => {\n\t\tlet done = false;\n\t\tlet promise: Promise<void> | undefined;\n\t\tawait limiter.schedule(async () => {\n\t\t\tawait limiter.schedule(async () => {\n\t\t\t\tawait limiter.schedule(async () => {\n\t\t\t\t\tpromise = limiter.schedule(async () => {\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t});\n\t\t\t\t\tassert(limiter.waitQueueLength === 1);\n\t\t\t\t});\n\t\t\t\tassert(limiter.waitQueueLength === 0);\n\t\t\t});\n\t\t});\n\t\tassert(promise !== undefined);\n\t\tawait promise;\n\t\tassert(done);\n\t\tassert(limiter.waitQueueLength === 0);\n\t});\n\n\tit(\"can run a lot of tasks\", async () => {\n\t\tlet counter = 0;\n\t\tconst tasks = 100;\n\t\tconst promises: Promise<void>[] = [];\n\t\tfor (let i = 0; i < tasks; i++) {\n\t\t\tpromises.push(\n\t\t\t\tlimiter.schedule(async () => {\n\t\t\t\t\tcounter++;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\t// This is implementation detail and may not be true in the future.\n\t\t// I.e. RateLimiter may asynchronously pick up first 3 tasks.\n\t\tassert(limiter.waitQueueLength === tasks - 3);\n\n\t\tawait Promise.all(promises);\n\t\tassert(counter === tasks);\n\t\tassert(limiter.waitQueueLength === 0);\n\t});\n\n\tit(\"can run many tasks sequentially\", async () => {\n\t\tlet counter = 0;\n\t\tconst promises: Promise<void>[] = [];\n\t\tfor (let i = 0; i < 3; i++) {\n\t\t\tpromises.push(\n\t\t\t\tlimiter.schedule(async () => {\n\t\t\t\t\tcounter++;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tawait Promise.all(promises);\n\t\t// Now check that we can schedule another task.\n\t\tawait limiter.schedule(async () => {\n\t\t\tcounter++;\n\t\t});\n\t\tassert(counter === 4);\n\t\tassert(limiter.waitQueueLength === 0);\n\t});\n});\n"]}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { strict as assert } from "assert";
|
|
6
|
-
import { DriverErrorTypes } from "@fluidframework/driver-definitions";
|
|
7
|
-
import { createChildLogger } from "@fluidframework/telemetry-utils";
|
|
8
|
-
import { runWithRetry } from "../runWithRetry.js";
|
|
9
|
-
const _setTimeout = global.setTimeout;
|
|
10
|
-
const fastSetTimeout = (callback, ms, ...args) => _setTimeout(callback, ms / 1000.0, ...args);
|
|
11
|
-
async function runWithFastSetTimeout(callback) {
|
|
12
|
-
global.setTimeout = fastSetTimeout;
|
|
13
|
-
return callback().finally(() => {
|
|
14
|
-
global.setTimeout = _setTimeout;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
describe("runWithRetry Tests", () => {
|
|
18
|
-
const logger = createChildLogger();
|
|
19
|
-
it("Should succeed at first time", async () => {
|
|
20
|
-
let retryTimes = 1;
|
|
21
|
-
let success = false;
|
|
22
|
-
const api = async () => {
|
|
23
|
-
retryTimes -= 1;
|
|
24
|
-
return true;
|
|
25
|
-
};
|
|
26
|
-
let emitDelayInfoTimes = 0;
|
|
27
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {
|
|
28
|
-
onRetry: () => {
|
|
29
|
-
emitDelayInfoTimes += 1;
|
|
30
|
-
},
|
|
31
|
-
}));
|
|
32
|
-
assert.strictEqual(retryTimes, 0, "Should succeed at first time");
|
|
33
|
-
assert.strictEqual(success, true, "Retry should succeed ultimately");
|
|
34
|
-
assert.strictEqual(emitDelayInfoTimes, 0, "Should not emit delay at first time");
|
|
35
|
-
});
|
|
36
|
-
it("Check that it retries infinitely", async () => {
|
|
37
|
-
const maxTries = 5;
|
|
38
|
-
let retryTimes = maxTries;
|
|
39
|
-
let success = false;
|
|
40
|
-
const api = async () => {
|
|
41
|
-
if (retryTimes > 0) {
|
|
42
|
-
retryTimes -= 1;
|
|
43
|
-
const error = new Error("Throw error");
|
|
44
|
-
error.retryAfterSeconds = 10;
|
|
45
|
-
error.canRetry = true;
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
};
|
|
50
|
-
let emitDelayInfoTimes = 0;
|
|
51
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {
|
|
52
|
-
onRetry: () => {
|
|
53
|
-
emitDelayInfoTimes += 1;
|
|
54
|
-
},
|
|
55
|
-
}));
|
|
56
|
-
assert.strictEqual(retryTimes, 0, "Should keep retrying until success");
|
|
57
|
-
assert.strictEqual(success, true, "Retry should succeed ultimately");
|
|
58
|
-
assert.strictEqual(emitDelayInfoTimes, maxTries, "Should emit delay at each try");
|
|
59
|
-
});
|
|
60
|
-
it("Check that it retries after retry seconds", async () => {
|
|
61
|
-
let retryTimes = 1;
|
|
62
|
-
let success = false;
|
|
63
|
-
const api = async () => {
|
|
64
|
-
if (retryTimes > 0) {
|
|
65
|
-
retryTimes -= 1;
|
|
66
|
-
const error = new Error("Throttle Error");
|
|
67
|
-
error.errorType = DriverErrorTypes.throttlingError;
|
|
68
|
-
error.retryAfterSeconds = 400;
|
|
69
|
-
error.canRetry = true;
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
73
|
-
};
|
|
74
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {}));
|
|
75
|
-
assert.strictEqual(retryTimes, 0, "Should retry once");
|
|
76
|
-
assert.strictEqual(success, true, "Retry should succeed ultimately");
|
|
77
|
-
});
|
|
78
|
-
it("If error is just a string, should retry as canRetry is not false", async () => {
|
|
79
|
-
let retryTimes = 1;
|
|
80
|
-
let success = false;
|
|
81
|
-
const api = async () => {
|
|
82
|
-
if (retryTimes > 0) {
|
|
83
|
-
retryTimes -= 1;
|
|
84
|
-
const err = new Error("error");
|
|
85
|
-
err.canRetry = true;
|
|
86
|
-
throw err;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
};
|
|
90
|
-
try {
|
|
91
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {}));
|
|
92
|
-
}
|
|
93
|
-
catch (error) { }
|
|
94
|
-
assert.strictEqual(retryTimes, 0, "Should retry");
|
|
95
|
-
assert.strictEqual(success, true, "Should succeed as retry should be successful");
|
|
96
|
-
});
|
|
97
|
-
it("Should not retry if canRetry is set as false", async () => {
|
|
98
|
-
let retryTimes = 1;
|
|
99
|
-
let success = false;
|
|
100
|
-
const api = async () => {
|
|
101
|
-
if (retryTimes > 0) {
|
|
102
|
-
retryTimes -= 1;
|
|
103
|
-
const error = new Error("error");
|
|
104
|
-
error.canRetry = false;
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
};
|
|
109
|
-
try {
|
|
110
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {}));
|
|
111
|
-
assert.fail("Should not succeed");
|
|
112
|
-
}
|
|
113
|
-
catch (error) { }
|
|
114
|
-
assert.strictEqual(retryTimes, 0, "Should not retry");
|
|
115
|
-
assert.strictEqual(success, false, "Should not succeed as canRetry was not set");
|
|
116
|
-
});
|
|
117
|
-
it("Should not retry if canRetry is not set", async () => {
|
|
118
|
-
let retryTimes = 1;
|
|
119
|
-
let success = false;
|
|
120
|
-
const api = async () => {
|
|
121
|
-
if (retryTimes > 0) {
|
|
122
|
-
retryTimes -= 1;
|
|
123
|
-
const error = new Error("error");
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
};
|
|
128
|
-
try {
|
|
129
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {}));
|
|
130
|
-
assert.fail("Should not succeed");
|
|
131
|
-
}
|
|
132
|
-
catch (error) { }
|
|
133
|
-
assert.strictEqual(retryTimes, 0, "Should not retry");
|
|
134
|
-
assert.strictEqual(success, false, "Should not succeed as canRetry was not set");
|
|
135
|
-
});
|
|
136
|
-
it("Should not retry if it is disabled", async () => {
|
|
137
|
-
let retryTimes = 1;
|
|
138
|
-
let success = false;
|
|
139
|
-
const api = async () => {
|
|
140
|
-
if (retryTimes > 0) {
|
|
141
|
-
retryTimes -= 1;
|
|
142
|
-
const error = new Error("error");
|
|
143
|
-
error.canRetry = true;
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
return true;
|
|
147
|
-
};
|
|
148
|
-
try {
|
|
149
|
-
success = await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {
|
|
150
|
-
onRetry: () => {
|
|
151
|
-
throw new Error("disposed");
|
|
152
|
-
},
|
|
153
|
-
}));
|
|
154
|
-
assert.fail("Should not succeed");
|
|
155
|
-
}
|
|
156
|
-
catch (error) { }
|
|
157
|
-
assert.strictEqual(retryTimes, 0, "Should not retry");
|
|
158
|
-
assert.strictEqual(success, false, "Should not succeed as retrying was disabled");
|
|
159
|
-
});
|
|
160
|
-
it("Abort reason is included in thrown exception", async () => {
|
|
161
|
-
const abortController = new AbortController();
|
|
162
|
-
const api = () => {
|
|
163
|
-
abortController.abort("Sample abort reason");
|
|
164
|
-
const error = new Error("aborted");
|
|
165
|
-
error.canRetry = true;
|
|
166
|
-
throw error;
|
|
167
|
-
};
|
|
168
|
-
try {
|
|
169
|
-
await runWithFastSetTimeout(async () => runWithRetry(api, "test", logger, {
|
|
170
|
-
cancel: abortController.signal,
|
|
171
|
-
}));
|
|
172
|
-
assert.fail("Should not succeed");
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
assert.strictEqual(error.message, "runWithRetry was Aborted");
|
|
176
|
-
assert.strictEqual(error.reason, "Sample abort reason");
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
//# sourceMappingURL=runWithRetry.spec.js.map
|