Forum Discussion

Marcky's avatar
Marcky
New Contributor
13 years ago

Make a running test wait for timer tick

Hi,



I was wondering if it was possible to make the test wait for a timer to trigger it's assigned function. (wait for the tick event)



What I want to do is simply call the same function over and over for every X minutes because I need to test something overnight. My problem is how can I prevent the test from stopping when there's no more line of code("actions") to be executed?



Quick example in jscript (script name is MainTestFunctionScript) :



var myTimer;



function MainTestFunctionScript(){



      //Setup my new timer

      myTimer= Utils.Timers.Add(5000, "MainTestFunctionScript.DoWhatIWant", false);

      myTimer.Name = "NotificationTimer";

      myTimer.Enabled = true;



     //I dont want the test to stop here, I want it to wait for the next timer tick (kind of an infinite timed loop)

    //Or is there a way to pause the test for an amount of time? Something like ->  test.Pause(5 minutes);

}



function DoWhatIWant(){

   //do something cool

}





Thanks!



Marc


2 Replies

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi Marc,



    Not sure that I got you absolutely correctly, but:



    a) Why not do just something like this:

    while true do

      DoWhatIWant();



    b) If for some reason you need to use timer, than add an empty infinite loop at the end of your MainTestFunctionScript() and handle a flag signalling that your code triggered by timer is running (unless you created it to be re-enterable). Something like this:



    var myTimer;

    var boolInTimer;



    function MainTestFunctionScript(){



          boolInTimer = false;



          //Setup my new timer

          myTimer= Utils.Timers.Add(5000, "MainTestFunctionScript.DoWhatIWant", false);

          myTimer.Name = "NotificationTimer";

          myTimer.Enabled = true;



          while true

              aqUtils.Delay(500);

    }



    function DoWhatIWant(){

        if (boolInTimer)

          return;



        boolInTimer = true;



        //do something cool



        boolInTimer = false;

    }
  • Marcky's avatar
    Marcky
    New Contributor
    Sorry I made it look more complicated then it really was! You solved my question with « aqUtils.Delay() » !



    Thanks alot!