Skip to main content
  1. Entry/

Test::mysqldを永続化しつつメモリ上で動かす

NUMSECTORS=128000 mydev=hdid -nomount ram://</span><span class="synPreProc">$NUMSECTORS</span><span class="synSpecial"> newfs_hfs $mydev mkdir /tmp/mnt mount -t hfs $mydev /tmp/mnt ~/bin に置いて

my $tempfile = File::Spec->catfile(File::Spec->tmpdir, ‘test_mysqld.json’);

$SIG{‘INT’} = *purge; END { purge(); }

print "Starting mysqld…"; my $mysqld = setup_database; my $log = File::Spec->catfile($mysqld->{‘base_dir’}, qw/tmp mysqld.log/); printf " started at %s\n", $mysqld->{‘my_cnf’}{‘socket’}; print "log file: $log\n";

{ my $json = encode_json({ %$mysqld }); open my $fh, ’>’, $tempfile or die $!; $fh->print($json); $fh->close; }

sleep 3 while -e $tempfile;

sub purge { unlink $tempfile; print "Shutting down mysqld…\n"; exit; } 適当な場所に置いて実行。TMPDIRはいじらなくていい。

if [ ! -e /tmp/mnt ] ; then echo no tmp disk "/tmp/mnt"’; exit; fi

</span><span class="synIdentifier">TMPDIR</span>=<span class="synSpecial">/tmp/mnt prove </span><span class="synPreProc">$@</span><span class="synSpecial"> いちおうディスクがなければ中断するように。 テストを走らせるときはこんな感じで。