4

I'm working on a Perl project written asynchronously using AnyEvent. During testing, I had a situation where a bug in my code caused blocked code to be called after my test had completed so the test looked like it passed, but the blocked call ended up polluting other tests later on.

What I'd like to have happen is in the teardown for the test, verify that AnyEvent isn't waiting on any other blocked calls. Is this possible to check AnyEvent if it has any calls that haven't yet been executed?

RobEarl
  • 7,862
  • 6
  • 35
  • 50
tbischel
  • 6,337
  • 11
  • 51
  • 73
  • Afaik the queue is depending on which event loop implementation, you are using. Try taking a look at the pure perl implementation named ```AnyEvent::Loop```, especially the variables ```@timer``` and ```@idle``` (look in the source). – mzedeler Jul 05 '12 at 17:18

3 Answers3

2

My first answer was deleted because the question was changed after I answered. This is rather frustrating, so if you want to get answers, you really shouldn't change your questions like this but instead amend them, so the context stays clear.

Anyways, as for your new question, AnyEvent itself doesn't have an event queue, so you cannot view it. While some of the underlying event libraries have an event queue, some don't, and none of them export their event queue publicly.

What's worse, it wouldn't even help, as the event might not yet be in the queue, even though it happened (for example, a timer could elapse while you are processing some event, so it wouldn't be in the event queue, but it would still more or less immediately trigger).

Lastly, AnyEvent (being event based) never waits for blocked calls.

Remember Monica
  • 3,897
  • 1
  • 24
  • 31
0

Use AnyEvent::Debug to wrap your watchers and listen on a socket for commands, including 'wl' to list all watchers, which would get you some way to what you need.

You can get, for example, the watcher list with a call to AnyEvent::Debug::shell::wl function in your code which you can then iterate through and inspect with AnyEvent::Debug::Wrapped methods.

MkV
  • 3,046
  • 22
  • 16
-1

Your question has no direct answer but I'd like to suggest two things that may help

  • use AnyEvent::Log to make sure you know where your async branching happens, it will also help you to find things you created that are not getting destroyed

  • run your test routine in a sub-process, watching over it with AnyEvent->child and making sure it quit before you move on further

Also try to see where you are loosing control over created conditional variables and/or IO handles, they are better to be available for you to destruct, it'll make testing much easier.

alexsergeyev
  • 525
  • 2
  • 7