Modules

  • ABCDE
  • FGHIL
  • MNOPS
  • TUX

Tools

TAP::Parser::Scheduler

Perl 5 version 26.0 documentation
Recently read

TAP::Parser::Scheduler

NAME

TAP::Parser::Scheduler - Schedule tests during parallel testing

VERSION

Version 3.38

SYNOPSIS

  1. use TAP::Parser::Scheduler;

DESCRIPTION

METHODS

Class Methods

new

  1. my $sched = TAP::Parser::Scheduler->new(tests => \@tests);
  2. my $sched = TAP::Parser::Scheduler->new(
  3. tests => [ ['t/test_name.t','Test Description'], ... ],
  4. rules => \%rules,
  5. );

Given 'tests' and optional 'rules' as input, returns a new TAP::Parser::Scheduler object. Each member of @tests should be either a a test file name, or a two element arrayref, where the first element is a test file name, and the second element is a test description. By default, we'll use the test name as the description.

The optional rules attribute provides direction on which tests should be run in parallel and which should be run sequentially. If no rule data structure is provided, a default data structure is used which makes every test eligible to be run in parallel:

  1. { par => '**' },

The rules data structure is documented more in the next section.

Rules data structure

The "rules " data structure is the the heart of the scheduler. It allows you to express simple rules like "run all tests in sequence" or "run all tests in parallel except these five tests.". However, the rules structure also supports glob-style pattern matching and recursive definitions, so you can also express arbitarily complicated patterns.

The rule must only have one top level key: either 'par' for "parallel" or 'seq' for "sequence".

Values must be either strings with possible glob-style matching, or arrayrefs of strings or hashrefs which follow this pattern recursively.

Every element in an arrayref directly below a 'par' key is eligible to be run in parallel, while vavalues directly below a 'seq' key must be run in sequence.

Rules examples

Here are some examples:

  1. # All tests be run in parallel (the default rule)
  2. { par => '**' },
  3. # Run all tests in sequence, except those starting with "p"
  4. { par => 't/p*.t' },
  5. # Run all tests in parallel, except those starting with "p"
  6. {
  7. seq => [
  8. { seq => 't/p*.t' },
  9. { par => '**' },
  10. ],
  11. }
  12. # Run some startup tests in sequence, then some parallel tests than some
  13. # teardown tests in sequence.
  14. {
  15. seq => [
  16. { seq => 't/startup/*.t' },
  17. { par => ['t/a/*.t','t/b/*.t','t/c/*.t'], }
  18. { seq => 't/shutdown/*.t' },
  19. ],
  20. },

Rules resolution

  • By default, all tests are eligible to be run in parallel. Specifying any of your own rules removes this one.
  • "First match wins". The first rule that matches a test will be the one that applies.
  • Any test which does not match a rule will be run in sequence at the end of the run.
  • The existence of a rule does not imply selecting a test. You must still specify the tests to run.
  • Specifying a rule to allow tests to run in parallel does not make the run in parallel. You still need specify the number of parallel jobs in your Harness object.

Glob-style pattern matching for rules

We implement our own glob-style pattern matching. Here are the patterns it supports:

  1. ** is any number of characters, including /, within a pathname
  2. * is zero or more characters within a filename/directory name
  3. ? is exactly one character within a filename/directory name
  4. {foo,bar,baz} is any of foo, bar or baz.
  5. \ is an escape character

Instance Methods

get_all

Get a list of all remaining tests.

get_job

Return the next available job as TAP::Parser::Scheduler::Job object or undef if none are available. Returns a TAP::Parser::Scheduler::Spinner if the scheduler still has pending jobs but none are available to run right now.

as_string

Return a human readable representation of the scheduling tree. For example:

  1. my @tests = (qw{
  2. t/startup/foo.t
  3. t/shutdown/foo.t
  4. t/a/foo.t t/b/foo.t t/c/foo.t t/d/foo.t
  5. });
  6. my $sched = TAP::Parser::Scheduler->new(
  7. tests => \@tests,
  8. rules => {
  9. seq => [
  10. { seq => 't/startup/*.t' },
  11. { par => ['t/a/*.t','t/b/*.t','t/c/*.t'] },
  12. { seq => 't/shutdown/*.t' },
  13. ],
  14. },
  15. );

Produces:

  1. par:
  2. seq:
  3. par:
  4. seq:
  5. par:
  6. seq:
  7. 't/startup/foo.t'
  8. par:
  9. seq:
  10. 't/a/foo.t'
  11. seq:
  12. 't/b/foo.t'
  13. seq:
  14. 't/c/foo.t'
  15. par:
  16. seq:
  17. 't/shutdown/foo.t'
  18. 't/d/foo.t'