Skip to content

Commit 16bfd0a

Browse files
committed
Added script timeout (thanks for the idea, Mike!)
If the script takes longer than X, fail it! Default is 0, so has no net effect on scripts if let unchanged.
1 parent 43ca799 commit 16bfd0a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

nr_synthetics_formatter/nr-synthetics.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ builder.selenium2.io.addLangFormatter({
1212
" * for details.\n" +
1313
" */\n\n" +
1414
"/** CONFIGURATIONS **/\n\n" +
15-
"// Script-wide timeout for wait and waitAndFind functions (in ms)\n" +
15+
"// Theshold for duration of entire script - fails test if script lasts longer than X (in ms)\n" +
16+
"// Default is '0', which means that it won't fail.\n" +
17+
"var ScriptTimeout = 0;\n" +
18+
"// Script-wide timeout for all wait and waitAndFind functions (in ms)\n" +
1619
"var DefaultTimeout = 10000;\n" +
1720
"// Change to any User Agent you want to use.\n" +
1821
"// Leave as \"default\" or empty to use the Synthetics default.\n" +
@@ -29,9 +32,13 @@ builder.selenium2.io.addLangFormatter({
2932
" VARS = {};\n\n" +
3033
"var log = function(thisStep, thisMsg) {\n" +
3134
" if (thisStep > 1 || thisStep == lastStep) {\n" +
35+
" var totalTimeElapsed = Date.now() - startTime;\n" +
3236
" var prevStepTimeElapsed = Date.now() - (startTime + stepStartTime);\n" +
3337
" console.log('Step ' + prevStep + ': ' + prevMsg + ' FINISHED. It took ' + prevStepTimeElapsed + 'ms to complete.');\n" +
3438
" $util.insights.set('Step ' + prevStep + ': ' + prevMsg, prevStepTimeElapsed);\n" +
39+
" if (ScriptTimeout > 0 && totalTimeElapsed > ScriptTimeout) {\n" +
40+
" throw new Error('Script timed out. ' + totalTimeElapsed + 'ms is longer than script timeout threshold of ' + ScriptTimeout + 'ms.');\n" +
41+
" }\n" +
3542
" }\n" +
3643
" if (thisStep > 0 && thisStep != lastStep) {\n" +
3744
" stepStartTime = Date.now() - startTime;\n" +
@@ -69,7 +76,6 @@ builder.selenium2.io.addLangFormatter({
6976
" log(lastStep, '');\n" +
7077
" console.log('Browser script execution SUCCEEDED.');\n" +
7178
"}, function(err) {\n" +
72-
" log(lastStep, '');\n" +
7379
" console.log ('Browser script execution FAILED.');\n" +
7480
" throw(err);\n" +
7581
"});\n\n" +

0 commit comments

Comments
 (0)