File: threads.t

package info (click to toggle)
libobject-id-perl 0.1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 188 kB
  • sloc: perl: 289; makefile: 2
file content (44 lines) | stat: -r--r--r-- 793 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
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl

use strict;
use warnings;

my $Have_Threads;
BEGIN {
    $Have_Threads = eval { require threads };
    require Test::More;
    Test::More->import;
}

plan skip_all => "Needs threads" unless $Have_Threads;

{
    package Foo;
    use Object::ID;
    sub new {
        my $class = shift;
        bless {}, $class;
    }
}

TODO: for my $method (qw(object_id object_uuid)) {
    note "*** Trying $method ***";
    todo_skip "uuid known to be thread hostile", 5 if $method eq 'object_uuid';

    my $obj = new_ok "Foo";
    my $id = $obj->$method;

    for(1..5) {
        threads->create(sub {
            is $obj->$method, $id, "$method in a thread";
        });
    }

    note "threads started";

    $_->join for threads->list;

    note "threads joined";
}

done_testing();