Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: test case for parallel load & destroy instance

DarkSky2913da11a092
diff --git a/packages/data-center/tests/datacenter.spec.ts b/packages/data-center/tests/datacenter.spec.ts
index 80c88402a6..a5785c3b37 100644
--- a/packages/data-center/tests/datacenter.spec.ts
+++ b/packages/data-center/tests/datacenter.spec.ts
@@ -13,12 +13,23 @@ test('init data center', async () => {
expect(workspace).toBeTruthy();
});
+test('init data center singleton', async () => {
+ const [dc1, dc2] = await Promise.all([getDataCenter(), getDataCenter()]);
+ expect(dc1).toEqual(dc2);
+
+ const [ws1, ws2] = await Promise.all([
+ dc1.getWorkspace('test1'),
+ dc2.getWorkspace('test1'),
+ ]);
+ expect(ws1).toEqual(ws2);
+});
+
test('should init error with unknown provider', async () => {
const dataCenter = await getDataCenter();
await dataCenter.clearWorkspaces();
test.fail();
- await dataCenter.getWorkspace('test2', 'not exist provider');
+ await dataCenter.getWorkspace('test2', { providerId: 'not exist provider' });
});
test.skip('init affine provider', async () => {
@@ -26,10 +37,10 @@ test.skip('init affine provider', async () => {
await dataCenter.clearWorkspaces();
// TODO: set constant token for testing
- await dataCenter.setWorkspaceConfig('6', 'token', 'YOUR_TOKEN');
-
- const workspace = await dataCenter.getWorkspace('6', 'affine');
-
+ const workspace = await dataCenter.getWorkspace('6', {
+ providerId: 'affine',
+ config: { token: 'YOUR_TOKEN' },
+ });
expect(workspace).toBeTruthy();
});
@@ -52,16 +63,27 @@ test('list workspaces', async () => {
]);
});
+test('destroy workspaces', async () => {
+ const dataCenter = await getDataCenter();
+ await dataCenter.clearWorkspaces();
+
+ const dc1 = await dataCenter.getWorkspace('test7');
+ await dataCenter.destroyWorkspace('test7');
+ const dc2 = await dataCenter.getWorkspace('test7');
+
+ expect(dc1 !== dc2).toBeTruthy();
+});
+
test('remove workspaces', async () => {
const dataCenter = await getDataCenter();
await dataCenter.clearWorkspaces();
await Promise.all([
- dataCenter.getWorkspace('test7'),
dataCenter.getWorkspace('test8'),
+ dataCenter.getWorkspace('test9'),
]);
- await dataCenter.removeWorkspace('test7');
+ await dataCenter.removeWorkspace('test8');
- expect(await dataCenter.listWorkspace()).toStrictEqual(['test8']);
+ expect(await dataCenter.listWorkspace()).toStrictEqual(['test9']);
});