use strict; use warnings; use Test::More tests => 1 + (5 * 8); use File::Path; use MediaLib; use POSIX ":sys_wait_h"; BEGIN { rmtree('t/var'); mkdir('t/var'); } my $root_path = '/Users/blblack/muzak'; my $db_path = 't/var'; my $schema_def = 't/ts/simple'; my $schema_obj = eval { MediaLib->library_init( root_path => $root_path, db_path => $db_path, schema_def => $schema_def, load_scan_code => 1, ); }; ok(!$@) or diag $@; # 8 tests in loop my $iter = 1; foreach my $force_full ((0, 0, 0, 1, 0)) { ok(-f "${db_path}/db") or diag "No database file at ${db_path}/db ($)"; ok(-f "${db_path}/schema") or diag "No schema file at ${db_path}/schema ($iter)"; eval { my ($pid, $fh) = $schema_obj->start_async_scan($force_full); while(<$fh>) { diag "Async Progress: " . $_; } my $wait = 5; while(waitpid($pid, WNOHANG) && kill(0, $pid) && --$wait) { diag "Waiting for PID $pid to exit..."; sleep(1); } }; ok(!$@) or diag $@; ok(-f "${db_path}/dbnew") or diag "No new database file at ${db_path}/dbnew ($iter)"; ok(-f "${db_path}/scanned") or diag "No new scan stamp file at ${db_path}/scanned ($iter)"; eval { $schema_obj->reload() }; ok(!$@) or diag $@; ok(! -f "${db_path}/dbnew") or diag "New database file ${db_path}/dbnew did not dissappear ($iter)"; ok(-f "${db_path}/db") or diag "No database file at ${db_path}/db (after scan/reload) ($iter)"; $iter++; sleep(2); # make sure the one-second scanned timestamp can advance on the tiny test lib } END { rmtree('t/var') }