Test::DB::Shared::mysqld - Replaces (and decorate) Test::mysqld to share the MySQL instance between your tests
If in your test you use Test::mysqld, this acts as a replacement for Test::mysqld:
my $mysqld = Test::DB::Shared::mysqld->new( test_namespace => 'myapp', # Then it's plain Test::mysqld config my_cnf => { 'skip-networking' => '', # no TCP socket } ); # and use like Test::mysqld: my $dbh = DBI->connect( $mysqld->dsn(), undef, '' );
And that's it. No special code to write, no restructuring of your tests, and using as a prove plugin is optional.
What you need is a test database, not a test mysqld instance.
See synopsis for the change to your test code. For the rest, you need to use prove -j number to benefit from it.
prove -j number
If not all your test use the test db, best results will be obtained by using prove -s -j number
prove -s -j number
To speed things even further, you can use that as a prove plugin, with an optional config file:
prove -PTest::DB::Shared::mysqld
Or
prove -PTest::DB::Shared::mysqld=./testmysqld.json
The ./testmysqld.json file can contain the arguments to Test::DB::Shared::mysqld in a json format (see SYNOPSIS). They will be used to build one instance for the whole test suite.
If no such file is given, the default configuration is the one specified in the SYNOPSIS, but with a randomly generated test_namespace.
Note that using this plugin will result in all your Test::DB::Shared::mysqld instances in your t/ files using the same configuration, regardless of what configuration you give in this or this test.
Do NOT use that if your test involves doing anything outside a test database. Tests that manage databases will probably break this.
Not all mysqld methods are available. Calls like 'start', 'stop', 'setup', 'read_log' .. are not implemented.
The first time this is used, it will create a Test::mysqld instance in the current process. Then concurrent processes that use the same module (with the same parameters) will be given a new Database in this already running instance, instead of a new MySQL instance.
When this goes out of scope, the test database is destroy, and the last process to destroy the last database will tear down the MySQL instance.
There are probably some. To diagnose them, you can run your test in verbose mode ( prove -v ). If that doesn't help, you can 'use Log::Any::Adapter qw/Stderr/' at the top of your test to get some very verbose tracing.
If you SIGKILL your whole test suite, bad things will happen. Running in verbose mode will most probably tell you which files you should clean up on your filesystem to get back to a working state.
App::Prove plugin implementation. Do NOT use that yourself.
Returns the dsn to connect to the test database. Note that the user is root and the password is the empty string.
See Test::mysqld
To install Test::DB::Shared, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::DB::Shared
CPAN shell
perl -MCPAN -e shell install Test::DB::Shared
For more information on module installation, please visit the detailed CPAN module installation guide.