Skip to content

Commit 17dea84

Browse files
committed
add test for current variable
1 parent 23302fe commit 17dea84

4 files changed

Lines changed: 98 additions & 9 deletions

File tree

bin/rerun

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if(argv.protractor) {
1515
stackAnalize: () => true,
1616
everyCycleCallback: async () => true,
1717
grepWord: argv.grepWord || '',
18-
longestTestTime: 450000,
18+
longestProcessTime: 450000,
1919
debugProcess: false,
2020
formCommanWithOption: undefined,
2121
pollTime: 1000

lib/commandExecutorBuilder.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function buildCommandExecutor(failedByAssert, runOpts) {
66
const {
77
addSpecificOptionsBeforeRun,
88
currentExecutionVariable,
9-
longestTestTime,
9+
longestProcessTime,
1010
debugProcess,
1111
addCommandOptionsAfterRun,
1212
stackAnalize
@@ -15,9 +15,16 @@ function buildCommandExecutor(failedByAssert, runOpts) {
1515

1616
const executeCommandAsync = (cmd, index) => new Promise((resolve) => {
1717

18+
let watcher = null
1819
let specificCallBack = null
20+
let killTooLongExecution = null
1921
let executionStack = ''
2022

23+
/**
24+
* @now this variable will be used for process kill if time more than @longestProcessTime
25+
*/
26+
const now = +Date.now()
27+
2128
/**
2229
* @param {undefined|function} addSpecificOptions if function cmd will go to this function as argument
2330
*/
@@ -37,12 +44,17 @@ function buildCommandExecutor(failedByAssert, runOpts) {
3744

3845
if(debugProcess) {console.log(cmd)}
3946

40-
const now = +Date.now()
4147
const proc = exec(cmd)
4248

43-
const killTooLongExecution = () => {if(+Date.now() - now > longestTestTime) {clearInterval(watcher); proc.kill(); resolve(cmd)} };
49+
killTooLongExecution = () => {
50+
if(+Date.now() - now > longestProcessTime) {
51+
clearInterval(watcher)
52+
proc.kill()
53+
resolve(cmd)
54+
}
55+
};
4456

45-
const watcher = setInterval(killTooLongExecution, 15000)
57+
watcher = setInterval(killTooLongExecution, 5000)
4658

4759
proc.on('exit', () => {clearInterval(watcher)})
4860

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function reRunnerBuilder(runOptions) {
1414
intervalPoll,
1515
everyCycleCallback: afterSingleRunCallBack,
1616
specsDir,
17-
longestTestTime,
17+
longestProcessTime,
1818
formCommanWithOption: addSpecificOptionsBeforeRun,
1919
currentExecutionVariable
2020
} = runOptions
@@ -30,7 +30,7 @@ function reRunnerBuilder(runOptions) {
3030
const executeCommandAsync = buildCommandExecutor(failedByAssert, {
3131
addSpecificOptionsBeforeRun,
3232
currentExecutionVariable,
33-
longestTestTime,
33+
longestProcessTime,
3434
debugProcess,
3535
addCommandOptionsAfterRun,
3636
stackAnalize
@@ -96,7 +96,7 @@ module.exports = {
9696
everyCycleCallback,
9797
reformatCommand,
9898
grepWord = '',
99-
longestTestTime = 450000,
99+
longestProcessTime = 450000,
100100
debugProcess = false,
101101
formCommanWithOption,
102102
pollTime = 1000,
@@ -106,7 +106,7 @@ module.exports = {
106106
const reformattedArgs = {
107107
formCommanWithOption,
108108
debugProcess,
109-
longestTestTime,
109+
longestProcessTime,
110110
maxSessionCount,
111111
specRerunCount,
112112
reformatCommand,

unit_specs/commandExecutorBuilder.spec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,81 @@ describe('buildCommandExecutor', () => {
6262
expect(holder.cmd).to.eq(cmd)
6363
expect(holder.stack).to.eq('test\n')
6464
})
65+
66+
it('longestProcessTime', async () => {
67+
{
68+
const failedByAssert = []
69+
let holder = null
70+
const stackAnalize = (stack) => {
71+
holder = {}
72+
holder.fromStackAnalize = stack
73+
return false
74+
}
75+
const cmd = `node -e "(async function() {await new Promise((res) => setTimeout(() => {
76+
res(process.exit(1))
77+
}, 25000))})()"`
78+
79+
const executeCommandAsync = buildCommandExecutor(failedByAssert, {stackAnalize, longestProcessTime: 1})
80+
await executeCommandAsync(cmd)
81+
expect(holder).to.eq(null)
82+
}
83+
{
84+
const failedByAssert = []
85+
let holder = null
86+
const stackAnalize = (stack) => {
87+
holder = {}
88+
holder.fromStackAnalize = stack
89+
return false
90+
}
91+
const cmd = `node -e "(async function() {await new Promise((res) => setTimeout(() => {
92+
res(process.exit(1))
93+
}, 1))})()"`
94+
95+
const executeCommandAsync = buildCommandExecutor(failedByAssert, {stackAnalize, longestProcessTime: 10000})
96+
await executeCommandAsync(cmd)
97+
expect(holder).to.not.eq(null)
98+
}
99+
})
100+
101+
it('currentExecutionVariable', async () => {
102+
const failedByAssert = []
103+
let holder = null
104+
const cmd = `node -e "console.log('test'); process.exit(1)"`
105+
106+
const stackAnalize = (stack) => {
107+
holder = {}
108+
holder.fromStackAnalize = stack
109+
return false
110+
}
111+
112+
const addCommandOptionsAfterRun = (cmd, stack) => {
113+
if(!holder) holder = {}
114+
holder.cmd = cmd
115+
holder.stack = stack
116+
}
117+
const currentExecutionVariable = 'CURRENT_COUNT'
118+
119+
const executeCommandAsync = buildCommandExecutor(failedByAssert, {
120+
stackAnalize,
121+
addCommandOptionsAfterRun,
122+
currentExecutionVariable
123+
})
124+
125+
const expetedReformatedCommandFirstIteration = `${currentExecutionVariable}=${1} ${cmd}`
126+
const expetedReformatedCommandSecondIteration = `${currentExecutionVariable}=${2} ${cmd}`
127+
128+
// first iteration
129+
await executeCommandAsync(cmd, 1)
130+
131+
expect(holder.fromStackAnalize).to.eq('test\n')
132+
expect(holder.cmd).to.eq(expetedReformatedCommandFirstIteration)
133+
expect(holder.stack).to.eq('test\n')
134+
135+
await executeCommandAsync(expetedReformatedCommandFirstIteration, 2)
136+
137+
expect(holder.fromStackAnalize).to.eq('test\n')
138+
expect(holder.cmd).to.eq(expetedReformatedCommandSecondIteration)
139+
expect(holder.stack).to.eq('test\n')
140+
141+
})
65142
})

0 commit comments

Comments
 (0)