From 15a297372dab411df3de4f302f890a77791ca0c2 Mon Sep 17 00:00:00 2001 From: Jared Johnson Date: Mon, 23 Feb 2015 14:32:42 -0600 Subject: [PATCH] Default to one-second connect timeout for Redis --- lib/Qpsmtpd/Plugin.pm | 1 + plugins/greylisting | 3 +++ t/plugin_tests/greylisting | 3 ++- t/qpsmtpd-plugin.t | 8 ++++---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index 379031b..d339696 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -352,6 +352,7 @@ sub db_args { $self->validate_db_args(@_); $self->{db_args} = \%arg if %arg; $self->{db_args}{name} ||= $self->plugin_name; + $self->{db_args}{cnx_timeout} ||= 1; return %{ $self->{db_args} }; } diff --git a/plugins/greylisting b/plugins/greylisting index deaa044..12926a2 100644 --- a/plugins/greylisting +++ b/plugins/greylisting @@ -111,6 +111,9 @@ Location of redis server where the greylisting DB will be stored. Redis can be used as a scalable and clusterable alternative to a simple DBM file. For more information, see http://redis.io +When Redis is in use, this plugin will wait up to 1 second to connect; +when Redis is unavailable, clients will not be greylisted. + =head2 per_recipient Flag to indicate whether to use per-recipient configs. diff --git a/t/plugin_tests/greylisting b/t/plugin_tests/greylisting index e5b93a9..d4b32b5 100644 --- a/t/plugin_tests/greylisting +++ b/t/plugin_tests/greylisting @@ -338,7 +338,8 @@ sub test_init_redis { $self->{_args}{redis} = 'testredis'; $self->init_db; is( keyvals($self->db_args), - 'class=Qpsmtpd::DB::Redis;name=greylist;server=testredis:6379', + 'class=Qpsmtpd::DB::Redis;cnx_timeout=1;' + . 'name=greylist;server=testredis:6379', 'init_redis() sets redis args' ); } diff --git a/t/qpsmtpd-plugin.t b/t/qpsmtpd-plugin.t index 2373c0e..dd08d6f 100644 --- a/t/qpsmtpd-plugin.t +++ b/t/qpsmtpd-plugin.t @@ -27,16 +27,16 @@ sub __validate_db_args { sub __db_args { my $plugin = FakePlugin->new; is( keyvals($plugin->db_args), - 'name=___MockHook___', + 'cnx_timeout=1;name=___MockHook___', 'default db args populated' ); is( keyvals($plugin->db_args( arg1 => 1 )), - 'arg1=1;name=___MockHook___', + 'arg1=1;cnx_timeout=1;name=___MockHook___', 'passed args in addition to defaults' ); is( keyvals($plugin->db_args( name => 'bob', arg2 => 2 )), - 'arg2=2;name=bob', + 'arg2=2;cnx_timeout=1;name=bob', 'passed args override defaults' ); is( keyvals($plugin->db_args), - 'arg2=2;name=bob', + 'arg2=2;cnx_timeout=1;name=bob', 'get previous args' ); }