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

Fix node versions #3286

Merged
merged 3 commits into from
Mar 12, 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
68 changes: 37 additions & 31 deletions packages/client/test/sync/fetcher/fetcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as td from 'testdouble'
import { assert, describe, it } from 'vitest'
import { assert, describe, it, vi } from 'vitest'

import { Config } from '../../../src/config'
import { Fetcher } from '../../../src/sync/fetcher/fetcher'
Expand All @@ -12,7 +12,8 @@ class FetcherTest extends Fetcher<any, any, any> {
return res
}
async request(_job: any, _peer: any) {
return
console.trace(_job)
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure: is this console.trace() meant to stay here (is this only triggered in the failure case for debugging e.g.?)?

Copy link
Member

Choose a reason for hiding this comment

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

(Otherwise: cool 🤩 and congrats on the merge! 🙏)

return _job
}
async store(_store: any) {}
// Just return any via _error
Expand Down Expand Up @@ -51,36 +52,41 @@ it('should handle failure', () => {
})

describe('should handle expiration', async () => {
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const fetcher = new FetcherTest({
config,
pool: td.object(),
timeout: 5,
})
const job = { index: 0 }
const peer = { idle: true }
fetcher.peer = td.func<FetcherTest['peer']>()
fetcher.request = td.func<FetcherTest['request']>()
td.when(fetcher.peer()).thenReturn(peer)
td.when(fetcher.request(td.matchers.anything(), { idle: false }), { delay: 10 }).thenReject(
new Error('err0')
)
td.when(fetcher['pool'].contains({ idle: false } as any)).thenReturn(true)
fetcher['in'].insert(job as any)
fetcher['_readableState'] = []
fetcher['running'] = true
fetcher['total'] = 10
fetcher.next()
await new Promise((resolve) => {
setTimeout(resolve, 10)
})
it('should expire', () => {
it('should expire', async () => {
const config = new Config({ accountCache: 10000, storageCache: 1000 })
const fetcher = new FetcherTest({
config,
pool: {
contains(peer: any) {
if (peer.idle === false) return true
return false
},
ban: vi.fn(),
} as any,
timeout: 5,
})
const job = { index: 0 }
const peer = { idle: true }
fetcher.peer = vi.fn().mockReturnValue(() => peer)
fetcher.request = vi.fn().mockImplementationOnce(async (job, peer) => {
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
if (peer.idle === false) throw new Error('err0')
return
})

fetcher['in'].insert(job as any)
fetcher['_readableState'] = []
fetcher['running'] = true
fetcher['total'] = 10
fetcher.next()
await new Promise((resolve) => {
setTimeout(resolve, 10)
})

assert.equal((fetcher as any).in.length, 1, 'enqueued job')
assert.deepEqual(
job as any,
{ index: 0, peer: { idle: false }, state: 'expired' },
'expired job'
)
assert.deepEqual((job as any).state, 'expired', 'expired job')
})
})

Expand Down
Loading