Skip to content

Commit a1be08c

Browse files
committed
Add test
1 parent 22b6793 commit a1be08c

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

t/60-fork.t

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use strict;
2+
use warnings;
3+
use lib 't/lib';
4+
5+
$Data::ObjectDriver::DEBUG = 0;
6+
use Test::More;
7+
use DodTestUtil;
8+
9+
BEGIN {
10+
my @requires = qw(
11+
Parallel::ForkManager
12+
Test::SharedFork
13+
);
14+
15+
for my $module (@requires) {
16+
eval "require $module" or plan skip_all => "requires $module";
17+
}
18+
DodTestUtil->check_driver;
19+
}
20+
21+
setup_dbs({
22+
global => [ qw( wines ) ],
23+
});
24+
25+
use Wine;
26+
27+
my $wine = Wine->new;
28+
$wine->name("Latour");
29+
ok($wine->save, 'Object saved successfully');
30+
31+
my $wine_id = $wine->id;
32+
undef $wine;
33+
$wine = Wine->lookup($wine_id);
34+
35+
ok $wine;
36+
37+
my $max = $ENV{DOD_TEST_MAX_FORK} || 10;
38+
my $pm = Parallel::ForkManager->new( $ENV{DOD_TEST_WORKERS} || 4 );
39+
$pm->run_on_finish(sub {
40+
my ($pid, $exit, $ident) = @_;
41+
ok !$exit, "pid $pid exits $exit";
42+
});
43+
$pm->run_on_start(sub {
44+
my ($pid, $ident) = @_;
45+
note "pid $pid starts";
46+
});
47+
for my $id ( 1 .. $max ) {
48+
my $pid = $pm->start and next;
49+
my $new_wine = Wine->new;
50+
$new_wine->name("Wine $id");
51+
$new_wine->begin_work;
52+
ok $new_wine->save, "saved wine $id";
53+
$new_wine->commit;
54+
55+
my ($result) = Wine->result({name => 'Latour'});
56+
ok !$result->is_finished, "not yet finished";
57+
ok my $latour = $result->next, "next";
58+
is $latour->name => 'Latour', "found Latour";
59+
ok !$result->next, "no more next";
60+
ok $result->is_finished, "finished";
61+
62+
$pm->finish;
63+
}
64+
65+
$pm->wait_all_children;
66+
67+
pass("waited all children");
68+
69+
my $result = Wine->result({});
70+
my %seen;
71+
while( my $wine = $result->next ) {
72+
$seen{$wine->name} = 1;
73+
}
74+
75+
ok $seen{Latour}, "seen Latour";
76+
ok $seen{"Wine $_"}, "seen Wine $_" for 1 .. $max;
77+
78+
done_testing;
79+
80+
teardown_dbs('global');

0 commit comments

Comments
 (0)