Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JulissaDantes committed Mar 20, 2024
1 parent e21f329 commit 8a74337
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 66 deletions.
45 changes: 21 additions & 24 deletions packages/cli/src/__tests__/ceramic-daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,34 +447,31 @@ describe('Ceramic interop: core <> http-client', () => {
clearTimeout(id)
})

test(
'Aborts fetch if taking too long even if given an AbortSignal that did not get aborted',
async () => {
const content1 = { test: 123 }
const doc = await TileDocument.create(core, content1, null, { anchor: false })

const loadStreamMock = jest.spyOn(core, 'loadStream')
let id = null
loadStreamMock.mockImplementation(() => {
return new Promise((resolve) => {
id = setTimeout(() => {
resolve(doc)
}, 4000)
})
test('Aborts fetch if taking too long even if given an AbortSignal that did not get aborted', async () => {
const content1 = { test: 123 }
const doc = await TileDocument.create(core, content1, null, { anchor: false })

const loadStreamMock = jest.spyOn(core, 'loadStream')
let id = null
loadStreamMock.mockImplementation(() => {
return new Promise((resolve) => {
id = setTimeout(() => {
resolve(doc)
}, 4000)
})
})

const controller = new AbortController()
const controller = new AbortController()

await expect(
fetchJson(`http://localhost:${daemon.port}/api/v0/streams/${doc.id}/content`, {
signal: controller.signal,
timeout: 1000,
})
).rejects.toThrow(/aborted/)
await expect(
fetchJson(`http://localhost:${daemon.port}/api/v0/streams/${doc.id}/content`, {
signal: controller.signal,
timeout: 1000,
})
).rejects.toThrow(/aborted/)

clearTimeout(id)
}
)
clearTimeout(id)
})

test('Aborts fetch if the AbortSignal given has already been aborted', async () => {
const content1 = { test: 123 }
Expand Down
3 changes: 0 additions & 3 deletions packages/common-test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import {
import first from 'it-first'
import { BaseTestUtils } from '@ceramicnetwork/base-test-utils'

export const testIfV3 = process.env['CERAMIC_RECON_MODE'] ? test.skip : test
export const describeIfV3 = process.env['CERAMIC_RECON_MODE'] ? describe.skip : describe

class FakeRunningState extends BehaviorSubject<StreamState> implements RunningStateLike {
readonly id: StreamID
readonly state: StreamState
Expand Down
68 changes: 29 additions & 39 deletions packages/stream-tests/src/__tests__/model-instance-document.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe, beforeAll, afterAll } from '@jest/globals'
import getPort from 'get-port'
import { AnchorStatus, EventType, IpfsApi, LoggerProvider } from '@ceramicnetwork/common'
import { AnchorStatus, EventType, IpfsApi, LoggerProvider, Networks } from '@ceramicnetwork/common'
import { Utils as CoreUtils, ReconApi } from '@ceramicnetwork/core'
import { createIPFS, swarmConnect } from '@ceramicnetwork/ipfs-daemon'
import {
Expand Down Expand Up @@ -439,56 +439,43 @@ describe('ModelInstanceDocument API multi-node tests', () => {
let reconApi1: ReconApi

beforeAll(async () => {
ipfs0 = await createIPFS()
ipfs1 = await createIPFS()

await swarmConnect(ipfs0, ipfs1)
if (process.env.CERAMIC_RECON_MODE) {
const regexPattern = new RegExp(`${RECON_URL}.*`)

reconApi0 = new ReconApi(
{
enabled: false,
url: RECON_URL,
feedEnabled: false,
},
LOGGER,
fetch
)

reconApi1 = new ReconApi(
{
enabled: false,
url: RECON_URL,
feedEnabled: false,
},
LOGGER,
fetch
)

await reconApi0.init()
await reconApi1.init()
/* const regexPattern = new RegExp(`${RECON_URL}.*`)
mocker.mock({
url: regexPattern,
body: JSON.stringify({ events: [], resumeToken: 'test' }),
status: 200,
})*/
ipfs0 = await createIPFS({
rust: {
type: 'binary',
network: Networks.INMEMORY,
},
})

// Simulates --ipfs-api
ipfs0.config.set('Addresses.API', RECON_URL)
ipfs1.config.set('Addresses.API', RECON_URL)
ipfs1 = await createIPFS({
rust: {
type: 'binary',
network: Networks.INMEMORY,
},
})
} else {
ipfs0 = await createIPFS()
ipfs1 = await createIPFS()
}

await swarmConnect(ipfs0, ipfs1)
console.log("1")
ceramic0 = await createCeramic(ipfs0)
console.log("1")
ceramic1 = await createCeramic(ipfs1)

reconApi0.stop()
reconApi1.stop()

console.log("1")
model = await Model.create(ceramic0, MODEL_DEFINITION)
reconApi0.stop()
reconApi1.stop()
console.log("1")
if (process.env.CERAMIC_RECON_MODE)
await TestUtils.waitForEvent(ceramic0.repository.recon, model.tip)

console.log("1")
midMetadata = { model: model.id }
}, 80000)

Expand All @@ -503,6 +490,9 @@ describe('ModelInstanceDocument API multi-node tests', () => {
test.only('load basic doc', async () => {
const doc = await ModelInstanceDocument.create(ceramic0, CONTENT0, midMetadata)

if (process.env.CERAMIC_RECON_MODE)
await TestUtils.waitForEvent(ceramic1.repository.recon, doc.tip)

const loaded = await ModelInstanceDocument.load(ceramic1, doc.id)

const docState = doc.state
Expand Down

0 comments on commit 8a74337

Please sign in to comment.