Skip to content
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

feat: test bi-directional syncing in update test #144

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this is going to break the longevity tests for existing streams in the database that were created with the old version of the update test that had fewer steps. We might need to coordinate merging this PR with clearing out the dynamodb database to prevent spurious failures, unfortunately

let streamIds: Array<StreamID> = []

beforeAll(async () => {
Expand Down
31 changes: 25 additions & 6 deletions suite/src/__tests__/fast/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StreamReaderWriter, SyncOptions } from '@ceramicnetwork/common'
import CeramicClient from '@ceramicnetwork/http-client'
import { CeramicClient } from '@ceramicnetwork/http-client'
import { afterAll, beforeAll, expect, test, describe } from '@jest/globals'

import * as helpers from '../../utils/dynamoDbHelpers.js'
Expand Down Expand Up @@ -58,7 +58,7 @@ function testUpdate(composeDbUrls: string[]) {
console.log(`test update with urls: ${composeDbUrls}`)
const firstNodeUrl = composeDbUrls[0]
const content = { step: 0 }
let firstCeramic: CeramicClient.CeramicClient
let firstCeramic: CeramicClient
let firstDocument: ModelInstanceDocument

// Create and update on first node
Expand Down 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
73 changes: 43 additions & 30 deletions suite/src/__tests__/slow/ceramic-cas-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import { AnchorStatus, StreamReaderWriter } from '@ceramicnetwork/common'
import { TileDocument } from '@ceramicnetwork/stream-tile'
import { jest, describe, test, beforeAll, expect } from '@jest/globals'
import { AnchorStatus } from '@ceramicnetwork/common'
import { describe, test, beforeAll, expect } from '@jest/globals'
import { newCeramic, waitForAnchor } from '../../utils/ceramicHelpers.js'
import { createDid } from '../../utils/didHelper.js'
import { Model } from '@ceramicnetwork/stream-model'
import { LIST_MODEL_DEFINITION } from '../../models/modelConstants.js'
import { indexModelOnNode } from '../../utils/composeDbHelpers.js'
import { CeramicClient } from '@ceramicnetwork/http-client'
import { ModelInstanceDocument } from '@ceramicnetwork/stream-model-instance'
import { StreamID } from '@ceramicnetwork/streamid'

const ComposeDbUrls = String(process.env.COMPOSEDB_URLS).split(',')
const adminSeeds = String(process.env.COMPOSEDB_ADMIN_DID_SEEDS).split(',')

// Skipped https://linear.app/3boxlabs/issue/WS1-1460/unskip-ceramic-cas-basic-integration
describe.skip('Ceramic<->CAS basic integration', () => {
jest.setTimeout(1000 * 60 * 60) // 1 hour
let ceramic: StreamReaderWriter
describe('Ceramic<->CAS basic integration', () => {
let ceramic: CeramicClient
let modelId: StreamID

beforeAll(async () => {
ceramic = await newCeramic(ComposeDbUrls[0])
const did = await createDid(adminSeeds[0])
ceramic = await newCeramic(ComposeDbUrls[0], did)
const model = await Model.create(ceramic, LIST_MODEL_DEFINITION)
modelId = model.id
await indexModelOnNode(ceramic, model.id)
})

test('basic crud is anchored properly, single update per anchor batch', async () => {
// Test document creation
console.log('Creating document')
const initialContent = { foo: 'bar' }
const doc = await TileDocument.create<any>(ceramic, initialContent)
const initialContent = { step: 0 }
const metadata = { controllers: [ceramic.did!.id], model: modelId }
const doc = await ModelInstanceDocument.create(ceramic, initialContent, metadata)
expect(doc.content).toEqual(initialContent)

// Test document creation is anchored correctly
Expand All @@ -30,8 +42,8 @@ describe.skip('Ceramic<->CAS basic integration', () => {

// Test document update
console.log('Updating document')
const newContent = { bar: 'baz' }
await doc.update(newContent)
const newContent = { step: 1 }
await doc.replace(newContent)
expect(doc.content).toEqual(newContent)

// Test document update is anchored correctly
Expand All @@ -44,18 +56,19 @@ describe.skip('Ceramic<->CAS basic integration', () => {
})

test('multiple documents are anchored properly, multiple updates per anchor batch', async () => {
const content0 = { state: 0 }
const content1 = { state: 1 }
const content2 = { state: 2 }
const content3 = { state: 3 }
const content4 = { state: 4 }
const content0 = { step: 0 }
const content1 = { step: 1 }
const content2 = { step: 2 }
const content3 = { step: 3 }
const content4 = { step: 4 }
const metadata = { controllers: [ceramic.did!.id], model: modelId }

// Create some documents
console.log('Creating documents')
const doc1 = await TileDocument.create(ceramic, content0)
const doc2 = await TileDocument.create(ceramic, content0)
const doc3 = await TileDocument.create(ceramic, content0)
const doc4 = await TileDocument.create(ceramic, content0)
const doc1 = await ModelInstanceDocument.create(ceramic, content0, metadata)
const doc2 = await ModelInstanceDocument.create(ceramic, content0, metadata)
const doc3 = await ModelInstanceDocument.create(ceramic, content0, metadata)
const doc4 = await ModelInstanceDocument.create(ceramic, content0, metadata)
expect(doc1.content).toEqual(content0)
expect(doc2.content).toEqual(content0)
expect(doc3.content).toEqual(content0)
Expand Down Expand Up @@ -87,19 +100,19 @@ describe.skip('Ceramic<->CAS basic integration', () => {

// Test document updates
console.log('Updating documents')
await doc1.update(content1, undefined, { anchor: true })
await doc2.update(content1, undefined, { anchor: false })
await doc3.update(content1, undefined, { anchor: false })
await doc4.update(content1, undefined, { anchor: false })
await doc1.replace(content1, undefined, { anchor: true })
await doc2.replace(content1, undefined, { anchor: false })
await doc3.replace(content1, undefined, { anchor: false })
await doc4.replace(content1, undefined, { anchor: false })

await doc2.update(content2, undefined, { anchor: true })
await doc3.update(content2, undefined, { anchor: false })
await doc4.update(content2, undefined, { anchor: false })
await doc2.replace(content2, undefined, { anchor: true })
await doc3.replace(content2, undefined, { anchor: false })
await doc4.replace(content2, undefined, { anchor: false })

await doc3.update(content3, undefined, { anchor: true })
await doc4.update(content3, undefined, { anchor: false })
await doc3.replace(content3, undefined, { anchor: true })
await doc4.replace(content3, undefined, { anchor: false })

await doc4.update(content4, undefined, { anchor: true })
await doc4.replace(content4, undefined, { anchor: true })

expect(doc1.content).toEqual(content1)
expect(doc2.content).toEqual(content2)
Expand Down
136 changes: 0 additions & 136 deletions suite/src/__tests__/slow/ceramic-ceramic-integration.test.ts

This file was deleted.