Forum Discussion

kakabubu's avatar
kakabubu
Contributor
6 years ago

onTimeout breaks onLogError activities

I have onTimeout and onLogError even handlers overwritten

Spoiler

here is my implementation of the event handlers

const isTest = () => !!Project.TestItems.Current;

function GeneralEvents_OnLogError(Sender, LogParams) { if (!isTest() || testIsStoping || LogParams.Priority === pmLowest) return true; testIsStoping = true; Log.Error(LogParams.MessageText, LogParams.AdditionalText, pmLowest); logs.indentLog('Stop test on Error and reset test environment.'); afterFailedTest(); logs.outdentLog(); logs.post(ProjectSuite.Variables.config.postLogsOnError); LogParams.Locked = true; return Runner.Stop(true); } function GeneralEvents_OnTimeout(Sender, LogParams) { return testIsStoping ? true : GeneralEvents_OnLogError(...arguments); }

function afterFailedTest() {
//...
//some actions with application are perfomed here
//...
}

Sometimes the timeout expires while onLogError event handler did not finish. In that case, the following tests are broken because onTimeout event terminates tested application while some important actions are running.

From the articles I've found, (Timeout Property OnTimeout Event Stopping Tests on Timeout) I've picked the following info:

  • The app is terminated before the event handler called
  • Project.TestItems.Current.TimeOut is readOnly

Please help me to understand what is the right way to handle this case.

 

cunderw, i believe you could have similar problems.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I don't think, honestly, that it's a good practice to explicitly call a handler routine inside another handler.  Each handler needs to handle it's event.  

    • Marsha_R's avatar
      Marsha_R
      Moderator

      I agree with tristaanogre 

       

      It's caused two problems doing it this way, because now we can't tell which handler is doing what.

       

       

    • kakabubu's avatar
      kakabubu
      Contributor

      tristaanogreMarsha_R 
      Ok. I can refactor my code in a way not to call the event handler from the other event handler.


      But my problem is that the onTimeout event terminates the application, while onLogError event is still running the afterTestFail routine
      To be exact, it terminates the application while the application database restore is performed. That causes the database to appear disabled. Which causes the following tests to fail.

      I can adjust the test timeouts. But it seems to be not the best solution, in my opinion.