Test::Synchronized released

2009-12-09 01:26

Tim Bray wrote on his article Concur.next that:

No longer; Next year’s system will do more computing all right, but by giving you more CPUs, running at this year’s speed, to work with.

Perl’s multi-core support is good old-fashioned fork(2). It’s not sexy, but it works. So recently I began to use “prove -j9″. But some of our project’s tests are not works correctly under the “prove” command.

For example, our cron script has tests that create and remove a log file.

  • foo.t open and create a log file.
  • foo.t write something to the file.
  • foo.t remove the file.
  • bar.t open and create a new log file.
  • bar.t write something to the file.
  • bar.t remove the file.

And it’s not works at the same time.

  • foo.t open and create a log file.
  • bar.t open the log file.
  • foo.t write something to the file.
  • bar.t write something to the file, too.
  • foo.t remove the file.
  • bar.t can’t remove the file.

I can modify the code to fix it. However, I’m lazy and impatient. So I wrote a simple lock system named Test::Synchronized.

Test::Synchronized provides a giant lock to your tests. When you add “use Test::Synchronized;” on both foo.t and bar.t.

  • foo.t create a lock directory.
  • foo.t open and create a log file.
  • bar.t can’t create the lock directory. So bar.t wait the end of foo.t.
  • foo.t write something to the file.
  • foo.t remove the file.
  • foo.t remove the lock directory.
  • bar.t create a new lock directory.
  • bar.t open and create a new log file.

It’s not sexy, but it works :)

I released 0.01 on Bitbucket and CPAN already. Enjoy!

0.02

Tokuhiro-san (aka tokuhirom) blogged about some bugs and problems of Test::Synchronized. So I fixed and released 0.02 now. Thanks a lot.

Leave a Reply