You are viewing the version of this documentation from Perl 5.41.11. This is a development version of Perl.

CONTENTS

NAME

Test2::AsyncSubtest - Object representing an async subtest.

DESCRIPTION

Regular subtests have a limited scope, they start, events are generated, then they close and send an Test2::Event::Subtest event. This is a problem if you want the subtest to keep receiving events while other events are also being generated. This class implements subtests that stay open until you decide to close them.

This is mainly useful for tools that start a subtest in one process and then spawn children. In many cases it is nice to let the parent process continue instead of waiting on the children.

SYNOPSIS

use Test2::AsyncSubtest;

my $ast = Test2::AsyncSubtest->new(name => foo);

$ast->run(sub {
    ok(1, "Event in parent" );
});

ok(1, "Event outside of subtest");

$ast->run_fork(sub {
    ok(1, "Event in child process");
});

...

$ast->finish;

done_testing;

CONSTRUCTION

my $ast = Test2::AsyncSubtest->new( ... );
name => $name (required)

Name of the subtest. This construction argument is required.

send_to => $hub (optional)

Hub to which the final subtest event should be sent. This must be an instance of Test2::Hub or a subclass. If none is specified then the current top hub will be used.

trace => $trace (optional)

File/Line to which errors should be attributed. This must be an instance of Test2::Util::Trace. If none is specified then the file/line where the constructor was called will be used.

hub => $hub (optional)

Use this to specify a hub the subtest should use. By default a new hub is generated. This must be an instance of Test2::AsyncSubtest::Hub.

METHODS

SIMPLE ACCESSORS

$bool = $ast->active

True if the subtest is active. The subtest is active if its hub appears in the global hub stack. This is true when $ast->run(...) us running.

$arrayref = $ast->children

Get an arrayref of child processes/threads. Numerical items are PIDs, blessed items are threads instances.

$arrayref = $ast->events

Get an arrayref of events that have been sent to the subtests hub.

$bool = $ast->finished

True if finished() has already been called.

$hub = $ast->hub

The hub created for the subtest.