| 1 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Data::Conveyor::App::Test::Stage::Integration; | ||||||||||||||||||||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | $Data::Conveyor::App::Test::Stage::Integration::VERSION = '1.103130'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Test::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use parent 'Data::Conveyor::App::Test::Stage'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | __PACKAGE__->mk_scalar_accessors(qw(dispatcher next_open_stage failed_tests)) | |||||||||||||||||||||||||||
| 15 | ->mk_array_accessors(qw(expect_list)); | ||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use constant runs => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub plan_test { | ||||||||||||||||||||||||||
|
Subroutine
plan_test: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($self, $test, $run) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # For integration tests, the expect block consists of several more expect | ||||||||||||||||||||||||||||
| 22 | # blocks, which are checked while the ticket is processed repeatedly by | ||||||||||||||||||||||||||||
| 23 | # the test dispatcher. | ||||||||||||||||||||||||||||
| 24 | # There's at least one test (we do expect at least an expected stage in | ||||||||||||||||||||||||||||
| 25 | # each expect sub-block). | ||||||||||||||||||||||||||||
| 26 | 0 | my $plan = 0; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | for (grep { !exists $_->{initial_stage} } @{ $test->{expect} || [] }) { | ||||||||||||||||||||||||||
|
Condition0%0/2
$test->{'expect'} || []
MC/DC0%0/1
$test->{'expect'} || []
$test->{'expect'}
Truth table0%0/2
A
A= $test->{'expect'}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # plan_ticket_* needs a hash with an 'expect' key | ||||||||||||||||||||||||||||
| 30 | 0 | my $subexpect = { expect => $_ }; | |||||||||||||||||||||||||||
| 31 | 0 | $plan += | |||||||||||||||||||||||||||
| 32 | $self->plan_ticket_expected_container($subexpect, $run) + | ||||||||||||||||||||||||||||
| 33 | $self->plan_ticket_tx($subexpect) + 1; # stage | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | $plan; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub run_subtest { | ||||||||||||||||||||||||||
|
Subroutine
run_subtest: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # We can create the dispatcher only here, not in init(), because there's | ||||||||||||||||||||||||||||
| 42 | # not storage yet in init(). The storage is created only in the | ||||||||||||||||||||||||||||
| 43 | # superclass's run() method, during Class::Scaffold::App::app_code(). But | ||||||||||||||||||||||||||||
| 44 | # to simulate realistic conditions, we only create the dispatcher object | ||||||||||||||||||||||||||||
| 45 | # once, i.e. it's expected to handle many requests. | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $self->dispatcher( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | $self->delegate->make_obj('ticket_dispatcher_test')->new( | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # storage => $self->storage, | ||||||||||||||||||||||||||||
| 50 | callback => $self | ||||||||||||||||||||||||||||
| 51 | ) | ||||||||||||||||||||||||||||
| 52 | ) unless defined $self->dispatcher; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # For integration tests, the expect block should be an array reference, | ||||||||||||||||||||||||||||
| 55 | # where each element contains the expect block that we check the ticket | ||||||||||||||||||||||||||||
| 56 | # against during each phase of the ticket's life cycle. The check_* | ||||||||||||||||||||||||||||
| 57 | # methods in Data::Conveyor::App::Test::Stage (e.g., | ||||||||||||||||||||||||||||
| 58 | # check_ticket_rc_status()) need to have that single expect block in the | ||||||||||||||||||||||||||||
| 59 | # expect() accessor, however. So we remember the list of expect blocks in | ||||||||||||||||||||||||||||
| 60 | # another accessor, expect_list(). See check_dispatched_ticket() for the | ||||||||||||||||||||||||||||
| 61 | # rest of the story. | ||||||||||||||||||||||||||||
| 62 | 0 | $self->expect_list(@{ $self->expect }); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # Get the first expect element; it should contain the initial stage. We | ||||||||||||||||||||||||||||
| 65 | # need it so we can open() the ticket. Later, after_ticket_finished() will | ||||||||||||||||||||||||||||
| 66 | # update the value so that we always know which stage to open the ticket | ||||||||||||||||||||||||||||
| 67 | # in. | ||||||||||||||||||||||||||||
| 68 | $self->next_open_stage($self->delegate->make_obj('value_ticket_stage') | ||||||||||||||||||||||||||||
| 69 | 0 | ->new(value => $self->expect_list_shift->{initial_stage})->name); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Repeatedly call the dispatcher until we don't have any more expect | ||||||||||||||||||||||||||||
| 72 | # blocks or until a test failed within this run. | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | while ($self->expect_list_count && !$self->failed_tests) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->expect_list_count and not $self->failed_tests
MC/DC0%0/2
$self->expect_list_count and not $self->failed_tests
$self->expect_list_count
not $self->failed_tests
Truth table0%0/3
A and not(B)
A= $self->expect_list_countB= not $self->failed_tests
| |||||||||||||||||||||||||||||
| 74 | 0 | $self->run_stage_test; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub run_stage_test { | ||||||||||||||||||||||||||
|
Subroutine
run_stage_test: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 0 | my $ticket = | |||||||||||||||||||||||||||
| 81 | $self->delegate->make_obj('ticket', ticket_no => $self->ticket_no,); | ||||||||||||||||||||||||||||
| 82 | 0 | $ticket->open($self->next_open_stage); | |||||||||||||||||||||||||||
| 83 | 0 | $self->dispatcher->dispatch($ticket); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # Did any tests already fail within this run? | ||||||||||||||||||||||||||||
| 86 | 0 | $self->failed_tests(grep { !$_->{ok} } Test::Builder->new->details); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub check_ticket_stage { | ||||||||||||||||||||||||||
|
Subroutine
check_ticket_stage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | is( $self->ticket->stage, $self->expect->{stage}, | ||||||||||||||||||||||||||||
| 92 | sprintf 'stage %s', $self->expect->{stage} | ||||||||||||||||||||||||||||
| 93 | 0 | ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub check_dispatched_ticket { | ||||||||||||||||||||||||||
|
Subroutine
check_dispatched_ticket: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # Get the next expect block from the expect block list and set it on the | ||||||||||||||||||||||||||||
| 100 | # expect() accessor so that the check_* methods that follow will know what | ||||||||||||||||||||||||||||
| 101 | # to check against. | ||||||||||||||||||||||||||||
| 102 | # Stop when we don't have any more expect blocks | ||||||||||||||||||||||||||||
| 103 | 0 | my $expect = $self->expect_list_shift; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | return unless defined $expect; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | $self->expect($expect); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Get the ticket from the dispatcher (it's a new object every time around) | ||||||||||||||||||||||||||||
| 108 | # and set it on our ticket() accessor so that the check_* methods that | ||||||||||||||||||||||||||||
| 109 | # follow can do their work. Also set the stage object, needed by | ||||||||||||||||||||||||||||
| 110 | # check_ticket_expected_container(). | ||||||||||||||||||||||||||||
| 111 | 0 | $self->ticket($self->dispatcher->ticket); | |||||||||||||||||||||||||||
| 112 | 0 | $self->stage($self->dispatcher->stage); | |||||||||||||||||||||||||||
| 113 | 0 | $self->check_ticket_stage; | |||||||||||||||||||||||||||
| 114 | 0 | $self->check_ticket_expected_container; | |||||||||||||||||||||||||||
| 115 | 0 | $self->check_ticket_tx; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # Callback methods from test ticket dispatcher; callback was set up | ||||||||||||||||||||||||||||
| 119 | # in this object's init() method. | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub after_ticket_closed { | ||||||||||||||||||||||||||
|
Subroutine
after_ticket_closed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | 0 | note 'ticket closed'; | |||||||||||||||||||||||||||
| 123 | 0 | $self->check_dispatched_ticket; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub after_ticket_finished { | ||||||||||||||||||||||||||
|
Subroutine
after_ticket_finished: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | note 'ticket finished'; | |||||||||||||||||||||||||||
| 129 | 0 | $self->check_dispatched_ticket; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # Remember the stage the ticket should be opened in during the next | ||||||||||||||||||||||||||||
| 132 | # dispatcher run. | ||||||||||||||||||||||||||||
| 133 | $self->next_open_stage($self->delegate->make_obj('value_ticket_stage') | ||||||||||||||||||||||||||||
| 134 | 0 | ->new(value => $self->expect->{stage})->name); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 1 | 1; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||