-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Enable sync with all peers for not local documents #292
base: main
Are you sure you want to change the base?
Changes from 5 commits
ea63ee0
7f06393
d3a8f4c
eae9890
9ed067e
dae554f
09e5c44
4196951
174ab6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1127,6 +1127,72 @@ describe("Repo", () => { | |
assert.equal(bobDoc.isReady(), true) | ||
}) | ||
|
||
it("share policy `false`", async () => { | ||
const alice = "alice" as PeerId | ||
const bob = "bob" as PeerId | ||
const [aliceAdapter, bobAdapter] = DummyNetworkAdapter.createConnectedPair() | ||
|
||
const aliceRepo = new Repo({ | ||
network: [aliceAdapter], | ||
peerId: alice, | ||
sharePolicy: async () => false, | ||
}) | ||
const bobRepo = new Repo({ | ||
network: [bobAdapter], | ||
peerId: bob, | ||
sharePolicy: async () => false, | ||
}) | ||
|
||
aliceAdapter.peerCandidate(bob) | ||
bobAdapter.peerCandidate(alice) | ||
|
||
const aliceDoc = aliceRepo.create() | ||
aliceDoc.change((doc: any) => (doc.text = "Hello world")) | ||
|
||
const bobDoc = bobRepo.find(aliceDoc.url) | ||
|
||
await bobDoc.whenReady() | ||
|
||
assert.equal(bobDoc.isReady(), true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there should be a test here for a 3rd peer, to show it can't find a document from across the network. eg. Alice creates a document. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
}) | ||
|
||
it("share policy `false` with `MessageChannelNetworkAdapter`", async () => { | ||
const alice = "alice" as PeerId | ||
const bob = "bob" as PeerId | ||
const { port1: ab, port2: ba } = new MessageChannel() | ||
|
||
const aliceNetworkAdapter = new MessageChannelNetworkAdapter(ab) | ||
const bobNetworkAdapter = new MessageChannelNetworkAdapter(ba) | ||
|
||
const aliceRepo = new Repo({ | ||
network: [aliceNetworkAdapter], | ||
peerId: alice, | ||
sharePolicy: async () => false, | ||
}) | ||
const bobRepo = new Repo({ | ||
network: [bobNetworkAdapter], | ||
peerId: bob, | ||
sharePolicy: async () => false, | ||
}) | ||
|
||
await Promise.all([ | ||
eventPromise(aliceRepo.networkSubsystem, "peer"), | ||
eventPromise(bobRepo.networkSubsystem, "peer"), | ||
]) | ||
|
||
const aliceDoc = aliceRepo.create() | ||
aliceDoc.change((doc: any) => (doc.text = "Hello world")) | ||
|
||
const bobDoc = bobRepo.find(aliceDoc.url) | ||
|
||
await bobDoc.whenReady() | ||
|
||
assert.equal(bobDoc.isReady(), true) | ||
|
||
ab.close() | ||
ba.close() | ||
}) | ||
|
||
describe("with peers (mesh network)", () => { | ||
const setup = async () => { | ||
// Set up three repos; connect Alice to Bob, Bob to Charlie, and Alice to Charlie | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is another side effect here. Let's say that we have a peer with a sharePolicy of false. If it boots up for the first time and tries to
find
a document, will this now be immediately synced with all peers?