Skip to content

Commit

Permalink
✨[RUMF-1377] Enable new transfer strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Oct 20, 2022
1 parent 17d5f96 commit c79f903
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 21 additions & 0 deletions packages/core/src/transport/httpRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createEndpointBuilder } from '../domain/configuration'
import { noop } from '../tools/utils'
import { createHttpRequest, fetchKeepAliveStrategy } from './httpRequest'
import type { HttpRequest } from './httpRequest'
import { INITIAL_BACKOFF_TIME } from './sendWithRetryStrategy'

describe('httpRequest', () => {
const BATCH_BYTES_LIMIT = 100
Expand Down Expand Up @@ -73,6 +74,26 @@ describe('httpRequest', () => {
done()
})
})

it('should use retry strategy', (done) => {
let calls = 0
interceptor.withFetch(() => {
calls++
if (calls === 1) {
return Promise.resolve({ status: 408 })
}
if (calls === 2) {
return Promise.resolve({ status: 200 })
}
})

request.send({ data: '{"foo":"bar1"}\n{"foo":"bar2"}', bytesCount: 10 })

setTimeout(() => {
expect(calls).toEqual(2)
done()
}, INITIAL_BACKOFF_TIME + 1)
})
})

describe('fetchKeepAliveStrategy onResponse', () => {
Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/transport/httpRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { EndpointBuilder } from '../domain/configuration'
import { addTelemetryError } from '../domain/telemetry'
import { monitor } from '../tools/monitor'
import { isExperimentalFeatureEnabled } from '../domain/configuration'
import type { RawError } from '../tools/error'
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'

Expand All @@ -15,6 +14,7 @@ import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'
*/

export type HttpRequest = ReturnType<typeof createHttpRequest>

export interface HttpResponse {
status: number
}
Expand All @@ -35,11 +35,7 @@ export function createHttpRequest(

return {
send: (payload: Payload) => {
if (!isExperimentalFeatureEnabled('retry')) {
fetchKeepAliveStrategy(endpointBuilder, bytesLimit, payload)
} else {
sendWithRetryStrategy(payload, retryState, sendStrategyForRetry, endpointBuilder.endpointType, reportError)
}
sendWithRetryStrategy(payload, retryState, sendStrategyForRetry, endpointBuilder.endpointType, reportError)
},
/**
* Since fetch keepalive behaves like regular fetch on Firefox,
Expand Down

0 comments on commit c79f903

Please sign in to comment.