RT 4.0.22
[freeside.git] / rt / t / ticket / race.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 2;
5
6 use constant KIDS => 50;
7
8 my $id;
9
10 {
11     my $t = RT::Ticket->new( RT->SystemUser );
12     ($id) = $t->Create(
13         Queue => "General",
14         Subject => "Race $$",
15     );
16 }
17
18 diag "Created ticket $id";
19 RT->DatabaseHandle->Disconnect;
20
21 my @kids;
22 for (1..KIDS) {
23     if (my $pid = fork()) {
24         push @kids, $pid;
25         next;
26     }
27
28     # In the kid, load up the ticket and correspond
29     RT->ConnectToDatabase;
30     my $t = RT::Ticket->new( RT->SystemUser );
31     $t->Load( $id );
32     $t->Correspond( Content => "Correspondence from PID $$" );
33     undef $t;
34     exit 0;
35 }
36
37
38 diag "Forked @kids";
39 waitpid $_, 0 for @kids;
40 diag "All kids finished corresponding";
41
42 RT->ConnectToDatabase;
43 my $t = RT::Ticket->new( RT->SystemUser );
44 $t->Load($id);
45 my $txns = $t->Transactions;
46 $txns->Limit( FIELD => 'Type', VALUE => 'Status' );
47 is($txns->Count, 1, "Only one transaction change recorded" );
48
49 $txns = $t->Transactions;
50 $txns->Limit( FIELD => 'Type', VALUE => 'Correspond' );
51 is($txns->Count, KIDS, "But all correspondences were recorded" );