Thanks David and Ricardo for answering,
I think I didn't explain the issue well enough.
I'm not trying to run my tests in parallel but with some reports that I receive
as FAIL, it seems those tests are being executed by the "same time" with
different versions (probably different Perl interpreters) in the same machine.
Can't guarantee that (maybe I should check with the tester that sent those
reports :-) ) but the reports are always from the same person and roughly
executed at the same moment.
My code creates a lock file in a default directory... it seems it works fine
for the first interpreter that executes the tests, but the next ones will fail.
I think that creating a temporary directory and leaving the lock file inside
there will help in this case... after all, one set of tests running with one
interpreter won't use the same temporary directory as the other. I think I'll
give a try to Test::TempDir::Tiny.
My best regards,Alceu
De: David Golden <[email protected]>
Para: Alceu R. de Freitas Jr. <[email protected]>
Cc: CPAN Testers Discuss <[email protected]>
Enviadas: Quarta-feira, 8 de Julho de 2015 10:46
Assunto: Re: avoid errors from concurrent tests executions
On Wed, Jul 8, 2015 at 9:02 AM, Alceu R. de Freitas Jr.
<[email protected]> wrote:
Did you had such situations in the past and could share your experience with
it? I'm not sure the best approach to avoid those failures. Maybe executing the
tests under eval, inside a while loop and sleeping for a random number of
seconds?
I really didn't understand your description of what's happening in your code,
but here are some general ideas I try to follow:
* Test can be run in parallel (see the -j flag to prove) so you should never
assume that different *.t files won't collide. If you keep that in mind, then
a smoker running your module under two or more different perls at the same time
will also not cause problems.
* Never use the same "temporary" path for testing in different *.t files,
either under /tmp or under the current directly. Always create a unique
temporary directory if you need to write files and write everything under that.
I wrote Test::TempDir::Tiny as a reasonably good way to do that safely even
under concurrent operations.
* Never hard code a port number for server operations. Use Net::EmptyPort
instead. For testing client/server operations, consider Test::TCP if it can
fit your needs.
* If a test file needs to start up some daemon in the background (perhaps
listening on an empty port), it must also shut it down. Consider Proc::Guard
for that.
* Never grep the process table expecting only to find one of something.
* If you really must control which tests are allowed to run in parallel,
require Test::Harness 3.31 or later (or skip the test) and use a rules file.
(Read TAP::Harness docs about rules and see
https://github.com/mongodb/mongo-perl-driver/blob/master/t/testrules.yml and
https://github.com/mongodb/mongo-perl-driver/blob/master/t/max_time_ms.t for
examples.)
Hope that helps,
David
--
David Golden <[email protected]> Twitter/IRC: @xdg