File: threads.t

package info (click to toggle)
libdata-uuid-perl 1.219-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 184 kB
  • ctags: 136
  • sloc: ansic: 344; perl: 70; makefile: 11
file content (34 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use strict;
use warnings;
use Test::More;
use Config;

BEGIN {
    plan skip_all => 'Perl not compiled with useithreads'
        if !$Config{useithreads};
    plan skip_all => 'This test does not cope well with this version of perl'
        if "$]" == 5.008_002
        or ("$]" < 5.013_004 and not $ENV{AUTHOR_TESTING});
    plan tests => 4;
}

use threads;
use Data::UUID;

my $ug = Data::UUID->new;

my @threads = map {
    threads->create(sub { ($ug->create_str, Data::UUID->new->create_str) });
} 1 .. 20;

my @ret = map {
    $_->join
} @threads;

pass 'we survived our threads';

is @ret, 40, 'got as all the uuids we expected';
ok !grep({ !defined } @ret), 'uuids look sane';

my %uuids = map { $_ => 1 } @ret;
is keys %uuids, @ret, "all UUIDs are unique";