]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/40-threads.t
Test same signature across threads
[perl/modules/Variable-Magic.git] / t / 40-threads.t
index 9e4c11b1a7b97354e87fcccc23e2fa6cd8229f7f..c31986019f76ece988fcf32de577cd4fcda8a3a2 100644 (file)
@@ -3,6 +3,16 @@
 use strict;
 use warnings;
 
+use Config qw/%Config/;
+
+BEGIN {
+ if (!$Config{useithreads}) {
+  require Test::More;
+  Test::More->import;
+  plan(skip_all => 'This perl wasn\'t built to support threads');
+ }
+}
+
 use threads; # Before Test::More
 use threads::shared;
 
@@ -11,20 +21,23 @@ use Test::More;
 use Variable::Magic qw/wizard cast dispell getdata VMG_THREADSAFE/;
 
 if (VMG_THREADSAFE) {
- plan tests => 2 * 16 + 1;
+ plan tests => 2 * (2 * 16 + 1);
 } else {
  plan skip_all => 'This Variable::Magic isn\'t thread safe';
 }
 
 my $destroyed : shared = 0;
 
+my $sig = undef;
+
 sub try {
  my $tid = threads->tid();
  my $c   = 0;
  my $wiz = eval {
   wizard get  => sub { ++$c },
          data => sub { $_[1] + $tid },
-         free => sub { ++$destroyed };
+         free => sub { ++$destroyed },
+         sig  => $sig;
  };
  is($@,     '',    "wizard in thread $tid doesn't croak");
  isnt($wiz, undef, "wizard in thread $tid is defined");
@@ -58,3 +71,13 @@ $t[0]->join;
 $t[1]->join;
 
 is($destroyed, 0, 'destructors didn\'t fired');
+
+$destroyed = 0;
+$sig = Variable::Magic::gensig();
+
+@t = map { threads->create(\&try) } 1 .. 2;
+$t[0]->join;
+$t[1]->join;
+
+is($destroyed, 0, 'destructors didn\'t fired');
+