Skip to content

Commit

Permalink
Merge pull request #729 from gabrielrussoc/100mb-spawnSync
Browse files Browse the repository at this point in the history
fix: increase maxBuffer of spawnSync
  • Loading branch information
drazisil-codecov authored Apr 22, 2022
2 parents d66522e + f77db22 commit 540fcc4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/helpers/constansts.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const DEFAULT_UPLOAD_HOST = 'https://codecov.io'

export const SPAWNPROCESSBUFFERSIZE = 1_048_576 * 100 // 100 MiB
11 changes: 6 additions & 5 deletions src/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UploaderArgs } from '../types'
import { logError, UploadLogger } from './logger'
import { runExternalProgram } from './util'
import micromatch from "../vendor/micromatch/index.js";
import { SPAWNPROCESSBUFFERSIZE } from './constansts'

export const MARKER_NETWORK_END = '\n<<<<<< network\n'
export const MARKER_FILE_END = '<<<<<< EOF\n'
Expand Down Expand Up @@ -235,11 +236,11 @@ export function getAllFiles(
): string[] {
UploadLogger.verbose(`Searching for files in ${dirPath}`)

const {
stdout,
status,
error,
} = spawnSync('git', ['-C', dirPath, 'ls-files'], { encoding: 'utf8' })
const { stdout, status, error } = spawnSync(
'git',
['-C', dirPath, 'ls-files'],
{ encoding: 'utf8', maxBuffer: SPAWNPROCESSBUFFERSIZE },
)

let files = []
if (error instanceof Error || status !== 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import childprocess from 'child_process'
import { SPAWNPROCESSBUFFERSIZE } from './constansts'
export { SPAWNPROCESSBUFFERSIZE } from './constansts'


export const SPAWNPROCESSBUFFERSIZE = 1_048_576 * 10 // 10 MiB

export function isProgramInstalled(programName: string): boolean {
return !childprocess.spawnSync(programName).error
Expand Down
83 changes: 41 additions & 42 deletions test/helpers/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
import childProcess from 'child_process'
import td from 'testdouble'
import {
isProgramInstalled,
runExternalProgram,
SPAWNPROCESSBUFFERSIZE,
} from '../../src/helpers/util'
import { isProgramInstalled, runExternalProgram } from '../../src/helpers/util'
import { SPAWNPROCESSBUFFERSIZE } from '../../src/helpers/constansts'

describe('isProgramInstalled()', () => {
afterEach(() => {
td.reset()
})

it('should throw an error when program is not found', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(spawnSync('fooProg')).thenReturn({
error: 'Huh?',
})
expect(isProgramInstalled('fooProg')).toBeFalsy()

afterEach(() => {
td.reset()
})

it('should throw an error when program is not found', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(spawnSync('fooProg')).thenReturn({
error: 'Huh?',
})
expect(isProgramInstalled('fooProg')).toBeFalsy()
})
})

describe('runExternalProgram()', () => {
afterEach(() => {
td.reset()
afterEach(() => {
td.reset()
})

it('should throw an error when program is not found', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('ls', ['-geewhiz'], { maxBuffer: SPAWNPROCESSBUFFERSIZE }),
).thenReturn({
error: 'Huh?',
})

it('should throw an error when program is not found', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(spawnSync('ls', ['-geewhiz'], { maxBuffer: SPAWNPROCESSBUFFERSIZE })).thenReturn({
error: 'Huh?',
})
expect(() => runExternalProgram('ls', ['-geewhiz'])).toThrowError(/Huh\?/)

expect(() => runExternalProgram('ls', ['-geewhiz'])).toThrowError(/Huh\?/)
})

it('should return stdout on success', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('ls', ['-geewhiz'], { maxBuffer: SPAWNPROCESSBUFFERSIZE }),
).thenReturn({
stdout: 'I am output',
})
expect(runExternalProgram('ls', ['-geewhiz'])).toEqual('I am output')
})

it('should return stdout on success', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(spawnSync('ls', ['-geewhiz'], { maxBuffer: SPAWNPROCESSBUFFERSIZE })).thenReturn({
stdout: 'I am output',
})
expect(runExternalProgram('ls', ['-geewhiz'])).toEqual("I am output")

})

it('should return a trimmed string with no newlines', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(spawnSync('ls', ['-geewhiz'], { maxBuffer: SPAWNPROCESSBUFFERSIZE })).thenReturn({
stdout: `
it('should return a trimmed string with no newlines', () => {
const spawnSync = td.replace(childProcess, 'spawnSync')
td.when(
spawnSync('ls', ['-geewhiz'], { maxBuffer: SPAWNPROCESSBUFFERSIZE }),
).thenReturn({
stdout: `
I am output
`,
})
expect(runExternalProgram('ls', ['-geewhiz'])).toEqual("I am output")

})
expect(runExternalProgram('ls', ['-geewhiz'])).toEqual('I am output')
})
})

0 comments on commit 540fcc4

Please sign in to comment.