4

How to set setTimeout/Thread.sleep in newman(postman's node module).

I am using below function :

setTimeout(function(){ 

        console.log('sleep for ten min');
    }, 600000);

Above function works perfectly in collection runner of postman.

But when I tried newman it is throwing error as

'setTimeout is not available inside sandbox and has no side-effect.'

I have found a similar thread like below:

https://github.com/postmanlabs/newman/issues/304

But they also haven't provided any solution.

Is there anyway by which I can mark my single API to delay for a time period.

I am already using Newman parameter --delay-request 60000 which delay between API's so it won't work for it.

enter image description here

Any solution will be helpful

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125

2 Answers2

4

Update newman to 3.8.3 or later.

The older version of newman is not supporting setTimeout

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
3

So opening the link you've given to us they say :

enter image description here


So to be clear, you are going to use newman a way it's not designed for.


This being said, you can try to implement a custom sleep :

function sleep(milisecond) {
  const date = Date.now();

  // Sleep in an *infinite* loop
  while ((date + milisecond) > Date.now());
}
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
  • 1
    Thanks @Gregory .. I have tried that too earlier .. I found the solution .. testing it .. will post once confirm.. vote you up for help ;) – Shubham Jain Dec 01 '17 at 12:41