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

test: Wait for The Graph before starting the crawl #23

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
19 changes: 14 additions & 5 deletions test/end-to-end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'reflect-metadata'
import { DhtAddress, NodeType, createRandomDhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '@streamr/dht'
import StreamrClient, { CONFIG_TEST, NetworkNodeType, PeerDescriptor, StreamID, StreamPermission, StreamrClientConfig } from '@streamr/sdk'
import { NetworkNode, createNetworkNode } from '@streamr/trackerless-network'
import { StreamPartID, setAbortableInterval, toStreamPartID, waitForCondition } from '@streamr/utils'
import { StreamPartID, collect, setAbortableInterval, toStreamPartID, waitForCondition } from '@streamr/utils'
import { sample, uniq, without } from 'lodash'
import Container from 'typedi'
import { CONFIG_TOKEN } from '../src/Config'
Expand Down Expand Up @@ -65,11 +65,9 @@ const createClientConfig = (entryPointPeerDescriptor: PeerDescriptor): StreamrCl
}
}

const createClient = (privateKey: string, entryPointPeerDescriptor: PeerDescriptor) => {
const createClient = (privateKey: string | undefined, entryPointPeerDescriptor: PeerDescriptor) => {
return new StreamrClient({
auth: {
privateKey
},
auth: (privateKey !== undefined) ? { privateKey } : undefined,
...createClientConfig(entryPointPeerDescriptor)
})
}
Expand Down Expand Up @@ -179,6 +177,16 @@ describe('end-to-end', () => {
}))
}

const waitForTheGraphToIndex = async (streamIds: StreamID[]): Promise<void> => {
const client = createClient(undefined, entryPoint.getPeerDescriptor())
for (const streamId of streamIds) {
await waitForCondition(async () => {
const streams = await collect(client.searchStreams(streamId, undefined))
return streams.length > 0
}, 5000, 500)
}
}

beforeAll(async () => {
entryPoint = await startEntryPoint()
const config = {
Expand Down Expand Up @@ -223,6 +231,7 @@ describe('end-to-end', () => {
await startPublisherAndSubscriberForStream(privateStream.id, publishingAbortControler.signal)
const publicStream = await createTestStream(true)
await startPublisherAndSubscriberForStream(publicStream.id, publishingAbortControler.signal)
await waitForTheGraphToIndex([privateStream.id, publicStream.id])

crawler = Container.get(Crawler)
await crawler.start(1)
Expand Down
Loading