-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make tests work under concurrent prove
- Loading branch information
Showing
9 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,4 @@ t2/non_perl/test.binary | |
t2_lib | ||
test-logs/ | ||
xxx | ||
.immiscible-test.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package Test2::Plugin::Immiscible; | ||
use strict; | ||
use warnings; | ||
|
||
use Test2::API qw/context/; | ||
|
||
our $VERSION = '2.000000'; | ||
|
||
our $LOCK; | ||
|
||
sub import { | ||
my $class = shift; | ||
my ($skip_cb) = @_; | ||
|
||
my $ctx = context(); | ||
|
||
if ($skip_cb && $skip_cb->()) { | ||
$ctx->note("Immiscibility enforcement skipped due to callback."); | ||
} | ||
else { | ||
if (-w '.') { | ||
if (open($LOCK, '>>', './.immiscible-test.lock')) { | ||
require Fcntl; | ||
if (flock($LOCK, Fcntl::LOCK_EX)) { | ||
$ctx->note("Immiscibility enforcement success."); | ||
} | ||
else { | ||
$ctx->plan(0, SKIP => "could not get lock '$!', cannot guarentee immiscibility."); | ||
} | ||
} | ||
else { | ||
$ctx->plan(0, SKIP => "could not get lock '$!', cannot guarentee immiscibility."); | ||
} | ||
} | ||
else { | ||
$ctx->plan(0, SKIP => "'.' is not writable, cannot guarentee immiscibility."); | ||
} | ||
} | ||
|
||
$ctx->release; | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=pod | ||
=encoding UTF-8 | ||
=head1 NAME | ||
Test2::Plugin::Immiscible - Prevent tests with this module from running | ||
together in the same test suite. | ||
=head1 DESCRIPTION | ||
Prevent any 2 tests with this module loaded from running together in the same | ||
repo. | ||
=head1 SYNOPSIS | ||
use Test2::Plugin::Immiscible; | ||
or | ||
Test2::Plugin::Immiscible(sub { $ENV{SKIP_IMMISCIBILITY_CHECK } ? 1 : 0 ); | ||
The second form allows you to skip the protection if certain conditions are | ||
met. The callback sub should return true if the protection should be skipped. | ||
=over 4 | ||
=back | ||
=head1 SOURCE | ||
The source code repository for Test2-Harness can be found at | ||
L<http://github.com/Test-More/Test2-Harness/>. | ||
=head1 MAINTAINERS | ||
=over 4 | ||
=item Chad Granum E<lt>exodist@cpan.orgE<gt> | ||
=back | ||
=head1 AUTHORS | ||
=over 4 | ||
=item Chad Granum E<lt>exodist@cpan.orgE<gt> | ||
=back | ||
=head1 COPYRIGHT | ||
Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the same terms as Perl itself. | ||
See L<http://dev.perl.org/licenses/> | ||
=cut | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package Test2::Plugin::IsolateTemp; | ||
use strict; | ||
use warnings; | ||
|
||
our $VERSION = '2.000000'; | ||
|
||
use Test2::Harness::Util qw/chmod_tmp/; | ||
use File::Temp qw/tempdir/; | ||
|
||
our $tempdir; | ||
|
||
if ($ENV{TEST2_HARNESS_ACTIVE}) { | ||
# Nothing currently | ||
} | ||
else { | ||
my $template = join '-' => ("T2ISO", $$, "XXXX"); | ||
|
||
$tempdir = tempdir( | ||
$template, | ||
TMPDIR => 1, | ||
CLEANUP => 1, | ||
); | ||
|
||
chmod_tmp($tempdir); | ||
|
||
$ENV{TMPDIR} = $tempdir; | ||
$ENV{TEMPDIR} = $tempdir; | ||
$ENV{TMP_DIR} = $tempdir; | ||
$ENV{TEMP_DIR} = $tempdir; | ||
} | ||
|
||
|
||
1; | ||
|
||
__END__ | ||
=pod | ||
=encoding UTF-8 | ||
=head1 NAME | ||
Test2::Plugin::IsolateTemp - Make sure a test uses an isolated temp dir. | ||
=head1 DESCRIPTION | ||
Make sure the test uses an isolated temp dir. | ||
B<NOTE:> This is a no-op when tests are run with yath (L<App::Yath> and | ||
L<Test2::Harness>) as yath will do this by default. | ||
=head1 SYNOPSIS | ||
use Test2::Plugin::IsolateTemp; | ||
=over 4 | ||
=back | ||
=head1 SOURCE | ||
The source code repository for Test2-Harness can be found at | ||
L<http://github.com/Test-More/Test2-Harness/>. | ||
=head1 MAINTAINERS | ||
=over 4 | ||
=item Chad Granum E<lt>exodist@cpan.orgE<gt> | ||
=back | ||
=head1 AUTHORS | ||
=over 4 | ||
=item Chad Granum E<lt>exodist@cpan.orgE<gt> | ||
=back | ||
=head1 COPYRIGHT | ||
Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the same terms as Perl itself. | ||
See L<http://dev.perl.org/licenses/> | ||
=cut | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters