Skip to content

Commit

Permalink
Fix tests related to recent POE::Resource::Events optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaputo committed Jul 24, 2010
1 parent 629ad38 commit cdc090b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
8 changes: 5 additions & 3 deletions lib/POE/Resource/Events.pm
Expand Up @@ -202,13 +202,15 @@ sub _data_ev_refcount_dec {

if (ASSERT_DATA) {
_trap $dest_session unless exists $event_count{$dest_session};
_trap $source_session unless exists $post_count{$source_session};
}

$event_count{$dest_session}--;
$self->_data_ses_refcount_dec($dest_session);

if ($dest_session != $source_session) {
if (ASSERT_DATA) {
_trap $source_session unless exists $post_count{$source_session};
}
$post_count{$source_session}--;
$self->_data_ses_refcount_dec($source_session);
}
Expand Down Expand Up @@ -266,8 +268,8 @@ sub _data_ev_dispatch_due {
}
}

# TODO - Can these two lines be reversed?
# TODO - May avoid entering/removing GC mark entries.
# TODO - Why can't we reverse these two lines?
# TODO - Reversing them could avoid entering and removing GC marks.
$self->_data_ev_refcount_dec($event->[EV_SOURCE], $event->[EV_SESSION]);
$self->_dispatch_event(@$event, $due_time, $id);

Expand Down
44 changes: 25 additions & 19 deletions t/20_resources/00_base/events.pm
Expand Up @@ -2,7 +2,7 @@
use strict;

use lib qw(./mylib ../mylib);
use Test::More tests => 38;
use Test::More tests => 48;

sub POE::Kernel::ASSERT_DEFAULT () { 1 }

Expand Down Expand Up @@ -45,11 +45,11 @@ $baseline_refcount += 2 if POE::Kernel::TRACE_STATISTICS; # stat poll event
"first user created event has correct ID"
);

# Kernel should therefore have two events due. A nonexistent
# session should have zero.
# Kernel should therefore have one events due.
# A nonexistent session should have zero.

is(
$poe_kernel->_data_ev_get_count_from($poe_kernel), $baseline_event + 1,
$poe_kernel->_data_ev_get_count_from($poe_kernel), $baseline_event,
"POE::Kernel has enqueued correct number of events"
);

Expand All @@ -68,11 +68,10 @@ $baseline_refcount += 2 if POE::Kernel::TRACE_STATISTICS; # stat poll event
"unknown session has no events enqueued for it"
);

# Performance timer (x2), session, and from/to for the event we
# enqueued.
# Performance timer only counts once now.

is(
$poe_kernel->_data_ses_refcount($poe_kernel), $baseline_refcount + 2,
$poe_kernel->_data_ses_refcount($poe_kernel), $baseline_refcount + 1,
"POE::Kernel's timer count is correct"
);
}
Expand All @@ -81,7 +80,7 @@ $baseline_refcount += 2 if POE::Kernel::TRACE_STATISTICS; # stat poll event

$poe_kernel->_data_ev_dispatch_due();
check_references(
$poe_kernel, 0, "after due events are dispatched"
$poe_kernel, 0, 0, 0, "after due events are dispatched"
);
}

Expand Down Expand Up @@ -116,7 +115,7 @@ for (1..4) {
# The from and to counts should add up to the reference count.

check_references(
$poe_kernel, 0, "after some timers are enqueued"
$poe_kernel, 0, 0, 4, "after some timers are enqueued"
);

{ # Remove one of the alarms by its ID.
Expand All @@ -132,7 +131,7 @@ check_references(
);

check_references(
$poe_kernel, 0, "after a single named event is removed"
$poe_kernel, 0, 0, 3, "after a single named event is removed"
);
}

Expand All @@ -145,7 +144,7 @@ check_references(

ok(!defined($time), "can't clear bogus alarm by nonexistent ID");
check_references(
$poe_kernel, 0, "after trying to clear a bogus alarm"
$poe_kernel, 0, 0, 3, "after trying to clear a bogus alarm"
);
}

Expand All @@ -154,7 +153,7 @@ check_references(

$poe_kernel->_data_ev_clear_alarm_by_name(BOGUS_SESSION, "timer");
check_references(
$poe_kernel, 0, "after removing timers from a bogus session"
$poe_kernel, 0, 0, 3, "after removing timers from a bogus session"
);

is(
Expand All @@ -172,7 +171,7 @@ is(

$poe_kernel->_data_ev_clear_alarm_by_name($poe_kernel, "timer");
check_references(
$poe_kernel, 0, "after removing 'timer' by name"
$poe_kernel, 0, 0, 1, "after removing 'timer' by name"
);

{ # Try to remove timers from some other (nonexistent should be ok)
Expand All @@ -195,7 +194,7 @@ check_references(
is($removed_time, 4, "last alarm had the corrent due time");

check_references(
$poe_kernel, 0, "after clearing all alarms for a session"
$poe_kernel, 0, 0, 0, "after clearing all alarms for a session"
);
}

Expand Down Expand Up @@ -259,19 +258,19 @@ $poe_kernel->_data_ev_clear_session($poe_kernel);
);

check_references(
$poe_kernel, 1, "after creating inter-session messages"
$poe_kernel, 1, 1, 1, "after creating inter-session messages"
);

$poe_kernel->_data_ev_clear_session($session);

check_references(
$poe_kernel, 1, "after clearing inter-session messages"
$poe_kernel, 1, 0, 0, "after clearing inter-session messages"
);

$poe_kernel->_data_ev_clear_session($poe_kernel);

check_references(
$poe_kernel, 1, "after clearing kernel messages"
$poe_kernel, 1, 0, 0, "after clearing kernel messages"
);
}

Expand All @@ -295,15 +294,22 @@ ok(
# later tests, they're from the addition of another session.

sub check_references {
my ($session, $base_ref, $when) = @_;
my ($session, $base_ref, $expected_from, $expected_to, $when) = @_;

my $ref_count = $poe_kernel->_data_ses_refcount($session);
my $from_count = $poe_kernel->_data_ev_get_count_from($session);
my $to_count = $poe_kernel->_data_ev_get_count_to($session);
my $check_sum = $from_count + $to_count + $base_ref;

is($check_sum, $ref_count, "refcnts $ref_count == $check_sum $when");
is($from_count, $to_count, "evcount $from_count == $to_count $when");
is(
$from_count, $expected_from,
"from evcount $from_count == $expected_from $when"
);
is(
$to_count, $expected_to,
"to evcount $to_count == $expected_to $when"
);
}

# We created a session, so run it.
Expand Down

0 comments on commit cdc090b

Please sign in to comment.