@dxos/echo-pipeline 0.6.11 → 0.6.12-main.5a87ad5
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/dist/lib/browser/chunk-YTSGJIY7.mjs +2036 -0
- package/dist/lib/browser/chunk-YTSGJIY7.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3401 -17
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -4
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-7HHYCGUR.cjs → chunk-6SSC2M4R.cjs} +65 -37
- package/dist/lib/node/chunk-6SSC2M4R.cjs.map +7 -0
- package/dist/lib/node/index.cjs +3378 -35
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +11 -12
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/{browser/chunk-UKXIJW43.mjs → node-esm/chunk-ASOERPR6.mjs} +52 -26
- package/dist/lib/node-esm/chunk-ASOERPR6.mjs.map +7 -0
- package/dist/lib/{browser/chunk-MPWFDDQK.mjs → node-esm/index.mjs} +1623 -318
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +551 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/automerge/automerge-host.d.ts +24 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts +2 -0
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/space-collection.d.ts +3 -2
- package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
- package/dist/types/src/db-host/automerge-metrics.d.ts +11 -0
- package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -0
- package/dist/types/src/db-host/data-service.d.ts +3 -2
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +20 -0
- package/dist/types/src/db-host/database-root.d.ts.map +1 -0
- package/dist/types/src/db-host/documents-iterator.d.ts +7 -0
- package/dist/types/src/db-host/documents-iterator.d.ts.map +1 -0
- package/dist/types/src/db-host/echo-host.d.ts +73 -0
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -0
- package/dist/types/src/db-host/index.d.ts +5 -0
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/db-host/migration.d.ts +8 -0
- package/dist/types/src/db-host/migration.d.ts.map +1 -0
- package/dist/types/src/db-host/query-service.d.ts +25 -0
- package/dist/types/src/db-host/query-service.d.ts.map +1 -0
- package/dist/types/src/db-host/query-state.d.ts +41 -0
- package/dist/types/src/db-host/query-state.d.ts.map +1 -0
- package/dist/types/src/db-host/space-state-manager.d.ts +23 -0
- package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-replicator.d.ts +23 -0
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -0
- package/dist/types/src/edge/index.d.ts +2 -0
- package/dist/types/src/edge/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/package.json +40 -50
- package/src/automerge/automerge-host.test.ts +8 -9
- package/src/automerge/automerge-host.ts +42 -6
- package/src/automerge/automerge-repo.test.ts +18 -16
- package/src/automerge/collection-synchronizer.test.ts +10 -5
- package/src/automerge/collection-synchronizer.ts +17 -6
- package/src/automerge/echo-data-monitor.test.ts +1 -3
- package/src/automerge/echo-network-adapter.test.ts +4 -3
- package/src/automerge/mesh-echo-replicator.ts +2 -1
- package/src/automerge/space-collection.ts +3 -2
- package/src/automerge/storage-adapter.test.ts +2 -3
- package/src/db-host/automerge-metrics.ts +38 -0
- package/src/db-host/data-service.ts +29 -14
- package/src/db-host/database-root.ts +86 -0
- package/src/db-host/documents-iterator.ts +73 -0
- package/src/db-host/documents-synchronizer.test.ts +2 -2
- package/src/db-host/echo-host.ts +257 -0
- package/src/db-host/index.ts +6 -1
- package/src/db-host/migration.ts +57 -0
- package/src/db-host/query-service.ts +208 -0
- package/src/db-host/query-state.ts +200 -0
- package/src/db-host/space-state-manager.ts +90 -0
- package/src/edge/echo-edge-replicator.ts +286 -0
- package/src/edge/index.ts +5 -0
- package/src/index.ts +1 -0
- package/src/pipeline/pipeline-stress.test.ts +44 -47
- package/src/pipeline/pipeline.test.ts +3 -4
- package/src/space/control-pipeline.test.ts +2 -3
- package/src/space/control-pipeline.ts +10 -1
- package/src/space/replication.browser.test.ts +2 -8
- package/src/space/space-manager.browser.test.ts +6 -5
- package/src/space/space-protocol.browser.test.ts +29 -34
- package/src/space/space-protocol.test.ts +29 -27
- package/src/space/space.test.ts +28 -11
- package/src/testing/test-agent-builder.ts +2 -2
- package/dist/lib/browser/chunk-MPWFDDQK.mjs.map +0 -7
- package/dist/lib/browser/chunk-UKXIJW43.mjs.map +0 -7
- package/dist/lib/browser/chunk-XPCF2V5U.mjs +0 -31
- package/dist/lib/browser/chunk-XPCF2V5U.mjs.map +0 -7
- package/dist/lib/browser/light.mjs +0 -32
- package/dist/lib/browser/light.mjs.map +0 -7
- package/dist/lib/node/chunk-5DH4KR2S.cjs +0 -2148
- package/dist/lib/node/chunk-5DH4KR2S.cjs.map +0 -7
- package/dist/lib/node/chunk-7HHYCGUR.cjs.map +0 -7
- package/dist/lib/node/chunk-DZVH7HDD.cjs +0 -43
- package/dist/lib/node/chunk-DZVH7HDD.cjs.map +0 -7
- package/dist/lib/node/light.cjs +0 -52
- package/dist/lib/node/light.cjs.map +0 -7
- package/dist/types/src/light.d.ts +0 -4
- package/dist/types/src/light.d.ts.map +0 -1
- package/src/light.ts +0 -7
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from 'expect';
|
|
6
5
|
import * as fc from 'fast-check';
|
|
7
|
-
import { inspect } from 'util';
|
|
6
|
+
import { inspect } from 'node:util';
|
|
7
|
+
import { describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { asyncTimeout } from '@dxos/async';
|
|
10
10
|
import { type FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
@@ -12,7 +12,6 @@ import { PublicKey } from '@dxos/keys';
|
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { type FeedMessageBlock } from '@dxos/protocols';
|
|
14
14
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
15
|
-
import { describe, test } from '@dxos/test';
|
|
16
15
|
import { Timeframe } from '@dxos/timeframe';
|
|
17
16
|
import { range } from '@dxos/util';
|
|
18
17
|
|
|
@@ -24,53 +23,51 @@ const NUM_MESSAGES = 10;
|
|
|
24
23
|
|
|
25
24
|
// TODO(burdon): Describe test.
|
|
26
25
|
describe('pipeline/stress test', () => {
|
|
27
|
-
test
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
[
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
await fc.asyncModelRun(setup, [...commands, new SyncCommand()]);
|
|
60
|
-
} finally {
|
|
61
|
-
await Promise.all(Array.from(agents.values()).map((agent) => agent.stop()));
|
|
62
|
-
await Promise.all(Array.from(agents.values()).map((agent) => agent.close()));
|
|
63
|
-
}
|
|
26
|
+
test.skip('stress', { timeout: 60_000 }, async () => {
|
|
27
|
+
const builder = new TestFeedBuilder();
|
|
28
|
+
|
|
29
|
+
const agentIds = range(NUM_AGENTS).map(() => PublicKey.random().toHex().slice(0, 8));
|
|
30
|
+
const anAgentId = fc.constantFrom(...agentIds);
|
|
31
|
+
|
|
32
|
+
const commands = fc.commands(
|
|
33
|
+
[
|
|
34
|
+
fc.tuple(anAgentId, fc.integer({ min: 1, max: 10 })).map(([agent, count]) => new WriteCommand(agent, count)),
|
|
35
|
+
fc.constant(new SyncCommand()),
|
|
36
|
+
anAgentId.map((agent) => new RestartCommand(agent)),
|
|
37
|
+
],
|
|
38
|
+
{ size: 'large' },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const model = fc.asyncProperty(commands, async (commands) => {
|
|
42
|
+
const feedStore = builder.createFeedStore();
|
|
43
|
+
|
|
44
|
+
const agents = new Map(agentIds.map((id) => [id, new Agent(builder, feedStore, id)]));
|
|
45
|
+
await Promise.all(Array.from(agents.values()).map((agent) => agent.open()));
|
|
46
|
+
await Promise.all(Array.from(agents.values()).map((agent) => agent.start()));
|
|
47
|
+
|
|
48
|
+
const setup: fc.ModelRunSetup<Model, Real> = () => ({
|
|
49
|
+
model: {},
|
|
50
|
+
real: {
|
|
51
|
+
feedStore,
|
|
52
|
+
agents,
|
|
53
|
+
},
|
|
64
54
|
});
|
|
65
55
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
try {
|
|
57
|
+
await fc.asyncModelRun(setup, [...commands, new SyncCommand()]);
|
|
58
|
+
} finally {
|
|
59
|
+
await Promise.all(Array.from(agents.values()).map((agent) => agent.stop()));
|
|
60
|
+
await Promise.all(Array.from(agents.values()).map((agent) => agent.close()));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const examples: [commands: Iterable<fc.AsyncCommand<Model, Real, boolean>>][] = [
|
|
65
|
+
[[new WriteCommand(agentIds[0], 10), new WriteCommand(agentIds[1], 10), new SyncCommand()]],
|
|
66
|
+
[[new WriteCommand(agentIds[0], 4), new RestartCommand(agentIds[0]), new SyncCommand()]],
|
|
67
|
+
];
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.timeout(60_000);
|
|
69
|
+
await fc.assert(model, { examples });
|
|
70
|
+
});
|
|
74
71
|
});
|
|
75
72
|
|
|
76
73
|
class Agent {
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
5
|
+
import { describe, expect, test, onTestFinished } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Event, sleep } from '@dxos/async';
|
|
8
8
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
9
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
10
9
|
import { Timeframe } from '@dxos/timeframe';
|
|
11
10
|
import { range } from '@dxos/util';
|
|
12
11
|
|
|
@@ -62,7 +61,7 @@ describe('pipeline/Pipeline', () => {
|
|
|
62
61
|
|
|
63
62
|
test('reading and writing with cursor changes', async () => {
|
|
64
63
|
const pipeline = new Pipeline();
|
|
65
|
-
|
|
64
|
+
onTestFinished(() => pipeline.stop());
|
|
66
65
|
|
|
67
66
|
const builder = new TestFeedBuilder();
|
|
68
67
|
const feedStore = builder.createFeedStore();
|
|
@@ -105,7 +104,7 @@ describe('pipeline/Pipeline', () => {
|
|
|
105
104
|
|
|
106
105
|
test('cursor change while polling', async () => {
|
|
107
106
|
const pipeline = new Pipeline();
|
|
108
|
-
|
|
107
|
+
onTestFinished(() => pipeline.stop());
|
|
109
108
|
|
|
110
109
|
const builder = new TestFeedBuilder();
|
|
111
110
|
const feedStore = builder.createFeedStore();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
5
|
+
import { describe, expect, test, onTestFinished } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { CredentialGenerator, createCredential } from '@dxos/credentials';
|
|
8
8
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
@@ -12,7 +12,6 @@ import { log } from '@dxos/log';
|
|
|
12
12
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
13
13
|
import { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
14
14
|
import { createStorage, StorageType } from '@dxos/random-access-storage';
|
|
15
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
16
15
|
import { Timeframe } from '@dxos/timeframe';
|
|
17
16
|
|
|
18
17
|
import { ControlPipeline } from './control-pipeline';
|
|
@@ -62,7 +61,7 @@ describe('space/control-pipeline', () => {
|
|
|
62
61
|
await controlPipeline.setWriteFeed(genesisFeed);
|
|
63
62
|
await controlPipeline.start();
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
onTestFinished(() => controlPipeline.stop());
|
|
66
65
|
|
|
67
66
|
//
|
|
68
67
|
// Genesis
|
|
@@ -160,7 +160,7 @@ export class ControlPipeline {
|
|
|
160
160
|
};
|
|
161
161
|
await this._pipeline.unpause();
|
|
162
162
|
|
|
163
|
-
log('save snapshot', { key: this._spaceKey, snapshot });
|
|
163
|
+
log('save snapshot', { key: this._spaceKey, snapshot: getSnapshotLoggerContext(snapshot) });
|
|
164
164
|
await this._metadata.setSpaceControlPipelineSnapshot(this._spaceKey, snapshot);
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -229,3 +229,12 @@ export class ControlPipeline {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
+
|
|
233
|
+
const getSnapshotLoggerContext = (snapshot: ControlPipelineSnapshot) => {
|
|
234
|
+
return snapshot.messages?.map((msg) => {
|
|
235
|
+
const issuer = msg.credential.issuer;
|
|
236
|
+
const subject = msg.credential.subject.id;
|
|
237
|
+
const type = msg.credential.subject.assertion['@type'];
|
|
238
|
+
return { issuer, subject, type };
|
|
239
|
+
});
|
|
240
|
+
};
|
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import expect from 'expect';
|
|
8
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
9
6
|
|
|
10
7
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
11
8
|
import { Keyring } from '@dxos/keyring';
|
|
12
9
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
13
10
|
import { createStorage } from '@dxos/random-access-storage';
|
|
14
|
-
import { describe, test } from '@dxos/test';
|
|
15
11
|
import { Timeframe } from '@dxos/timeframe';
|
|
16
12
|
|
|
17
13
|
import { valueEncoding } from '../common';
|
|
@@ -57,8 +53,6 @@ describe('replication', () => {
|
|
|
57
53
|
timeframe: new Timeframe([[feed1.key, 123]]),
|
|
58
54
|
});
|
|
59
55
|
|
|
60
|
-
await
|
|
61
|
-
expect(feed2.properties.length).toEqual(1);
|
|
62
|
-
});
|
|
56
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
63
57
|
});
|
|
64
58
|
});
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { describe, test, onTestFinished } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { createStorage } from '@dxos/random-access-storage';
|
|
8
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
9
8
|
|
|
10
9
|
import { TestAgentBuilder, WebsocketNetworkManagerProvider } from '../testing';
|
|
11
10
|
|
|
@@ -20,7 +19,9 @@ describe('space-manager', () => {
|
|
|
20
19
|
storage: createStorage(),
|
|
21
20
|
networkManagerProvider: WebsocketNetworkManagerProvider(SIGNAL_URL),
|
|
22
21
|
});
|
|
23
|
-
|
|
22
|
+
onTestFinished(async () => {
|
|
23
|
+
await builder.close();
|
|
24
|
+
});
|
|
24
25
|
|
|
25
26
|
const peer1 = await builder.createPeer();
|
|
26
27
|
const spaceManager1 = peer1.spaceManager;
|
|
@@ -30,8 +31,8 @@ describe('space-manager', () => {
|
|
|
30
31
|
const spaceManager2 = peer2.spaceManager;
|
|
31
32
|
await spaceManager2.open();
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
onTestFinished(() => spaceManager1.close());
|
|
35
|
+
onTestFinished(() => spaceManager2.close());
|
|
35
36
|
|
|
36
37
|
// const space1 = await spaceManager1.createSpace();
|
|
37
38
|
// expect(space1.isOpen).to.be.true;
|
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import expect from 'expect';
|
|
8
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { describe, expect, test, onTestFinished } from 'vitest';
|
|
9
6
|
|
|
10
7
|
import { Keyring } from '@dxos/keyring';
|
|
11
8
|
import { PublicKey } from '@dxos/keys';
|
|
12
9
|
import { createStorage } from '@dxos/random-access-storage';
|
|
13
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
14
10
|
import { Timeframe } from '@dxos/timeframe';
|
|
15
11
|
|
|
16
12
|
import { TestFeedBuilder, TestAgentBuilder, WebsocketNetworkManagerProvider } from '../testing';
|
|
@@ -23,7 +19,9 @@ const SIGNAL_URL = `ws://localhost:${port}/.well-known/dx/signal`;
|
|
|
23
19
|
describe('space/space-protocol', () => {
|
|
24
20
|
test('two peers discover each other', async () => {
|
|
25
21
|
const builder = new TestAgentBuilder();
|
|
26
|
-
|
|
22
|
+
onTestFinished(async () => {
|
|
23
|
+
await builder.close();
|
|
24
|
+
});
|
|
27
25
|
const topic = PublicKey.random();
|
|
28
26
|
|
|
29
27
|
const peer1 = await builder.createPeer();
|
|
@@ -39,18 +37,22 @@ describe('space/space-protocol', () => {
|
|
|
39
37
|
await protocol1.start();
|
|
40
38
|
await protocol2.start();
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
onTestFinished(() => protocol1.stop());
|
|
41
|
+
onTestFinished(() => protocol2.stop());
|
|
44
42
|
|
|
45
|
-
await
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
await expect
|
|
44
|
+
.poll(() => presence1.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer2.identityKey)))
|
|
45
|
+
.toBeTruthy();
|
|
46
|
+
await expect
|
|
47
|
+
.poll(() => presence2.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer1.identityKey)))
|
|
48
|
+
.toBeTruthy();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('replicates a feed', async () => {
|
|
52
52
|
const builder = new TestAgentBuilder();
|
|
53
|
-
|
|
53
|
+
onTestFinished(async () => {
|
|
54
|
+
await builder.close();
|
|
55
|
+
});
|
|
54
56
|
const topic = PublicKey.random();
|
|
55
57
|
|
|
56
58
|
const peer1 = await builder.createPeer();
|
|
@@ -62,8 +64,8 @@ describe('space/space-protocol', () => {
|
|
|
62
64
|
await protocol1.start();
|
|
63
65
|
await protocol2.start();
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
onTestFinished(() => protocol1.stop());
|
|
68
|
+
onTestFinished(() => protocol2.stop());
|
|
67
69
|
|
|
68
70
|
const builder1 = new TestFeedBuilder();
|
|
69
71
|
const feedStore1 = builder1.createFeedStore();
|
|
@@ -79,24 +81,23 @@ describe('space/space-protocol', () => {
|
|
|
79
81
|
await protocol2.addFeed(feed2);
|
|
80
82
|
|
|
81
83
|
await feed1.append({ timeframe: new Timeframe() });
|
|
82
|
-
await
|
|
83
|
-
expect(feed2.properties.length).toEqual(1);
|
|
84
|
-
});
|
|
84
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
85
85
|
|
|
86
86
|
await feed1.append({ timeframe: new Timeframe() });
|
|
87
|
-
await
|
|
88
|
-
expect(feed2.properties.length).toEqual(2);
|
|
89
|
-
});
|
|
87
|
+
await expect.poll(() => feed2.properties.length).toEqual(2);
|
|
90
88
|
|
|
91
89
|
await builder.close();
|
|
92
90
|
});
|
|
93
91
|
|
|
94
|
-
|
|
92
|
+
// TODO: Some storage drivers may break when there are multiple storage instances.
|
|
93
|
+
test.skip('replicates a feed through a webrtc connection', async () => {
|
|
95
94
|
const builder = new TestAgentBuilder({
|
|
96
95
|
storage: createStorage(),
|
|
97
96
|
networkManagerProvider: WebsocketNetworkManagerProvider(SIGNAL_URL),
|
|
98
97
|
});
|
|
99
|
-
|
|
98
|
+
onTestFinished(async () => {
|
|
99
|
+
await builder.close();
|
|
100
|
+
});
|
|
100
101
|
|
|
101
102
|
const keyring = new Keyring();
|
|
102
103
|
const topic = await keyring.createKey();
|
|
@@ -110,8 +111,8 @@ describe('space/space-protocol', () => {
|
|
|
110
111
|
await protocol1.start();
|
|
111
112
|
await protocol2.start();
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
onTestFinished(() => protocol1.stop());
|
|
115
|
+
onTestFinished(() => protocol2.stop());
|
|
115
116
|
|
|
116
117
|
const feedKey = await peer1.keyring.createKey();
|
|
117
118
|
|
|
@@ -122,17 +123,11 @@ describe('space/space-protocol', () => {
|
|
|
122
123
|
await protocol2.addFeed(feed2);
|
|
123
124
|
|
|
124
125
|
await feed1.append({ timeframe: new Timeframe() });
|
|
125
|
-
await
|
|
126
|
-
expect(feed2.properties.length).toEqual(1);
|
|
127
|
-
});
|
|
126
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
128
127
|
|
|
129
128
|
await feed1.append({ timeframe: new Timeframe() });
|
|
130
|
-
await
|
|
131
|
-
expect(feed2.properties.length).toEqual(2);
|
|
132
|
-
});
|
|
129
|
+
await expect.poll(() => feed2.properties.length).toEqual(2);
|
|
133
130
|
|
|
134
131
|
await builder.close();
|
|
135
|
-
})
|
|
136
|
-
.skipEnvironments('webkit')
|
|
137
|
-
.tag('flaky'); // Some storage drivers may break when there are multiple storage instances.
|
|
132
|
+
});
|
|
138
133
|
});
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
6
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { describe, expect, test, onTestFinished } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { PublicKey } from '@dxos/keys';
|
|
9
8
|
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
10
9
|
import { MemoryTransportFactory, SwarmNetworkManager } from '@dxos/network-manager';
|
|
11
10
|
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
12
11
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
13
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
14
12
|
import { Timeframe } from '@dxos/timeframe';
|
|
15
13
|
|
|
16
14
|
import { AuthStatus, MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceProtocol } from './space-protocol';
|
|
@@ -19,7 +17,9 @@ import { TestAgentBuilder, TestFeedBuilder } from '../testing';
|
|
|
19
17
|
describe('space/space-protocol', () => {
|
|
20
18
|
test('two peers discover each other via presence', async () => {
|
|
21
19
|
const builder = new TestAgentBuilder();
|
|
22
|
-
|
|
20
|
+
onTestFinished(async () => {
|
|
21
|
+
await builder.close();
|
|
22
|
+
});
|
|
23
23
|
const topic = PublicKey.random();
|
|
24
24
|
|
|
25
25
|
const peer1 = await builder.createPeer();
|
|
@@ -35,15 +35,21 @@ describe('space/space-protocol', () => {
|
|
|
35
35
|
const protocol2 = peer2.createSpaceProtocol(topic, gossip2);
|
|
36
36
|
|
|
37
37
|
await protocol1.start();
|
|
38
|
-
|
|
38
|
+
onTestFinished(() => protocol1.stop());
|
|
39
39
|
|
|
40
40
|
await protocol2.start();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
onTestFinished(() => protocol2.stop());
|
|
42
|
+
|
|
43
|
+
await expect
|
|
44
|
+
.poll(() => presence1.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer2.identityKey)), {
|
|
45
|
+
timeout: 1_000,
|
|
46
|
+
})
|
|
47
|
+
.toBeTruthy();
|
|
48
|
+
await expect
|
|
49
|
+
.poll(() => presence2.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer1.identityKey)), {
|
|
50
|
+
timeout: 1_000,
|
|
51
|
+
})
|
|
52
|
+
.toBeTruthy();
|
|
47
53
|
});
|
|
48
54
|
|
|
49
55
|
test('failing authentication', async () => {
|
|
@@ -81,19 +87,19 @@ describe('space/space-protocol', () => {
|
|
|
81
87
|
});
|
|
82
88
|
|
|
83
89
|
await protocol1.start();
|
|
84
|
-
|
|
90
|
+
onTestFinished(() => protocol1.stop());
|
|
85
91
|
|
|
86
92
|
await protocol2.start();
|
|
87
|
-
|
|
93
|
+
onTestFinished(() => protocol2.stop());
|
|
88
94
|
|
|
89
|
-
await
|
|
90
|
-
expect(protocol1.sessions.get(peerId2)?.authStatus).toEqual(AuthStatus.FAILURE);
|
|
91
|
-
});
|
|
95
|
+
await expect.poll(() => protocol1.sessions.get(peerId2)?.authStatus).toEqual(AuthStatus.FAILURE);
|
|
92
96
|
});
|
|
93
97
|
|
|
94
98
|
test('replicates a feed', async () => {
|
|
95
99
|
const builder = new TestAgentBuilder();
|
|
96
|
-
|
|
100
|
+
onTestFinished(async () => {
|
|
101
|
+
await builder.close();
|
|
102
|
+
});
|
|
97
103
|
|
|
98
104
|
const topic = PublicKey.random();
|
|
99
105
|
|
|
@@ -106,8 +112,8 @@ describe('space/space-protocol', () => {
|
|
|
106
112
|
await protocol1.start();
|
|
107
113
|
await protocol2.start();
|
|
108
114
|
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
onTestFinished(() => protocol1.stop());
|
|
116
|
+
onTestFinished(() => protocol2.stop());
|
|
111
117
|
|
|
112
118
|
//
|
|
113
119
|
// Create feeds.
|
|
@@ -131,16 +137,12 @@ describe('space/space-protocol', () => {
|
|
|
131
137
|
|
|
132
138
|
// TODO(burdon): Append batch of messages.
|
|
133
139
|
await feed1.append({ timeframe: new Timeframe() });
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
expect(feed2.properties.length).toEqual(1);
|
|
137
|
-
});
|
|
140
|
+
// Received message appended before replication.
|
|
141
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
138
142
|
|
|
139
143
|
// TODO(burdon): Append batch of messages.
|
|
140
144
|
await feed1.append({ timeframe: new Timeframe() });
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(feed2.properties.length).toEqual(2);
|
|
144
|
-
});
|
|
145
|
+
// Received message appended after replication.
|
|
146
|
+
await expect.poll(() => feed2.properties.length).toEqual(2);
|
|
145
147
|
});
|
|
146
148
|
});
|
package/src/space/space.test.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
5
|
+
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Context } from '@dxos/context';
|
|
8
8
|
import { CredentialGenerator } from '@dxos/credentials';
|
|
9
|
-
import { afterTest, describe, test } from '@dxos/test';
|
|
10
9
|
|
|
11
10
|
import { TestAgentBuilder } from '../testing';
|
|
12
11
|
|
|
@@ -16,13 +15,17 @@ const run = <T>(cb: () => Promise<T>): Promise<T> => cb();
|
|
|
16
15
|
describe('space/space', () => {
|
|
17
16
|
test('creates a database with object model', async () => {
|
|
18
17
|
const builder = new TestAgentBuilder();
|
|
19
|
-
|
|
18
|
+
onTestFinished(async () => {
|
|
19
|
+
await builder.close();
|
|
20
|
+
});
|
|
20
21
|
const agent = await builder.createPeer();
|
|
21
22
|
const space = await agent.createSpace();
|
|
22
23
|
|
|
23
24
|
await space.open(Context.default());
|
|
24
25
|
expect(space.isOpen).toBeTruthy();
|
|
25
|
-
|
|
26
|
+
onTestFinished(async () => {
|
|
27
|
+
await space.close();
|
|
28
|
+
});
|
|
26
29
|
|
|
27
30
|
await agent.spaceGenesis(space);
|
|
28
31
|
|
|
@@ -34,7 +37,9 @@ describe('space/space', () => {
|
|
|
34
37
|
|
|
35
38
|
test('two spaces replicating', async () => {
|
|
36
39
|
const builder = new TestAgentBuilder();
|
|
37
|
-
|
|
40
|
+
onTestFinished(async () => {
|
|
41
|
+
await builder.close();
|
|
42
|
+
});
|
|
38
43
|
|
|
39
44
|
//
|
|
40
45
|
// Agent 1
|
|
@@ -45,7 +50,9 @@ describe('space/space', () => {
|
|
|
45
50
|
|
|
46
51
|
await space.open(Context.default());
|
|
47
52
|
expect(space.isOpen).toBeTruthy();
|
|
48
|
-
|
|
53
|
+
onTestFinished(async () => {
|
|
54
|
+
await space.close();
|
|
55
|
+
});
|
|
49
56
|
|
|
50
57
|
await agent.spaceGenesis(space);
|
|
51
58
|
|
|
@@ -64,7 +71,9 @@ describe('space/space', () => {
|
|
|
64
71
|
|
|
65
72
|
await space.open(Context.default());
|
|
66
73
|
expect(space.isOpen).toBeTruthy();
|
|
67
|
-
|
|
74
|
+
onTestFinished(async () => {
|
|
75
|
+
await space.close();
|
|
76
|
+
});
|
|
68
77
|
|
|
69
78
|
return [agent, space];
|
|
70
79
|
});
|
|
@@ -110,13 +119,17 @@ describe('space/space', () => {
|
|
|
110
119
|
|
|
111
120
|
test('open & close', async () => {
|
|
112
121
|
const builder = new TestAgentBuilder();
|
|
113
|
-
|
|
122
|
+
onTestFinished(async () => {
|
|
123
|
+
await builder.close();
|
|
124
|
+
});
|
|
114
125
|
const agent = await builder.createPeer();
|
|
115
126
|
const space1 = await agent.createSpace();
|
|
116
127
|
|
|
117
128
|
await space1.open(Context.default());
|
|
118
129
|
expect(space1.isOpen).toBeTruthy();
|
|
119
|
-
|
|
130
|
+
onTestFinished(async () => {
|
|
131
|
+
await space1.close();
|
|
132
|
+
});
|
|
120
133
|
|
|
121
134
|
await agent.spaceGenesis(space1);
|
|
122
135
|
|
|
@@ -134,13 +147,17 @@ describe('space/space', () => {
|
|
|
134
147
|
|
|
135
148
|
test('re-open', async () => {
|
|
136
149
|
const builder = new TestAgentBuilder();
|
|
137
|
-
|
|
150
|
+
onTestFinished(async () => {
|
|
151
|
+
await builder.close();
|
|
152
|
+
});
|
|
138
153
|
const agent = await builder.createPeer();
|
|
139
154
|
const space = await agent.createSpace();
|
|
140
155
|
|
|
141
156
|
{
|
|
142
157
|
await space.open(Context.default());
|
|
143
|
-
|
|
158
|
+
onTestFinished(async () => {
|
|
159
|
+
await space.close();
|
|
160
|
+
});
|
|
144
161
|
expect(space.isOpen).toBeTruthy();
|
|
145
162
|
|
|
146
163
|
await agent.spaceGenesis(space);
|
|
@@ -8,7 +8,7 @@ import { type FeedStore } from '@dxos/feed-store';
|
|
|
8
8
|
import { type Keyring } from '@dxos/keyring';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';
|
|
11
|
-
import { MemoryTransportFactory, SwarmNetworkManager,
|
|
11
|
+
import { MemoryTransportFactory, SwarmNetworkManager, createRtcTransportFactory } from '@dxos/network-manager';
|
|
12
12
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
13
13
|
import { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
14
14
|
import { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
@@ -36,7 +36,7 @@ export const WebsocketNetworkManagerProvider =
|
|
|
36
36
|
() =>
|
|
37
37
|
new SwarmNetworkManager({
|
|
38
38
|
signalManager: new WebsocketSignalManager([{ server: signalUrl }]),
|
|
39
|
-
transportFactory:
|
|
39
|
+
transportFactory: createRtcTransportFactory(),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
export type TestAgentBuilderOptions = {
|