mercredi 3 juin 2015

Testing what happned inside an infinite loop

I have a service which has a method that runs forever, in a while loop.

The method is called Run.

I would like to test this method, Run, for a period of time. That's because within that method, something else is happing that I need to assert in my test.

I have thought about spinning up a new thread and calling the metod on that, but I am not sure if that's the best approach. And can I have a thread that exits in a certain number of seconds ?

Right now I simply call it like this, but the Run() never returns since it's an infinite loop :)

...
WorkerRole wr = new WorkerRole();
wr.OnStart();
wr.Run();

//Assert on something that happened inside Run

Any help much appreciated.

Aucun commentaire:

Enregistrer un commentaire