]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/79-uid-threads.t
Port t/79-uid-threads.t to the new threads interface
[perl/modules/Scope-Upper.git] / t / 79-uid-threads.t
index 8fe180deb2e29239de00d8ed5b8a0e2ae9ef53e6..817a144973440f8102f5161a2b7ef93d626ef28f 100644 (file)
@@ -1,18 +1,18 @@
-#!perl -T
+#!perl
 
 use strict;
 use warnings;
 
-use Scope::Upper qw<uid validate_uid UP HERE>;
-
 use lib 't/lib';
 use VPIT::TestHelpers (
- threads => [ 'Scope::Upper' => Scope::Upper::SU_THREADSAFE ],
+ threads => [ 'Scope::Upper' => 'Scope::Upper::SU_THREADSAFE()' ],
  'usleep',
 );
 
 use Test::Leaner;
 
+use Scope::Upper qw<uid validate_uid UP HERE>;
+
 my $top = uid;
 
 sub cb {
@@ -27,7 +27,7 @@ sub cb {
 
  is uid(UP), $top, "uid(UP) == \$top (in thread $tid)";
 
- usleep rand(1e6);
+ usleep rand(2.5e5);
 
  ok validate_uid($here), "\$here is valid (in thread $tid)";
  ok !validate_uid($up),  "\$up is no longer valid (in thread $tid)";
@@ -37,14 +37,16 @@ sub cb {
 
 my %uids;
 my $threads = 0;
-for my $thread (map threads->create(\&cb), 1 .. 30) {
- ++$threads;
+for my $thread (map spawn(\&cb), 1 .. 30) {
  my $tid = $thread->tid;
  my $uid = $thread->join;
- ++$uids{$uid};
- ok !validate_uid($uid), "\$here is no longer valid (out of thread $tid)";
+ if (defined $uid) {
+  ++$threads;
+  ++$uids{$uid};
+  ok !validate_uid($uid), "\$here is no longer valid (out of thread $tid)";
+ }
 }
 
 is scalar(keys %uids), $threads, 'all the UIDs were different';
 
-done_testing($threads * 5 + 1);
+done_testing;