File: fork.t

package info (click to toggle)
libnumber-phone-perl 3.6006-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 136,072 kB
  • sloc: perl: 2,719; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use strict;
use warnings;

use Config;

use Test::More;

use Number::Phone::NANP;
use Number::Phone::UK::Data;

use Parallel::ForkManager;
my $forker = Parallel::ForkManager->new(1);
my $returned_from_child;
$forker->run_on_finish(sub { $returned_from_child = ${$_[-1]}; });

# this gets an operator to force a seek() on the filehandle
# so we can compare it to what should be a shiny new fh
Number::Phone->new("+1 242 225 0000")->operator();
my $original_tell = tell(Number::Phone::NANP::_datafh);
$forker->start() || $forker->finish(0, \tell(Number::Phone::NANP::_datafh));
$forker->wait_all_children();
isnt($original_tell, $returned_from_child, "forking gets us a new NANP operators db");

my $original_ukdb = ''.Number::Phone::UK::Data::db;
$forker->start() || $forker->finish(0, \(''.Number::Phone::UK::Data::db));
$forker->wait_all_children();
isnt($original_ukdb, $returned_from_child, "forking gets us a new UK db");

SKIP: {
    if(
        $ENV{CI} || !$ENV{AUTOMATED_TESTING}
    ) {
        skip "slurping is too slow so skipping under CI and for normal installs, set AUTOMATED_TESTING to run this", 1;
    } 
    diag("NB: this test takes a few minutes and lots of memory");
    Number::Phone::UK::Data::slurp();
    my $original_slurped_ukdb = ''.Number::Phone::UK::Data::db;
    $forker->start() || $forker->finish(0, \(''.Number::Phone::UK::Data::db));
    $forker->wait_all_children();
    is($original_slurped_ukdb, $returned_from_child, "forking doesn't get us a new UK db if we slurped");
}

done_testing();