|
1 | 1 | import * as config from '../src/internal/shared/config'
|
| 2 | +import os from 'os' |
| 3 | + |
| 4 | +// Mock the 'os' module |
| 5 | +jest.mock('os', () => ({ |
| 6 | + cpus: jest.fn() |
| 7 | +})) |
2 | 8 |
|
3 | 9 | beforeEach(() => {
|
4 | 10 | jest.resetModules()
|
@@ -35,14 +41,53 @@ describe('uploadChunkTimeoutEnv', () => {
|
35 | 41 | it('should return default 300000 when no env set', () => {
|
36 | 42 | expect(config.getUploadChunkTimeout()).toBe(300000)
|
37 | 43 | })
|
| 44 | + |
38 | 45 | it('should return value set in ACTIONS_UPLOAD_TIMEOUT_MS', () => {
|
39 | 46 | process.env.ACTIONS_UPLOAD_TIMEOUT_MS = '150000'
|
40 | 47 | expect(config.getUploadChunkTimeout()).toBe(150000)
|
41 | 48 | })
|
| 49 | + |
42 | 50 | it('should throw if value set in ACTIONS_UPLOAD_TIMEOUT_MS is invalid', () => {
|
43 | 51 | process.env.ACTIONS_UPLOAD_TIMEOUT_MS = 'abc'
|
44 | 52 | expect(() => {
|
45 | 53 | config.getUploadChunkTimeout()
|
46 | 54 | }).toThrow()
|
47 | 55 | })
|
48 | 56 | })
|
| 57 | + |
| 58 | +describe('uploadConcurrencyEnv', () => { |
| 59 | + it('should return default 32 when cpu num is <= 4', () => { |
| 60 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 61 | + expect(config.getConcurrency()).toBe(32) |
| 62 | + }) |
| 63 | + |
| 64 | + it('should return 16 * num of cpu when cpu num is > 4', () => { |
| 65 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(6)) |
| 66 | + expect(config.getConcurrency()).toBe(96) |
| 67 | + }) |
| 68 | + |
| 69 | + it('should return up to 300 max value', () => { |
| 70 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(32)) |
| 71 | + expect(config.getConcurrency()).toBe(300) |
| 72 | + }) |
| 73 | + |
| 74 | + it('should return override value when ACTIONS_UPLOAD_CONCURRENCY is set', () => { |
| 75 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 76 | + process.env.ACTIONS_UPLOAD_CONCURRENCY = '10' |
| 77 | + expect(config.getConcurrency()).toBe(10) |
| 78 | + }) |
| 79 | + |
| 80 | + it('should throw with invalid value of ACTIONS_UPLOAD_CONCURRENCY', () => { |
| 81 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 82 | + process.env.ACTIONS_UPLOAD_CONCURRENCY = 'abc' |
| 83 | + expect(() => { |
| 84 | + config.getConcurrency() |
| 85 | + }).toThrow() |
| 86 | + }) |
| 87 | + |
| 88 | + it('cannot go over currency cap when override value is greater', () => { |
| 89 | + ;(os.cpus as jest.Mock).mockReturnValue(new Array(4)) |
| 90 | + process.env.ACTIONS_UPLOAD_CONCURRENCY = '40' |
| 91 | + expect(config.getConcurrency()).toBe(32) |
| 92 | + }) |
| 93 | +}) |
0 commit comments