1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!./perl -w
#
# Test script to check the memory consumption
# of an Event loop which installs, handles and
# cancels a number of IO watchers (recursively).
#
# For extra diagnostics, Event.pm can be built with
# -DEVENT_MEMORY_DEBUG.
#
# If the script succeeds, the final memory check
# replies something like this:
# "1-29509-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0"
# (all slots except of the first two ones should
# be 0 - the second number may differ).
#
# J. Stenzel (perl@jochen-stenzel.de)
#
use Test; plan test => 2;
use Event;
# $Event::DebugLevel = 3;
sub check {warn "[DBG] ", join('-', Event::_memory_counters), "\n";}
sub iosub {
for (my $l=0; $l<=5; $l++) {
Event->io(
fh => \*STDIO, timeout => "0.5$l",
repeat => 1, cb => \&iosub,
prio => 5);
}
$_[0]->w->cancel;
}
Event->io(fh => \*STDIO, timeout => 0.5, repeat => 1,
cb => \&iosub, prio => 5);
Event->timer(prio => 1, after => 3,
cb => sub {
$_->cancel foreach Event::all_watchers;
ok !defined Event::all_watchers;
}
);
Event::loop();
ok 1;
|