The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::DB::Shared::mysqld - Replaces (and decorate) Test::mysqld to share the MySQL instance between your tests

SYNOPSIS

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.

STATEMENT

What you need is a test database, not a test mysqld instance.

HOW TO USE IT

See synopsis for the change to your test code. For the rest, you need to use prove -j number to benefit from it.

If not all your test use the test db, best results will be obtained by using prove -s -j number

Using it as a prove Plugin

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.

LIMITATIONS

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.

WHAT THIS DOES

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.

BUGS, DIAGNOSTICS and TROUBLESHOOTING

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.

METHODS

load

App::Prove plugin implementation. Do NOT use that yourself.

dsn

Returns the dsn to connect to the test database. Note that the user is root and the password is the empty string.

pid

See Test::mysqld