@fluidframework/driver-web-cache 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-web-cache.api.md +3 -3
- package/dist/FluidCache.d.ts +1 -1
- package/dist/FluidCache.d.ts.map +1 -1
- package/dist/FluidCache.js +11 -11
- package/dist/FluidCache.js.map +1 -1
- package/dist/FluidCacheIndexedDb.d.ts +2 -2
- package/dist/FluidCacheIndexedDb.d.ts.map +1 -1
- package/dist/FluidCacheIndexedDb.js +2 -2
- package/dist/FluidCacheIndexedDb.js.map +1 -1
- package/dist/legacy.d.ts +16 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +12 -0
- package/internal.d.ts +11 -0
- package/legacy.d.ts +11 -0
- package/lib/FluidCache.d.ts +1 -1
- package/lib/FluidCache.d.ts.map +1 -1
- package/lib/FluidCache.js +5 -5
- package/lib/FluidCache.js.map +1 -1
- package/lib/FluidCacheIndexedDb.d.ts +2 -2
- package/lib/FluidCacheIndexedDb.d.ts.map +1 -1
- package/lib/FluidCacheIndexedDb.js +2 -2
- package/lib/FluidCacheIndexedDb.js.map +1 -1
- package/lib/legacy.d.ts +16 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +12 -0
- package/package.json +27 -48
- package/src/FluidCache.ts +10 -12
- package/src/FluidCacheIndexedDb.ts +4 -3
- package/src/packageVersion.ts +1 -1
- package/api-extractor-cjs.json +0 -8
- package/dist/driver-web-cache-alpha.d.ts +0 -65
- package/dist/driver-web-cache-beta.d.ts +0 -19
- package/dist/driver-web-cache-public.d.ts +0 -19
- package/dist/driver-web-cache-untrimmed.d.ts +0 -65
- package/lib/driver-web-cache-alpha.d.ts +0 -65
- package/lib/driver-web-cache-beta.d.ts +0 -19
- package/lib/driver-web-cache-public.d.ts +0 -19
- package/lib/driver-web-cache-untrimmed.d.ts +0 -65
- package/lib/test/FluidCache.test.js +0 -196
- package/lib/test/FluidCache.test.js.map +0 -1
- package/lib/test/FluidCacheIndexedDb.test.js +0 -77
- package/lib/test/FluidCacheIndexedDb.test.js.map +0 -1
- package/lib/test/FluidCacheTimer.test.js +0 -100
- package/lib/test/FluidCacheTimer.test.js.map +0 -1
- package/lib/test/types/validateDriverWebCachePrevious.generated.js +0 -8
- package/lib/test/types/validateDriverWebCachePrevious.generated.js.map +0 -1
- /package/{dist → lib}/tsdoc-metadata.json +0 -0
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { openDB } from "idb";
|
|
6
|
-
import { FluidCache } from "../FluidCache.js";
|
|
7
|
-
import { getFluidCacheIndexedDbInstance, FluidDriverObjectStoreName, FluidDriverCacheDBName, getKeyForCacheEntry, } from "../FluidCacheIndexedDb.js";
|
|
8
|
-
// eslint-disable-next-line import/no-unassigned-import, @typescript-eslint/no-require-imports, import/no-internal-modules
|
|
9
|
-
require("fake-indexeddb/auto");
|
|
10
|
-
const mockPartitionKey = "FAKEPARTITIONKEY";
|
|
11
|
-
class DateMock {
|
|
12
|
-
static now() {
|
|
13
|
-
return DateMock.mockTimeMs;
|
|
14
|
-
}
|
|
15
|
-
getTime() {
|
|
16
|
-
return DateMock.mockTimeMs;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
// The current time being used by the mock
|
|
20
|
-
DateMock.mockTimeMs = 0;
|
|
21
|
-
// Sets up a mock date time for the current test. Returns a function that should be called to reset the environment
|
|
22
|
-
function setupDateMock(startMockTime) {
|
|
23
|
-
const realDate = window.Date;
|
|
24
|
-
DateMock.mockTimeMs = startMockTime;
|
|
25
|
-
window.Date = DateMock;
|
|
26
|
-
return () => (window.Date = realDate);
|
|
27
|
-
}
|
|
28
|
-
// Gets a mock cache entry from an item key, all entries returned will be for the same document.
|
|
29
|
-
function getMockCacheEntry(itemKey, options) {
|
|
30
|
-
return {
|
|
31
|
-
file: {
|
|
32
|
-
docId: options?.docId ?? "myDocument",
|
|
33
|
-
resolvedUrl: {
|
|
34
|
-
type: "fluid",
|
|
35
|
-
url: "https://bing.com/myDocument",
|
|
36
|
-
id: "mockContainer",
|
|
37
|
-
tokens: {},
|
|
38
|
-
endpoints: {},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
type: "snapshot",
|
|
42
|
-
key: itemKey,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
[true, false].forEach((immediateClose) => {
|
|
46
|
-
function getFluidCache(config) {
|
|
47
|
-
return new FluidCache({
|
|
48
|
-
partitionKey: config?.partitionKey ?? mockPartitionKey,
|
|
49
|
-
maxCacheItemAge: config?.maxCacheItemAge ?? 3 * 24 * 60 * 60 * 1000,
|
|
50
|
-
closeDbAfterMs: immediateClose ? 0 : 100,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
describe(`Fluid Cache tests: immediateClose: ${immediateClose}`, () => {
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
// Reset the indexed db before each test so that it starts off in an empty state
|
|
56
|
-
// eslint-disable-next-line import/no-internal-modules, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
57
|
-
const FDBFactory = require("fake-indexeddb/lib/FDBFactory");
|
|
58
|
-
window.indexedDB = new FDBFactory();
|
|
59
|
-
});
|
|
60
|
-
it("returns undefined when there is nothing in the cache", async () => {
|
|
61
|
-
const fluidCache = getFluidCache();
|
|
62
|
-
const result = await fluidCache.get(getMockCacheEntry("shouldNotExist"));
|
|
63
|
-
expect(result).toBeUndefined();
|
|
64
|
-
});
|
|
65
|
-
it("returns an item put in the cache", async () => {
|
|
66
|
-
const fluidCache = getFluidCache();
|
|
67
|
-
const cacheEntry = getMockCacheEntry("shouldExist");
|
|
68
|
-
const cachedItem = { foo: "bar" };
|
|
69
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
70
|
-
const result = await fluidCache.get(cacheEntry);
|
|
71
|
-
expect(result).toEqual(cachedItem);
|
|
72
|
-
});
|
|
73
|
-
it("returns an item put in the cache when max ops has not passed", async () => {
|
|
74
|
-
const fluidCache = getFluidCache();
|
|
75
|
-
const cacheEntry = getMockCacheEntry("stillGood");
|
|
76
|
-
const cachedItem = { foo: "bar" };
|
|
77
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
78
|
-
const result = await fluidCache.get(cacheEntry);
|
|
79
|
-
expect(result).toEqual(cachedItem);
|
|
80
|
-
});
|
|
81
|
-
it("does not return an item from the cache that is older than maxCacheItemAge", async () => {
|
|
82
|
-
const clearTimeMock = setupDateMock(100);
|
|
83
|
-
const fluidCache = getFluidCache({ maxCacheItemAge: 5000 });
|
|
84
|
-
const cacheEntry = getMockCacheEntry("tooOld");
|
|
85
|
-
const cachedItem = { foo: "bar" };
|
|
86
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
87
|
-
expect(await fluidCache.get(cacheEntry)).toEqual(cachedItem);
|
|
88
|
-
DateMock.mockTimeMs += 5050;
|
|
89
|
-
const result = await fluidCache.get(cacheEntry);
|
|
90
|
-
expect(result).toBeUndefined();
|
|
91
|
-
clearTimeMock();
|
|
92
|
-
});
|
|
93
|
-
it("does not return items from the cache when the partition keys do not match", async () => {
|
|
94
|
-
const fluidCache = getFluidCache({ partitionKey: "partitionKey1" });
|
|
95
|
-
const cacheEntry = getMockCacheEntry("partitionKey1Data");
|
|
96
|
-
const cachedItem = { foo: "bar" };
|
|
97
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
98
|
-
expect(await fluidCache.get(cacheEntry)).toEqual(cachedItem);
|
|
99
|
-
// We should not return the data from partition 1 when in partition 2
|
|
100
|
-
const partition2FluidCache = getFluidCache({
|
|
101
|
-
partitionKey: "partitionKey2",
|
|
102
|
-
});
|
|
103
|
-
expect(await partition2FluidCache.get(cacheEntry)).toEqual(undefined);
|
|
104
|
-
});
|
|
105
|
-
it("returns values from cache when partition key is null", async () => {
|
|
106
|
-
const fluidCache = getFluidCache({ partitionKey: null });
|
|
107
|
-
const cacheEntry = getMockCacheEntry("partitionKey1Data");
|
|
108
|
-
const cachedItem = { foo: "bar" };
|
|
109
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
110
|
-
expect(await fluidCache.get(cacheEntry)).toEqual(cachedItem);
|
|
111
|
-
});
|
|
112
|
-
it("implements the removeAllEntriesForDocId API", async () => {
|
|
113
|
-
const fluidCache = getFluidCache();
|
|
114
|
-
const docId1Entry1 = getMockCacheEntry("docId1Entry1", {
|
|
115
|
-
docId: "docId1",
|
|
116
|
-
});
|
|
117
|
-
const docId2Entry1 = getMockCacheEntry("docId2Entry1", {
|
|
118
|
-
docId: "docId2",
|
|
119
|
-
});
|
|
120
|
-
const docId1Entry2 = getMockCacheEntry("docId1Entry2", {
|
|
121
|
-
docId: "docId1",
|
|
122
|
-
});
|
|
123
|
-
await fluidCache.put(docId1Entry1, {});
|
|
124
|
-
await fluidCache.put(docId2Entry1, {});
|
|
125
|
-
await fluidCache.put(docId1Entry2, {});
|
|
126
|
-
expect(await fluidCache.get(docId1Entry1)).not.toBeUndefined();
|
|
127
|
-
expect(await fluidCache.get(docId2Entry1)).not.toBeUndefined();
|
|
128
|
-
expect(await fluidCache.get(docId1Entry2)).not.toBeUndefined();
|
|
129
|
-
await fluidCache.removeEntries(docId1Entry1.file);
|
|
130
|
-
expect(await fluidCache.get(docId1Entry1)).toBeUndefined();
|
|
131
|
-
expect(await fluidCache.get(docId2Entry1)).not.toBeUndefined();
|
|
132
|
-
expect(await fluidCache.get(docId1Entry2)).toBeUndefined();
|
|
133
|
-
});
|
|
134
|
-
// The tests above test the public API of Fluid Cache.
|
|
135
|
-
// Those tests should not break if we changed the implementation.
|
|
136
|
-
// The tests below test implementation details of the Fluid Cache, such as the usage of indexedDB.
|
|
137
|
-
it("writes cached values to indexedDb", async () => {
|
|
138
|
-
// We need to mock out the Date API to make this test work
|
|
139
|
-
const clearDateMock = setupDateMock(100);
|
|
140
|
-
const fluidCache = getFluidCache();
|
|
141
|
-
const cacheEntry = getMockCacheEntry("shouldBeInLocalStorage");
|
|
142
|
-
const cachedItem = { dateToStore: "foo" };
|
|
143
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
144
|
-
const db = await getFluidCacheIndexedDbInstance();
|
|
145
|
-
expect(await db.get(FluidDriverObjectStoreName, getKeyForCacheEntry(cacheEntry))).toEqual({
|
|
146
|
-
cacheItemId: "shouldBeInLocalStorage",
|
|
147
|
-
cachedObject: {
|
|
148
|
-
dateToStore: "foo",
|
|
149
|
-
},
|
|
150
|
-
createdTimeMs: 100,
|
|
151
|
-
fileId: "myDocument",
|
|
152
|
-
lastAccessTimeMs: 100,
|
|
153
|
-
type: "snapshot",
|
|
154
|
-
partitionKey: "FAKEPARTITIONKEY",
|
|
155
|
-
});
|
|
156
|
-
clearDateMock();
|
|
157
|
-
});
|
|
158
|
-
it("does not throw when APIs are called and the database has been upgraded by another client", async () => {
|
|
159
|
-
// Create a DB with a much newer version number to simulate an old client
|
|
160
|
-
await openDB(FluidDriverCacheDBName, 1000000);
|
|
161
|
-
const fluidCache = getFluidCache();
|
|
162
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
163
|
-
const cachedItem = { dateToStore: "foo" };
|
|
164
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
165
|
-
const result = await fluidCache.get(cacheEntry);
|
|
166
|
-
expect(result).toEqual(undefined);
|
|
167
|
-
});
|
|
168
|
-
it("does not hang when an older client is blocking the database from opening", async () => {
|
|
169
|
-
await openDB(FluidDriverCacheDBName, 1);
|
|
170
|
-
const fluidCache = getFluidCache();
|
|
171
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
172
|
-
const cachedItem = { dateToStore: "foo" };
|
|
173
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
174
|
-
const result = await fluidCache.get(cacheEntry);
|
|
175
|
-
expect(result).toEqual(undefined);
|
|
176
|
-
});
|
|
177
|
-
it("does not hang when client is getting data after putting in the cache", async () => {
|
|
178
|
-
const fluidCache = getFluidCache();
|
|
179
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
180
|
-
const cachedItem = { dateToStore: "foo" };
|
|
181
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
182
|
-
const result = await fluidCache.get(cacheEntry);
|
|
183
|
-
expect(result).toEqual(cachedItem);
|
|
184
|
-
});
|
|
185
|
-
it("does not hang when client is getting data after removing the entry from cache", async () => {
|
|
186
|
-
const fluidCache = getFluidCache();
|
|
187
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
188
|
-
const cachedItem = { dateToStore: "foo" };
|
|
189
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
190
|
-
await fluidCache.removeEntries(cacheEntry.file);
|
|
191
|
-
const result = await fluidCache.get(cacheEntry);
|
|
192
|
-
expect(result).toEqual(undefined);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
//# sourceMappingURL=FluidCache.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FluidCache.test.js","sourceRoot":"","sources":["../../src/test/FluidCache.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACN,8BAA8B,EAC9B,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,0HAA0H;AAC1H,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAE/B,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C,MAAM,QAAQ;IAIN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C,UAAU,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;YACrF,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;YAEnC,MAAM,UAAU,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,UAAU,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;YAC1C,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YAE7C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+EAA+E,EAAE,KAAK,IAAI,EAAE;YAC9F,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;YAEnC,MAAM,UAAU,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,UAAU,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;YAC1C,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YAC7C,MAAM,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAChD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACJ,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 { ICacheEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { openDB } from \"idb\";\nimport { FluidCache } from \"../FluidCache.js\";\nimport {\n\tgetFluidCacheIndexedDbInstance,\n\tFluidDriverObjectStoreName,\n\tFluidDriverCacheDBName,\n\tgetKeyForCacheEntry,\n} from \"../FluidCacheIndexedDb.js\";\n\n// eslint-disable-next-line import/no-unassigned-import, @typescript-eslint/no-require-imports, import/no-internal-modules\nrequire(\"fake-indexeddb/auto\");\n\nconst mockPartitionKey = \"FAKEPARTITIONKEY\";\n\nclass DateMock {\n\t// The current time being used by the mock\n\tpublic static mockTimeMs: number = 0;\n\n\tpublic static now() {\n\t\treturn DateMock.mockTimeMs;\n\t}\n\n\tpublic getTime() {\n\t\treturn DateMock.mockTimeMs;\n\t}\n}\n\n// Sets up a mock date time for the current test. Returns a function that should be called to reset the environment\nfunction setupDateMock(startMockTime: number) {\n\tconst realDate = window.Date;\n\tDateMock.mockTimeMs = startMockTime;\n\t(window.Date as any) = DateMock;\n\n\treturn () => (window.Date = realDate);\n}\n\n// Gets a mock cache entry from an item key, all entries returned will be for the same document.\nfunction getMockCacheEntry(itemKey: string, options?: { docId: string }): ICacheEntry {\n\treturn {\n\t\tfile: {\n\t\t\tdocId: options?.docId ?? \"myDocument\",\n\t\t\tresolvedUrl: {\n\t\t\t\ttype: \"fluid\",\n\t\t\t\turl: \"https://bing.com/myDocument\",\n\t\t\t\tid: \"mockContainer\",\n\t\t\t\ttokens: {},\n\t\t\t\tendpoints: {},\n\t\t\t},\n\t\t},\n\t\ttype: \"snapshot\",\n\t\tkey: itemKey,\n\t};\n}\n\n[true, false].forEach((immediateClose) => {\n\tfunction getFluidCache(config?: {\n\t\tmaxCacheItemAge?: number;\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpartitionKey?: string | null;\n\t}) {\n\t\treturn new FluidCache({\n\t\t\tpartitionKey: config?.partitionKey ?? mockPartitionKey,\n\t\t\tmaxCacheItemAge: config?.maxCacheItemAge ?? 3 * 24 * 60 * 60 * 1000,\n\t\t\tcloseDbAfterMs: immediateClose ? 0 : 100,\n\t\t});\n\t}\n\tdescribe(`Fluid Cache tests: immediateClose: ${immediateClose}`, () => {\n\t\tbeforeEach(() => {\n\t\t\t// Reset the indexed db before each test so that it starts off in an empty state\n\t\t\t// eslint-disable-next-line import/no-internal-modules, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires\n\t\t\tconst FDBFactory = require(\"fake-indexeddb/lib/FDBFactory\");\n\t\t\t(window.indexedDB as any) = new FDBFactory();\n\t\t});\n\n\t\tit(\"returns undefined when there is nothing in the cache\", async () => {\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst result = await fluidCache.get(getMockCacheEntry(\"shouldNotExist\"));\n\t\t\texpect(result).toBeUndefined();\n\t\t});\n\n\t\tit(\"returns an item put in the cache\", async () => {\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"shouldExist\");\n\t\t\tconst cachedItem = { foo: \"bar\" };\n\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toEqual(cachedItem);\n\t\t});\n\n\t\tit(\"returns an item put in the cache when max ops has not passed\", async () => {\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"stillGood\");\n\t\t\tconst cachedItem = { foo: \"bar\" };\n\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toEqual(cachedItem);\n\t\t});\n\n\t\tit(\"does not return an item from the cache that is older than maxCacheItemAge\", async () => {\n\t\t\tconst clearTimeMock = setupDateMock(100);\n\n\t\t\tconst fluidCache = getFluidCache({ maxCacheItemAge: 5000 });\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"tooOld\");\n\t\t\tconst cachedItem = { foo: \"bar\" };\n\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\texpect(await fluidCache.get(cacheEntry)).toEqual(cachedItem);\n\n\t\t\tDateMock.mockTimeMs += 5050;\n\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toBeUndefined();\n\n\t\t\tclearTimeMock();\n\t\t});\n\n\t\tit(\"does not return items from the cache when the partition keys do not match\", async () => {\n\t\t\tconst fluidCache = getFluidCache({ partitionKey: \"partitionKey1\" });\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"partitionKey1Data\");\n\t\t\tconst cachedItem = { foo: \"bar\" };\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\texpect(await fluidCache.get(cacheEntry)).toEqual(cachedItem);\n\n\t\t\t// We should not return the data from partition 1 when in partition 2\n\t\t\tconst partition2FluidCache = getFluidCache({\n\t\t\t\tpartitionKey: \"partitionKey2\",\n\t\t\t});\n\t\t\texpect(await partition2FluidCache.get(cacheEntry)).toEqual(undefined);\n\t\t});\n\n\t\tit(\"returns values from cache when partition key is null\", async () => {\n\t\t\tconst fluidCache = getFluidCache({ partitionKey: null });\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"partitionKey1Data\");\n\t\t\tconst cachedItem = { foo: \"bar\" };\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\texpect(await fluidCache.get(cacheEntry)).toEqual(cachedItem);\n\t\t});\n\n\t\tit(\"implements the removeAllEntriesForDocId API\", async () => {\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst docId1Entry1 = getMockCacheEntry(\"docId1Entry1\", {\n\t\t\t\tdocId: \"docId1\",\n\t\t\t});\n\t\t\tconst docId2Entry1 = getMockCacheEntry(\"docId2Entry1\", {\n\t\t\t\tdocId: \"docId2\",\n\t\t\t});\n\t\t\tconst docId1Entry2 = getMockCacheEntry(\"docId1Entry2\", {\n\t\t\t\tdocId: \"docId1\",\n\t\t\t});\n\n\t\t\tawait fluidCache.put(docId1Entry1, {});\n\t\t\tawait fluidCache.put(docId2Entry1, {});\n\t\t\tawait fluidCache.put(docId1Entry2, {});\n\n\t\t\texpect(await fluidCache.get(docId1Entry1)).not.toBeUndefined();\n\t\t\texpect(await fluidCache.get(docId2Entry1)).not.toBeUndefined();\n\t\t\texpect(await fluidCache.get(docId1Entry2)).not.toBeUndefined();\n\n\t\t\tawait fluidCache.removeEntries(docId1Entry1.file);\n\n\t\t\texpect(await fluidCache.get(docId1Entry1)).toBeUndefined();\n\t\t\texpect(await fluidCache.get(docId2Entry1)).not.toBeUndefined();\n\t\t\texpect(await fluidCache.get(docId1Entry2)).toBeUndefined();\n\t\t});\n\n\t\t// The tests above test the public API of Fluid Cache.\n\t\t// Those tests should not break if we changed the implementation.\n\t\t// The tests below test implementation details of the Fluid Cache, such as the usage of indexedDB.\n\t\tit(\"writes cached values to indexedDb\", async () => {\n\t\t\t// We need to mock out the Date API to make this test work\n\t\t\tconst clearDateMock = setupDateMock(100);\n\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"shouldBeInLocalStorage\");\n\t\t\tconst cachedItem = { dateToStore: \"foo\" };\n\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\tconst db = await getFluidCacheIndexedDbInstance();\n\t\t\texpect(\n\t\t\t\tawait db.get(FluidDriverObjectStoreName, getKeyForCacheEntry(cacheEntry)),\n\t\t\t).toEqual({\n\t\t\t\tcacheItemId: \"shouldBeInLocalStorage\",\n\t\t\t\tcachedObject: {\n\t\t\t\t\tdateToStore: \"foo\",\n\t\t\t\t},\n\t\t\t\tcreatedTimeMs: 100,\n\t\t\t\tfileId: \"myDocument\",\n\t\t\t\tlastAccessTimeMs: 100,\n\t\t\t\ttype: \"snapshot\",\n\t\t\t\tpartitionKey: \"FAKEPARTITIONKEY\",\n\t\t\t});\n\n\t\t\tclearDateMock();\n\t\t});\n\n\t\tit(\"does not throw when APIs are called and the database has been upgraded by another client\", async () => {\n\t\t\t// Create a DB with a much newer version number to simulate an old client\n\t\t\tawait openDB(FluidDriverCacheDBName, 1000000);\n\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toEqual(undefined);\n\t\t});\n\n\t\tit(\"does not hang when an older client is blocking the database from opening\", async () => {\n\t\t\tawait openDB(FluidDriverCacheDBName, 1);\n\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toEqual(undefined);\n\t\t});\n\n\t\tit(\"does not hang when client is getting data after putting in the cache\", async () => {\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toEqual(cachedItem);\n\t\t});\n\n\t\tit(\"does not hang when client is getting data after removing the entry from cache\", async () => {\n\t\t\tconst fluidCache = getFluidCache();\n\n\t\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\t\t\tawait fluidCache.removeEntries(cacheEntry.file);\n\t\t\tconst result = await fluidCache.get(cacheEntry);\n\t\t\texpect(result).toEqual(undefined);\n\t\t});\n\t});\n});\n"]}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { openDB } from "idb";
|
|
6
|
-
import { getFluidCacheIndexedDbInstance, oldVersionNameMapping, FluidDriverCacheDBName, FluidDriverObjectStoreName, CurrentCacheVersion, } from "../FluidCacheIndexedDb.js";
|
|
7
|
-
// eslint-disable-next-line import/no-unassigned-import, @typescript-eslint/no-require-imports, import/no-internal-modules
|
|
8
|
-
require("fake-indexeddb/auto");
|
|
9
|
-
class MockLogger {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.NamespaceLogger = this;
|
|
12
|
-
this.send = jest.fn();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const versions = Object.keys(oldVersionNameMapping);
|
|
16
|
-
// Dynamically get the test cases for successful upgrades to run though all old versions
|
|
17
|
-
const getUpgradeTestCases = (versionsArray) => {
|
|
18
|
-
const testCases = [];
|
|
19
|
-
versionsArray.map((value) => {
|
|
20
|
-
testCases.push([
|
|
21
|
-
`upgrades successfully without an error for version number ${value}`,
|
|
22
|
-
{ oldVersionNumber: parseInt(value, 10 /* base10 */) },
|
|
23
|
-
]);
|
|
24
|
-
});
|
|
25
|
-
return testCases;
|
|
26
|
-
};
|
|
27
|
-
const upgradeTestCases = getUpgradeTestCases(versions);
|
|
28
|
-
describe("getFluidCacheIndexedDbInstance", () => {
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
// Reset the indexed db before each test so that it starts off in an empty state
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, import/no-internal-modules
|
|
32
|
-
const FDBFactory = require("fake-indexeddb/lib/FDBFactory");
|
|
33
|
-
window.indexedDB = new FDBFactory();
|
|
34
|
-
});
|
|
35
|
-
// The jest types in the FF repo are old, so it doesn't have the each signature.
|
|
36
|
-
// This typecast can be removed when the types are bumped.
|
|
37
|
-
it.each(upgradeTestCases)("%s", async (_, { oldVersionNumber }) => {
|
|
38
|
-
// Arrange
|
|
39
|
-
// Create a database with the old version number
|
|
40
|
-
const oldDb = await openDB(FluidDriverCacheDBName, oldVersionNumber, {
|
|
41
|
-
upgrade: (dbToUpgrade) => {
|
|
42
|
-
// Create the old object to simulate what state we would be in
|
|
43
|
-
dbToUpgrade.createObjectStore(oldVersionNameMapping[oldVersionNumber]);
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
oldDb.close(); // Close so the upgrade won't be blocked
|
|
47
|
-
// Act
|
|
48
|
-
// Now attempt to get the FluidCache instance, which will run the upgrade function
|
|
49
|
-
const db = await getFluidCacheIndexedDbInstance();
|
|
50
|
-
// Assert
|
|
51
|
-
expect(db.objectStoreNames).toEqual([FluidDriverObjectStoreName]);
|
|
52
|
-
expect(db.name).toEqual(FluidDriverCacheDBName);
|
|
53
|
-
expect(db.version).toEqual(CurrentCacheVersion);
|
|
54
|
-
});
|
|
55
|
-
it("if error thrown in deletion of old database, is swallowed and logged", async () => {
|
|
56
|
-
// Arrange
|
|
57
|
-
// Create a database with the old version number, but DONT create the data store.
|
|
58
|
-
// This will cause an error that we should catch in the upgrade function where we
|
|
59
|
-
// delete the old data store.
|
|
60
|
-
const oldDb = await openDB(FluidDriverCacheDBName, CurrentCacheVersion - 1);
|
|
61
|
-
oldDb.close(); // Close so the upgrade won't be blocked
|
|
62
|
-
const logger = new MockLogger();
|
|
63
|
-
const sendSpy = jest.spyOn(logger, "send");
|
|
64
|
-
// Act
|
|
65
|
-
// Now attempt to get the FluidCache instance, which will run the upgrade function
|
|
66
|
-
const db = await getFluidCacheIndexedDbInstance(logger);
|
|
67
|
-
// Assert
|
|
68
|
-
// We catch the error and send it to the logger
|
|
69
|
-
expect(sendSpy.mock.calls).toHaveLength(1);
|
|
70
|
-
expect(sendSpy.mock.calls[0][0].eventName).toEqual("FluidCacheDeleteOldDbError" /* FluidCacheErrorEvent.FluidCacheDeleteOldDbError */);
|
|
71
|
-
// The cache was still created as expected
|
|
72
|
-
expect(db.objectStoreNames).toEqual([FluidDriverObjectStoreName]);
|
|
73
|
-
expect(db.name).toEqual(FluidDriverCacheDBName);
|
|
74
|
-
expect(db.version).toEqual(CurrentCacheVersion);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=FluidCacheIndexedDb.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FluidCacheIndexedDb.test.js","sourceRoot":"","sources":["../../src/test/FluidCacheIndexedDb.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EACN,8BAA8B,EAC9B,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,GACnB,MAAM,2BAA2B,CAAC;AAGnC,0HAA0H;AAC1H,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAE/B,MAAM,UAAU;IAAhB;QACC,oBAAe,GAAG,IAAI,CAAC;QACvB,SAAI,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAClB,CAAC;CAAA;AAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAEpD,wFAAwF;AACxF,MAAM,mBAAmB,GAAG,CAAC,aAAuB,EAAS,EAAE;IAC9D,MAAM,SAAS,GAAU,EAAE,CAAC;IAC5B,aAAa,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE;QACnC,SAAS,CAAC,IAAI,CAAC;YACd,6DAA6D,KAAK,EAAE;YACpE,EAAE,gBAAgB,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE;SACtD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AACF,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAEvD,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC/C,UAAU,CAAC,GAAG,EAAE;QACf,gFAAgF;QAChF,iIAAi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GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAE3C,MAAM;QACN,kFAAkF;QAClF,MAAM,EAAE,GAAG,MAAM,8BAA8B,CAAC,MAAM,CAAC,CAAC;QAExD,SAAS;QACT,+CAA+C;QAC/C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,oFAEjD,CAAC;QAEF,0CAA0C;QAC1C,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC;QAClE,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAChD,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,mBAAmB,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 { openDB } from \"idb\";\nimport {\n\tgetFluidCacheIndexedDbInstance,\n\toldVersionNameMapping,\n\tFluidDriverCacheDBName,\n\tFluidDriverObjectStoreName,\n\tCurrentCacheVersion,\n} from \"../FluidCacheIndexedDb.js\";\nimport { FluidCacheErrorEvent } from \"../fluidCacheTelemetry.js\";\n\n// eslint-disable-next-line import/no-unassigned-import, @typescript-eslint/no-require-imports, import/no-internal-modules\nrequire(\"fake-indexeddb/auto\");\n\nclass MockLogger {\n\tNamespaceLogger = this;\n\tsend = jest.fn();\n}\n\nconst versions = Object.keys(oldVersionNameMapping);\n\n// Dynamically get the test cases for successful upgrades to run though all old versions\nconst getUpgradeTestCases = (versionsArray: string[]): any[] => {\n\tconst testCases: any[] = [];\n\tversionsArray.map((value: string) => {\n\t\ttestCases.push([\n\t\t\t`upgrades successfully without an error for version number ${value}`,\n\t\t\t{ oldVersionNumber: parseInt(value, 10 /* base10 */) },\n\t\t]);\n\t});\n\treturn testCases;\n};\nconst upgradeTestCases = getUpgradeTestCases(versions);\n\ndescribe(\"getFluidCacheIndexedDbInstance\", () => {\n\tbeforeEach(() => {\n\t\t// Reset the indexed db before each test so that it starts off in an empty state\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, import/no-internal-modules\n\t\tconst FDBFactory = require(\"fake-indexeddb/lib/FDBFactory\");\n\t\t(window.indexedDB as any) = new FDBFactory();\n\t});\n\n\t// The jest types in the FF repo are old, so it doesn't have the each signature.\n\t// This typecast can be removed when the types are bumped.\n\t(it as any).each(upgradeTestCases)(\"%s\", async (_, { oldVersionNumber }) => {\n\t\t// Arrange\n\t\t// Create a database with the old version number\n\t\tconst oldDb = await openDB(FluidDriverCacheDBName, oldVersionNumber, {\n\t\t\tupgrade: (dbToUpgrade) => {\n\t\t\t\t// Create the old object to simulate what state we would be in\n\t\t\t\tdbToUpgrade.createObjectStore(oldVersionNameMapping[oldVersionNumber]!);\n\t\t\t},\n\t\t});\n\t\toldDb.close(); // Close so the upgrade won't be blocked\n\n\t\t// Act\n\t\t// Now attempt to get the FluidCache instance, which will run the upgrade function\n\t\tconst db = await getFluidCacheIndexedDbInstance();\n\n\t\t// Assert\n\t\texpect(db.objectStoreNames).toEqual([FluidDriverObjectStoreName]);\n\t\texpect(db.name).toEqual(FluidDriverCacheDBName);\n\t\texpect(db.version).toEqual(CurrentCacheVersion);\n\t});\n\n\tit(\"if error thrown in deletion of old database, is swallowed and logged\", async () => {\n\t\t// Arrange\n\t\t// Create a database with the old version number, but DONT create the data store.\n\t\t// This will cause an error that we should catch in the upgrade function where we\n\t\t// delete the old data store.\n\t\tconst oldDb = await openDB(FluidDriverCacheDBName, CurrentCacheVersion - 1);\n\t\toldDb.close(); // Close so the upgrade won't be blocked\n\n\t\tconst logger = new MockLogger();\n\t\tconst sendSpy = jest.spyOn(logger, \"send\");\n\n\t\t// Act\n\t\t// Now attempt to get the FluidCache instance, which will run the upgrade function\n\t\tconst db = await getFluidCacheIndexedDbInstance(logger);\n\n\t\t// Assert\n\t\t// We catch the error and send it to the logger\n\t\texpect(sendSpy.mock.calls).toHaveLength(1);\n\t\texpect(sendSpy.mock.calls[0][0].eventName).toEqual(\n\t\t\tFluidCacheErrorEvent.FluidCacheDeleteOldDbError,\n\t\t);\n\n\t\t// The cache was still created as expected\n\t\texpect(db.objectStoreNames).toEqual([FluidDriverObjectStoreName]);\n\t\texpect(db.name).toEqual(FluidDriverCacheDBName);\n\t\texpect(db.version).toEqual(CurrentCacheVersion);\n\t});\n});\n"]}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/* eslint-disable @typescript-eslint/dot-notation */
|
|
6
|
-
import { openDB } from "idb";
|
|
7
|
-
import { MockLogger } from "@fluidframework/telemetry-utils";
|
|
8
|
-
import { delay } from "@fluidframework/core-utils";
|
|
9
|
-
import { FluidDriverCacheDBName } from "../FluidCacheIndexedDb.js";
|
|
10
|
-
import { FluidCache } from "../FluidCache.js";
|
|
11
|
-
// eslint-disable-next-line import/no-unassigned-import, @typescript-eslint/no-require-imports, import/no-internal-modules
|
|
12
|
-
require("fake-indexeddb/auto");
|
|
13
|
-
const mockPartitionKey = "FAKEPARTITIONKEY";
|
|
14
|
-
function getFluidCache(config) {
|
|
15
|
-
return new FluidCache({
|
|
16
|
-
partitionKey: config?.partitionKey ?? mockPartitionKey,
|
|
17
|
-
maxCacheItemAge: config?.maxCacheItemAge ?? 3 * 24 * 60 * 60 * 1000,
|
|
18
|
-
logger: config?.logger,
|
|
19
|
-
closeDbAfterMs: 100,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
class DateMock {
|
|
23
|
-
static now() {
|
|
24
|
-
return DateMock.mockTimeMs;
|
|
25
|
-
}
|
|
26
|
-
getTime() {
|
|
27
|
-
return DateMock.mockTimeMs;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// The current time being used by the mock
|
|
31
|
-
DateMock.mockTimeMs = 0;
|
|
32
|
-
// Sets up a mock date time for the current test. Returns a function that should be called to reset the environment
|
|
33
|
-
export function setupDateMock(startMockTime) {
|
|
34
|
-
const realDate = window.Date;
|
|
35
|
-
DateMock.mockTimeMs = startMockTime;
|
|
36
|
-
window.Date = DateMock;
|
|
37
|
-
return () => (window.Date = realDate);
|
|
38
|
-
}
|
|
39
|
-
// Gets a mock cache entry from an item key, all entries returned will be for the same document.
|
|
40
|
-
function getMockCacheEntry(itemKey, options) {
|
|
41
|
-
return {
|
|
42
|
-
file: {
|
|
43
|
-
docId: options?.docId ?? "myDocument",
|
|
44
|
-
resolvedUrl: {
|
|
45
|
-
type: "fluid",
|
|
46
|
-
url: "https://bing.com/myDocument",
|
|
47
|
-
id: "mockContainer",
|
|
48
|
-
tokens: {},
|
|
49
|
-
endpoints: {},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
type: "snapshot",
|
|
53
|
-
key: itemKey,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
describe("FluidCacheTimer tests", () => {
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
// Reset the indexed db before each test so that it starts off in an empty state
|
|
59
|
-
// eslint-disable-next-line import/no-internal-modules, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
60
|
-
const FDBFactory = require("fake-indexeddb/lib/FDBFactory");
|
|
61
|
-
window.indexedDB = new FDBFactory();
|
|
62
|
-
});
|
|
63
|
-
it("db should be closed after the close timer", async () => {
|
|
64
|
-
const logger = new MockLogger();
|
|
65
|
-
const fluidCache = getFluidCache({ logger });
|
|
66
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
67
|
-
const cachedItem = { dateToStore: "foo" };
|
|
68
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
69
|
-
expect(fluidCache["db"] !== undefined).toEqual(true);
|
|
70
|
-
// Wait for timer to pass.
|
|
71
|
-
await delay(101);
|
|
72
|
-
expect(fluidCache["db"] === undefined).toEqual(true);
|
|
73
|
-
expect(fluidCache["dbCloseTimer"] === undefined).toEqual(true);
|
|
74
|
-
});
|
|
75
|
-
it("db should be closed after the version upgrade", async () => {
|
|
76
|
-
const logger = new MockLogger();
|
|
77
|
-
const fluidCache = getFluidCache({ logger });
|
|
78
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
79
|
-
const cachedItem = { dateToStore: "foo" };
|
|
80
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
81
|
-
expect(fluidCache["db"] !== undefined).toEqual(true);
|
|
82
|
-
// Create a DB with a much newer version number to force version upgrade on older cache causing it to close.
|
|
83
|
-
await openDB(FluidDriverCacheDBName, 1000000);
|
|
84
|
-
expect(fluidCache["db"] === undefined).toEqual(true);
|
|
85
|
-
expect(fluidCache["dbCloseTimer"] === undefined).toEqual(true);
|
|
86
|
-
});
|
|
87
|
-
it("db should be closed after the version upgrade", async () => {
|
|
88
|
-
const logger = new MockLogger();
|
|
89
|
-
const fluidCache = getFluidCache({ logger });
|
|
90
|
-
const cacheEntry = getMockCacheEntry("someKey");
|
|
91
|
-
const cachedItem = { dateToStore: "foo" };
|
|
92
|
-
await fluidCache.put(cacheEntry, cachedItem);
|
|
93
|
-
expect(fluidCache["db"] !== undefined).toEqual(true);
|
|
94
|
-
// Create a DB with a much newer version number to force version upgrade on older cache causing it to close.
|
|
95
|
-
await openDB(FluidDriverCacheDBName, 1000000);
|
|
96
|
-
expect(fluidCache["db"] === undefined).toEqual(true);
|
|
97
|
-
expect(fluidCache["dbCloseTimer"] === undefined).toEqual(true);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
//# sourceMappingURL=FluidCacheTimer.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FluidCacheTimer.test.js","sourceRoot":"","sources":["../../src/test/FluidCacheTimer.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oDAAoD;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,0HAA0H;AAC1H,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAE/B,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C,SAAS,aAAa,CAAC,MAKtB;IACA,OAAO,IAAI,UAAU,CAAC;QACrB,YAAY,EAAE,MAAM,EAAE,YAAY,IAAI,gBAAgB;QACtD,eAAe,EAAE,MAAM,EAAE,eAAe,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;QACnE,MAAM,EAAE,MAAM,EAAE,MAAM;QACtB,cAAc,EAAE,GAAG;KACnB,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,QAAQ;IAIN,MAAM,CAAC,GAAG;QAChB,OAAO,QAAQ,CAAC,UAAU,CAAC;IAC5B,CAAC;IAEM,OAAO;QACb,OAAO,QAAQ,CAAC,UAAU,CAAC;IAC5B,CAAC;;AATD,0CAA0C;AAC5B,mBAAU,GAAW,CAAC,CAAC;AAWtC,mHAAmH;AACnH,MAAM,UAAU,aAAa,CAAC,aAAqB;IAClD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;IAC7B,QAAQ,CAAC,UAAU,GAAG,aAAa,CAA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,KAAK,EAAE,CAAC;QAC1C,MAAM,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC7C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,4GAA4G;QAC5G,MAAM,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;QAC9C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,KAAK,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,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\n/* eslint-disable @typescript-eslint/dot-notation */\n\nimport { openDB } from \"idb\";\nimport { ICacheEntry } from \"@fluidframework/odsp-driver-definitions\";\nimport { MockLogger } from \"@fluidframework/telemetry-utils\";\nimport { delay } from \"@fluidframework/core-utils\";\nimport { FluidDriverCacheDBName } from \"../FluidCacheIndexedDb.js\";\nimport { FluidCache } from \"../FluidCache.js\";\n\n// eslint-disable-next-line import/no-unassigned-import, @typescript-eslint/no-require-imports, import/no-internal-modules\nrequire(\"fake-indexeddb/auto\");\n\nconst mockPartitionKey = \"FAKEPARTITIONKEY\";\n\nfunction getFluidCache(config?: {\n\tmaxCacheItemAge?: number;\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpartitionKey?: string | null;\n\tlogger?: MockLogger;\n}) {\n\treturn new FluidCache({\n\t\tpartitionKey: config?.partitionKey ?? mockPartitionKey,\n\t\tmaxCacheItemAge: config?.maxCacheItemAge ?? 3 * 24 * 60 * 60 * 1000,\n\t\tlogger: config?.logger,\n\t\tcloseDbAfterMs: 100,\n\t});\n}\n\nclass DateMock {\n\t// The current time being used by the mock\n\tpublic static mockTimeMs: number = 0;\n\n\tpublic static now() {\n\t\treturn DateMock.mockTimeMs;\n\t}\n\n\tpublic getTime() {\n\t\treturn DateMock.mockTimeMs;\n\t}\n}\n\n// Sets up a mock date time for the current test. Returns a function that should be called to reset the environment\nexport function setupDateMock(startMockTime: number) {\n\tconst realDate = window.Date;\n\tDateMock.mockTimeMs = startMockTime;\n\t(window.Date as any) = DateMock;\n\n\treturn () => (window.Date = realDate);\n}\n\n// Gets a mock cache entry from an item key, all entries returned will be for the same document.\nfunction getMockCacheEntry(itemKey: string, options?: { docId: string }): ICacheEntry {\n\treturn {\n\t\tfile: {\n\t\t\tdocId: options?.docId ?? \"myDocument\",\n\t\t\tresolvedUrl: {\n\t\t\t\ttype: \"fluid\",\n\t\t\t\turl: \"https://bing.com/myDocument\",\n\t\t\t\tid: \"mockContainer\",\n\t\t\t\ttokens: {},\n\t\t\t\tendpoints: {},\n\t\t\t},\n\t\t},\n\t\ttype: \"snapshot\",\n\t\tkey: itemKey,\n\t};\n}\n\ndescribe(\"FluidCacheTimer tests\", () => {\n\tbeforeEach(() => {\n\t\t// Reset the indexed db before each test so that it starts off in an empty state\n\t\t// eslint-disable-next-line import/no-internal-modules, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires\n\t\tconst FDBFactory = require(\"fake-indexeddb/lib/FDBFactory\");\n\t\t(window.indexedDB as any) = new FDBFactory();\n\t});\n\n\tit(\"db should be closed after the close timer\", async () => {\n\t\tconst logger = new MockLogger();\n\t\tconst fluidCache = getFluidCache({ logger });\n\n\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\t\texpect(fluidCache[\"db\"] !== undefined).toEqual(true);\n\t\t// Wait for timer to pass.\n\t\tawait delay(101);\n\t\texpect(fluidCache[\"db\"] === undefined).toEqual(true);\n\t\texpect(fluidCache[\"dbCloseTimer\"] === undefined).toEqual(true);\n\t});\n\n\tit(\"db should be closed after the version upgrade\", async () => {\n\t\tconst logger = new MockLogger();\n\t\tconst fluidCache = getFluidCache({ logger });\n\n\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\t\texpect(fluidCache[\"db\"] !== undefined).toEqual(true);\n\t\t// Create a DB with a much newer version number to force version upgrade on older cache causing it to close.\n\t\tawait openDB(FluidDriverCacheDBName, 1000000);\n\t\texpect(fluidCache[\"db\"] === undefined).toEqual(true);\n\t\texpect(fluidCache[\"dbCloseTimer\"] === undefined).toEqual(true);\n\t});\n\n\tit(\"db should be closed after the version upgrade\", async () => {\n\t\tconst logger = new MockLogger();\n\t\tconst fluidCache = getFluidCache({ logger });\n\n\t\tconst cacheEntry = getMockCacheEntry(\"someKey\");\n\t\tconst cachedItem = { dateToStore: \"foo\" };\n\t\tawait fluidCache.put(cacheEntry, cachedItem);\n\t\texpect(fluidCache[\"db\"] !== undefined).toEqual(true);\n\t\t// Create a DB with a much newer version number to force version upgrade on older cache causing it to close.\n\t\tawait openDB(FluidDriverCacheDBName, 1000000);\n\t\texpect(fluidCache[\"db\"] === undefined).toEqual(true);\n\t\texpect(fluidCache[\"dbCloseTimer\"] === undefined).toEqual(true);\n\t});\n});\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
use_current_ClassDeclaration_FluidCache(get_old_ClassDeclaration_FluidCache());
|
|
2
|
-
use_old_ClassDeclaration_FluidCache(get_current_ClassDeclaration_FluidCache());
|
|
3
|
-
use_current_InterfaceDeclaration_FluidCacheConfig(get_old_InterfaceDeclaration_FluidCacheConfig());
|
|
4
|
-
use_old_InterfaceDeclaration_FluidCacheConfig(get_current_InterfaceDeclaration_FluidCacheConfig());
|
|
5
|
-
use_current_FunctionDeclaration_deleteFluidCacheIndexDbInstance(get_old_FunctionDeclaration_deleteFluidCacheIndexDbInstance());
|
|
6
|
-
use_old_FunctionDeclaration_deleteFluidCacheIndexDbInstance(get_current_FunctionDeclaration_deleteFluidCacheIndexDbInstance());
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=validateDriverWebCachePrevious.generated.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateDriverWebCachePrevious.generated.js","sourceRoot":"","sources":["../../../src/test/types/validateDriverWebCachePrevious.generated.ts"],"names":[],"mappings":"AAgCA,uCAAuC,CACnC,mCAAmC,EAAE,CAAC,CAAC;AAW3C,mCAAmC,CAC/B,uCAAuC,EAAE,CAAC,CAAC;AAW/C,iDAAiD,CAC7C,6CAA6C,EAAE,CAAC,CAAC;AAWrD,6CAA6C,CACzC,iDAAiD,EAAE,CAAC,CAAC;AAWzD,+DAA+D,CAC3D,2DAA2D,EAAE,CAAC,CAAC;AAWnE,2DAA2D,CACvD,+DAA+D,EAAE,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n/*\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n * Generated by fluid-type-test-generator in @fluidframework/build-tools.\n */\nimport type * as old from \"@fluidframework/driver-web-cache-previous\";\nimport type * as current from \"../../index.js\";\n\n\n// See 'build-tools/src/type-test-generator/compatibility.ts' for more information.\ntype TypeOnly<T> = T extends number\n\t? number\n\t: T extends string\n\t? string\n\t: T extends boolean | bigint | symbol\n\t? T\n\t: {\n\t\t\t[P in keyof T]: TypeOnly<T[P]>;\n\t };\n\n/*\n* Validate forward compat by using old type in place of current type\n* If breaking change required, add in package.json under typeValidation.broken:\n* \"ClassDeclaration_FluidCache\": {\"forwardCompat\": false}\n*/\ndeclare function get_old_ClassDeclaration_FluidCache():\n TypeOnly<old.FluidCache>;\ndeclare function use_current_ClassDeclaration_FluidCache(\n use: TypeOnly<current.FluidCache>): void;\nuse_current_ClassDeclaration_FluidCache(\n get_old_ClassDeclaration_FluidCache());\n\n/*\n* Validate back compat by using current type in place of old type\n* If breaking change required, add in package.json under typeValidation.broken:\n* \"ClassDeclaration_FluidCache\": {\"backCompat\": false}\n*/\ndeclare function get_current_ClassDeclaration_FluidCache():\n TypeOnly<current.FluidCache>;\ndeclare function use_old_ClassDeclaration_FluidCache(\n use: TypeOnly<old.FluidCache>): void;\nuse_old_ClassDeclaration_FluidCache(\n get_current_ClassDeclaration_FluidCache());\n\n/*\n* Validate forward compat by using old type in place of current type\n* If breaking change required, add in package.json under typeValidation.broken:\n* \"InterfaceDeclaration_FluidCacheConfig\": {\"forwardCompat\": false}\n*/\ndeclare function get_old_InterfaceDeclaration_FluidCacheConfig():\n TypeOnly<old.FluidCacheConfig>;\ndeclare function use_current_InterfaceDeclaration_FluidCacheConfig(\n use: TypeOnly<current.FluidCacheConfig>): void;\nuse_current_InterfaceDeclaration_FluidCacheConfig(\n get_old_InterfaceDeclaration_FluidCacheConfig());\n\n/*\n* Validate back compat by using current type in place of old type\n* If breaking change required, add in package.json under typeValidation.broken:\n* \"InterfaceDeclaration_FluidCacheConfig\": {\"backCompat\": false}\n*/\ndeclare function get_current_InterfaceDeclaration_FluidCacheConfig():\n TypeOnly<current.FluidCacheConfig>;\ndeclare function use_old_InterfaceDeclaration_FluidCacheConfig(\n use: TypeOnly<old.FluidCacheConfig>): void;\nuse_old_InterfaceDeclaration_FluidCacheConfig(\n get_current_InterfaceDeclaration_FluidCacheConfig());\n\n/*\n* Validate forward compat by using old type in place of current type\n* If breaking change required, add in package.json under typeValidation.broken:\n* \"FunctionDeclaration_deleteFluidCacheIndexDbInstance\": {\"forwardCompat\": false}\n*/\ndeclare function get_old_FunctionDeclaration_deleteFluidCacheIndexDbInstance():\n TypeOnly<typeof old.deleteFluidCacheIndexDbInstance>;\ndeclare function use_current_FunctionDeclaration_deleteFluidCacheIndexDbInstance(\n use: TypeOnly<typeof current.deleteFluidCacheIndexDbInstance>): void;\nuse_current_FunctionDeclaration_deleteFluidCacheIndexDbInstance(\n get_old_FunctionDeclaration_deleteFluidCacheIndexDbInstance());\n\n/*\n* Validate back compat by using current type in place of old type\n* If breaking change required, add in package.json under typeValidation.broken:\n* \"FunctionDeclaration_deleteFluidCacheIndexDbInstance\": {\"backCompat\": false}\n*/\ndeclare function get_current_FunctionDeclaration_deleteFluidCacheIndexDbInstance():\n TypeOnly<typeof current.deleteFluidCacheIndexDbInstance>;\ndeclare function use_old_FunctionDeclaration_deleteFluidCacheIndexDbInstance(\n use: TypeOnly<typeof old.deleteFluidCacheIndexDbInstance>): void;\nuse_old_FunctionDeclaration_deleteFluidCacheIndexDbInstance(\n get_current_FunctionDeclaration_deleteFluidCacheIndexDbInstance());\n"]}
|
|
File without changes
|