Skip to content

Commit

Permalink
fix: fallback bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeanAsad committed Oct 17, 2023
1 parent e0065d8 commit 109019b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class Saturn {
const remainingBytes = byteCountCheckpoint - byteCount
if (remainingBytes < chunk.length) {
yield chunk.slice(remainingBytes)
byteCountCheckpoint += chunk.length - remainingBytes
}
} else {
yield chunk
Expand Down
2 changes: 1 addition & 1 deletion src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function parseUrl (url) {
// This is a temp function to resolve URLs for mock testing
// See issue here: https://github.com/mswjs/msw/issues/1597
if (process.env.TESTING) {
return url.href
return url.toJSON()
}
return url
}
Expand Down
10 changes: 7 additions & 3 deletions test/fallback.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { describe, mock, test } from 'node:test'
import { Saturn } from '#src/index.js'
import { concatChunks, generateNodes, getMockServer, mockJWT, mockNodesHandlers, mockOrchHandler, mockSaturnOriginHandler, MSW_SERVER_OPTS } from './test-utils.js'

const TEST_DEFAULT_ORCH = 'https://orchestrator.strn.pl/nodes?maxNodes=100'
const TEST_DEFAULT_ORCH = 'https://orchestrator.strn.pl/nodes'
const TEST_NODES_LIST_KEY = 'saturn-nodes'
const TEST_AUTH = 'https://fz3dyeyxmebszwhuiky7vggmsu0rlkoy.lambda-url.us-west-2.on.aws/'
const TEST_ORIGIN_DOMAIN = 'saturn.ms'
Expand Down Expand Up @@ -277,10 +277,14 @@ describe('Client Fallback', () => {
callCount++
if (callCount === 1) {
yield Buffer.from('chunk1-')
yield Buffer.from('overlap')
throw new Error('First call error')
}
if (callCount === 2) {
yield Buffer.from('chunk1')
yield Buffer.from('-overlap')
throw new Error('Second call error')
}
if (callCount === 3) {
yield Buffer.from('chunk1-overlap')
yield Buffer.from('chunk2')
}
Expand All @@ -292,7 +296,7 @@ describe('Client Fallback', () => {
buffer = await concatChunks(content)

assert.deepEqual(buffer, expectedContent)
assert.strictEqual(fetchContentMock.mock.calls.length, 2)
assert.strictEqual(fetchContentMock.mock.calls.length, 3)

server.close()
mock.reset()
Expand Down

0 comments on commit 109019b

Please sign in to comment.