Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some some "subscription" event callback #22

Open
basiliscos opened this issue Oct 19, 2013 · 0 comments
Open

Some some "subscription" event callback #22

basiliscos opened this issue Oct 19, 2013 · 0 comments

Comments

@basiliscos
Copy link

It is needed to have such an notification, when the subscription succeeds, and only then publish events (to be caught by subscriber).

The following test demonstrates the issue:

use strict;
use AnyEvent;
use Test::More;
use t::Redis;

test_redis {
    my $sub = shift;
    my $port = shift;

    my $info = $sub->info->recv;
    if($info->{redis_version} lt "1.3.10") {
      plan skip_all => "No PUBLISH/SUBSCRIBE support in this Redis version";
    }

    my $sub = AnyEvent::Redis->new(host => "127.0.0.1", port => $port);
    # umcomment the following to let the test pass
    # $sub->ping->recv;
    my $pub = AnyEvent::Redis->new(host => "127.0.0.1", port => $port);

    my $cv = AnyEvent->condvar;
    $sub->subscribe("test", sub {
            my($message, $chan) = @_;
            $cv->send(1);
        });
    $pub->publish("test", "test")->recv;
    my $guard = AnyEvent->timer(after => 5, cb => sub { $cv->send(0); });

    ok $cv->recv, "got published message";

    done_testing;
};

The test passed and fails time-to-time. If ping will be uncommented it will always succeed. But pingin isn't elegant solution.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant