2020-07-10 15:09:32 +00:00
|
|
|
import {
|
|
|
|
DownloadOptions,
|
|
|
|
UploadOptions,
|
|
|
|
getDownloadOptions,
|
|
|
|
getUploadOptions
|
|
|
|
} from '../src/options'
|
|
|
|
|
2023-08-07 17:25:56 +00:00
|
|
|
const useAzureSdk = false
|
|
|
|
const concurrentBlobDownloads = true
|
2020-07-10 15:09:32 +00:00
|
|
|
const downloadConcurrency = 8
|
|
|
|
const timeoutInMs = 30000
|
2023-03-08 09:26:29 +00:00
|
|
|
const segmentTimeoutInMs = 600000
|
2023-01-17 16:12:42 +00:00
|
|
|
const lookupOnly = false
|
2020-07-10 15:09:32 +00:00
|
|
|
|
|
|
|
test('getDownloadOptions sets defaults', async () => {
|
|
|
|
const actualOptions = getDownloadOptions()
|
|
|
|
|
|
|
|
expect(actualOptions).toEqual({
|
|
|
|
useAzureSdk,
|
2023-08-07 17:25:56 +00:00
|
|
|
concurrentBlobDownloads,
|
2020-07-10 15:09:32 +00:00
|
|
|
downloadConcurrency,
|
2022-08-03 13:25:47 +00:00
|
|
|
timeoutInMs,
|
2022-12-23 11:44:35 +00:00
|
|
|
segmentTimeoutInMs,
|
2023-01-17 16:12:42 +00:00
|
|
|
lookupOnly
|
2020-07-10 15:09:32 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('getDownloadOptions overrides all settings', async () => {
|
|
|
|
const expectedOptions: DownloadOptions = {
|
2023-08-07 17:25:56 +00:00
|
|
|
useAzureSdk: true,
|
|
|
|
concurrentBlobDownloads: false,
|
2020-07-10 15:09:32 +00:00
|
|
|
downloadConcurrency: 14,
|
2022-08-03 13:25:47 +00:00
|
|
|
timeoutInMs: 20000,
|
2022-12-23 11:44:35 +00:00
|
|
|
segmentTimeoutInMs: 3600000,
|
2023-01-17 16:12:42 +00:00
|
|
|
lookupOnly: true
|
2020-07-10 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const actualOptions = getDownloadOptions(expectedOptions)
|
|
|
|
|
|
|
|
expect(actualOptions).toEqual(expectedOptions)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('getUploadOptions sets defaults', async () => {
|
2024-12-02 15:32:33 +00:00
|
|
|
const expectedOptions: UploadOptions = {
|
|
|
|
uploadConcurrency: 4,
|
|
|
|
uploadChunkSize: 32 * 1024 * 1024,
|
|
|
|
useAzureSdk: false
|
|
|
|
}
|
2020-07-10 15:09:32 +00:00
|
|
|
const actualOptions = getUploadOptions()
|
|
|
|
|
2024-12-02 15:32:33 +00:00
|
|
|
expect(actualOptions).toEqual(expectedOptions)
|
2020-07-10 15:09:32 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('getUploadOptions overrides all settings', async () => {
|
|
|
|
const expectedOptions: UploadOptions = {
|
|
|
|
uploadConcurrency: 2,
|
2024-11-28 15:22:01 +00:00
|
|
|
uploadChunkSize: 16 * 1024 * 1024,
|
|
|
|
useAzureSdk: true
|
2020-07-10 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const actualOptions = getUploadOptions(expectedOptions)
|
|
|
|
|
|
|
|
expect(actualOptions).toEqual(expectedOptions)
|
|
|
|
})
|
2022-08-16 04:14:27 +00:00
|
|
|
|
2024-12-02 15:32:33 +00:00
|
|
|
test('env variables override all getUploadOptions settings', async () => {
|
|
|
|
const expectedOptions: UploadOptions = {
|
|
|
|
uploadConcurrency: 16,
|
|
|
|
uploadChunkSize: 64 * 1024 * 1024,
|
|
|
|
useAzureSdk: true
|
|
|
|
}
|
|
|
|
|
|
|
|
process.env.CACHE_UPLOAD_CONCURRENCY = '16'
|
|
|
|
process.env.CACHE_UPLOAD_CHUNK_SIZE = '64'
|
|
|
|
|
|
|
|
const actualOptions = getUploadOptions(expectedOptions)
|
|
|
|
expect(actualOptions).toEqual(expectedOptions)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('env variables override all getUploadOptions settings but do not exceed caps', async () => {
|
|
|
|
const expectedOptions: UploadOptions = {
|
|
|
|
uploadConcurrency: 32,
|
|
|
|
uploadChunkSize: 128 * 1024 * 1024,
|
|
|
|
useAzureSdk: true
|
|
|
|
}
|
|
|
|
|
|
|
|
process.env.CACHE_UPLOAD_CONCURRENCY = '64'
|
|
|
|
process.env.CACHE_UPLOAD_CHUNK_SIZE = '256'
|
|
|
|
|
|
|
|
const actualOptions = getUploadOptions(expectedOptions)
|
|
|
|
expect(actualOptions).toEqual(expectedOptions)
|
|
|
|
})
|
|
|
|
|
2022-08-16 04:14:27 +00:00
|
|
|
test('getDownloadOptions overrides download timeout minutes', async () => {
|
|
|
|
const expectedOptions: DownloadOptions = {
|
|
|
|
useAzureSdk: false,
|
|
|
|
downloadConcurrency: 14,
|
|
|
|
timeoutInMs: 20000,
|
2022-12-23 11:44:35 +00:00
|
|
|
segmentTimeoutInMs: 3600000,
|
2023-01-17 16:12:42 +00:00
|
|
|
lookupOnly: true
|
2022-08-16 04:14:27 +00:00
|
|
|
}
|
2022-08-18 05:32:49 +00:00
|
|
|
process.env.SEGMENT_DOWNLOAD_TIMEOUT_MINS = '10'
|
2022-08-16 04:14:27 +00:00
|
|
|
const actualOptions = getDownloadOptions(expectedOptions)
|
|
|
|
|
|
|
|
expect(actualOptions.useAzureSdk).toEqual(expectedOptions.useAzureSdk)
|
|
|
|
expect(actualOptions.downloadConcurrency).toEqual(
|
|
|
|
expectedOptions.downloadConcurrency
|
|
|
|
)
|
|
|
|
expect(actualOptions.timeoutInMs).toEqual(expectedOptions.timeoutInMs)
|
|
|
|
expect(actualOptions.segmentTimeoutInMs).toEqual(600000)
|
2023-01-17 16:12:42 +00:00
|
|
|
expect(actualOptions.lookupOnly).toEqual(expectedOptions.lookupOnly)
|
2022-08-16 04:14:27 +00:00
|
|
|
})
|