Giter Club home page Giter Club logo

test-redisserver's Introduction

Actions Status

NAME

Test::RedisServer - redis-server runner for tests.

SYNOPSIS

use Redis;
use Test::RedisServer;
use Test::More;

my $redis_server;
eval {
    $redis_server = Test::RedisServer->new;
} or plan skip_all => 'redis-server is required for this test';

my $redis = Redis->new( $redis_server->connect_info );

is $redis->ping, 'PONG', 'ping pong ok';

done_testing;

DESCRIPTION

METHODS

new(%options)

my $redis_server = Test::RedisServer->new(%options);

Create a new redis-server instance, and start it by default (use auto_start option to avoid this)

Available options are:

  • auto_start => 0 | 1 (Default: 1)

    Automatically start redis-server instance (by default). You can disable this feature by auto_start => 0, and start instance manually by start or exec method below.

  • conf => 'HashRef'

    This is a redis.conf key value pair. You can use any key-value pair(s) that redis-server supports.

    If you want to use this redis.conf:

    port 9999
    databases 16
    save 900 1
    

    Your conf parameter will be:

    Test::RedisServer->new( conf => {
        port      => 9999,
        databases => 16,
        save      => '900 1',
    });
  • timeout => 'Int'

    Timeout seconds for detecting if redis-server is awake or not. (Default: 3)

  • tmpdir => 'String'

    Temporal directory, where redis config will be stored. By default it is created for you, but if you start Test::RedisServer via exec (e.g. with Test::TCP), you should provide it to be automatically deleted:

start

Start redis-server instance manually.

exec

Just exec to redis-server instance. This method is useful to use this module with Test::TCP, Proclet or etc.

use File::Temp;
use Test::TCP;
my $tmp_dir = File::Temp->newdir( CLEANUP => 1 );

test_tcp(
    client => sub {
        my ($port, $server_pid) = @_;
        ...
    },
    server => sub {
        my ($port) = @_;
        my $redis = Test::RedisServer->new(
            auto_start => 0,
            conf       => { port => $port },
            tmpdir     => $tmp_dir,
        );
        $redis->exec;
    },
);

stop

Stop redis-server instance.

This method is automatically called from object destructor, DESTROY.

connect_info

Return connection info for client library to connect this redis-server instance.

This parameter is designed to pass directly to Redis module.

my $redis_server = Test::RedisServer->new;
my $redis = Redis->new( $redis_server->connect_info );

pid

Return redis-server instance's process id, or undef when redis-server is not running.

wait_exit

Block until redis instance exited.

SEE ALSO

Test::mysqld for mysqld.

Test::Memcached for Memcached.

This module steals lots of stuff from above modules.

Test::Mock::Redis, another approach for testing redis application.

INTERNAL METHODS

BUILD

DEMOLISH

AUTHOR

Daisuke Murase [email protected]

COPYRIGHT AND LICENSE

Copyright (c) 2012 KAYAC Inc. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

test-redisserver's People

Contributors

typester avatar songmu avatar davidcantrell-bb avatar dthadi3 avatar robinsmidsrod avatar gregoa avatar

Stargazers

Boyd Duffee avatar Thibault Duponchelle avatar Ivan Baidakou avatar OKAMURA Naoki aka nyarla / kalaclista avatar karupanerura avatar Sim Gamboa avatar Jeremy Zawodny avatar  avatar  avatar

Watchers

 avatar Jeremy Zawodny avatar  avatar James Cloos avatar Shah Shohag avatar

test-redisserver's Issues

Redis 6 on Mac won't halt on SIGTERM if the temp directory has been deleted

If you create a Test::RedisServer object which doesn't get destroyed until global destruction, and use the default setting of having T::RS create a temp dir for you, then, because the order of destruction is not guaranteed, the directory object may get destroyed (triggering deletion of the directory) before T::RS sends the SIGTERM signal to redis-server.

Redis-server then doesn't stop, because for some reason it seems to want the directory to exist.

I have a work-around in my code, where I supply a temp dir to the constructor, and then call ...->stop in and END block, thus guaranteeing that T::RS stops redis-server while the directory still exists.

I can't think off the top of my head of a better solution which could be applied inside T::RS itself, except perhaps that of sending a SIGKILL instead, but that's a bit icky.

I've only seen this on MacOS, so it may be a platform-specific quirk of Redis - it's definitely a Redis bug at heart and I have also reported it to them: redis/redis#10330

Invalid Assumption in t/tmp_dir.t

I've just seen a test failure in t/tmp_dir.t that I thought I should report.

The test counts the number of files in the temporary directory, starts and stops a Redis server, then counts the files again. It expects both counts to yield the same result.

However, other processes can write to the temporary directory, adding or removing files while the tests run. In this case, the test fails even though the code has behaved as it should.

Failed test 'error msg ok'

On my freebsd 13 smokers the test suite failed --- probably because the error message format changed in newer redis versions:

#   Failed test 'error msg ok'
#   at t/unknown_conf.t line 17.
#                   '*** failed to launch redis-server ***
# 
# *** FATAL CONFIG FILE ERROR (Redis 6.0.10) ***
# Reading the configuration file, at line 3
# >>> 'unknown_key unknown_val'
# Bad directive or wrong number of arguments
#  at t/unknown_conf.t line 11.
# '
#     doesn't match '(?^:\*\*\* FATAL CONFIG FILE ERROR \*\*\*)'
# Looks like you failed 1 test of 2.
t/unknown_conf.t .. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 

If using Test::RedisServer with Redis 4.0.1, server ready state is never detected

With version 4.0.1 of Redis server, the log line used to signify that the server is ready to accept connections is formatted like this: 18565:M 17 Aug 14:28:47.860 * Ready to accept connections

In previous versions the log line was formatted like this: 33:M 17 Aug 14:39:07.985 * The server is now ready to accept connections on port 6379

Please ensure the regexp in the start sub is changed to support both of these syntaxes. I would recommend you match on more generic terms or use a ping query to redis to verify it is operational instead.

This is using version 0.20 of Test::RedisServer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.