Skip to content

Commit

Permalink
feat: test bi-directional syncing in update test
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrody committed Jun 13, 2024
1 parent 2dae25a commit 8d3907c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 143 deletions.
6 changes: 3 additions & 3 deletions suite/src/__tests__/fast/longevity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const ComposeDbUrls = String(process.env.COMPOSEDB_URLS).split(',')
* accessible days later, possibly even after a new version of Ceramic is released and deployed.
*/
describe('longevity', () => {
// `step` is incremented once for each r/w node during the `update` test, so use
// the length of the r/w URL array to test the content.
const expectedContent = { step: ComposeDbUrls.length }
// `step` is incremented once for the first r/w node and twice for each subsequent node,
// during the `update` test, so use the length of the r/w URL array to test the content.
const expectedContent = { step: 1 + (ComposeDbUrls.length - 1) * 2 }
let streamIds: Array<StreamID> = []

beforeAll(async () => {
Expand Down
27 changes: 23 additions & 4 deletions suite/src/__tests__/fast/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,16 @@ function testUpdate(composeDbUrls: string[]) {
)
})
test(`sync stream on ${apiUrl}`, async () => {
const isFinalWriter = idx == composeDbUrls.length - 1
// Update the content as we iterate through the list of node URLs so that each step includes some change
// from the previous step.
content.step++
// Update on first node and wait for update to propagate to other nodes via pubsub
// Only anchor on the final write to avoid writes conflicting with anchors.
// Update on first node and wait for update to propagate to other nodes
console.log(
`Updating stream ${firstDocument.id.toString()} on ${firstNodeUrl} so we can sync it on ${apiUrl} with step ${
content.step
}`,
)
await firstDocument.replace(content, undefined, { anchor: isFinalWriter })
await firstDocument.replace(content, undefined, { anchor: false })
await waitForCondition(doc, (state) => state.content.step == content.step, SYNC_TIMEOUT_MS)
await doc.sync({ sync: SyncOptions.NEVER_SYNC })
expect(doc.content).toEqual(firstDocument.content)
Expand All @@ -131,6 +129,27 @@ function testUpdate(composeDbUrls: string[]) {
content.step
}`,
)
})
test(`update on ${apiUrl}, sync on ${firstNodeUrl}`, async () => {
const isFinalWriter = idx == composeDbUrls.length - 1
// Now Update the stream on the non-first-node and check that the write syncs back to the
// first node. This way we ensure writes are syncing in both directions.
content.step++
console.log(
`Updating stream ${doc.id.toString()} on ${apiUrl} so we can sync it on ${firstNodeUrl} with step ${
content.step
}`,
)
// Only anchor on the final write to avoid writes conflicting with anchors.
await doc.replace(content, undefined, { anchor: isFinalWriter })
await waitForCondition(doc, (state) => state.content.step == content.step, SYNC_TIMEOUT_MS)
await firstDocument.sync({ sync: SyncOptions.NEVER_SYNC })
expect(firstDocument.content).toEqual(doc.content)
console.log(
`Synced stream on ${firstNodeUrl}: ${firstDocument.id.toString()} successfully with step ${
content.step
}`,
)

if (isFinalWriter) {
// Store the anchor request in the DB
Expand Down
136 changes: 0 additions & 136 deletions suite/src/__tests__/slow/ceramic-ceramic-integration.test.ts

This file was deleted.

0 comments on commit 8d3907c

Please sign in to comment.