PageRenderTime 404ms CodeModel.GetById 181ms app.highlight 9ms RepoModel.GetById 212ms app.codeStats 0ms

/t/Teto-Queue.t

http://github.com/motemen/Teto
Unknown | 47 lines | 35 code | 12 blank | 0 comment | 0 complexity | a9f58a2e8e3c7c46d583f0ddb2114d11 MD5 | raw file
 1use strict;
 2use lib 'lib';
 3use Test::More tests => 3;
 4use Test::Deep;
 5use Teto::Track;
 6use Coro;
 7
 8use_ok 'Teto::Queue';
 9
10subtest basic => sub {
11    my $queue = new_ok 'Teto::Queue', [ track_fh => do { my $s = ''; open my $fh, '>', \$s; $fh } ];
12
13    cmp_deeply $queue->tracks, [];
14
15    $queue->add_track(Teto::Track->from_url('http://www.nicovideo.jp/watch/sm12441199'));
16    cmp_deeply $queue->tracks, [ isa('Teto::Track') & methods(video_id => 'sm12441199') ];
17
18    async {
19        my $track = $queue->wait_for_track;
20        isa_ok $track, 'Teto::Track';
21    };
22    cede;
23};
24
25subtest signal => sub {
26    my $queue = Teto::Queue->new(track_fh => do { my $s = ''; open my $fh, '>', \$s; $fh });
27
28    my @coros;
29    my ($waiting, $track);
30    push @coros, async {
31        $waiting++;
32        $track = $queue->wait_for_track;
33        cmp_deeply $track, isa('Teto::Track') & methods(video_id => 'sm9'), 'got added track';
34    };
35
36    cede;
37
38    ok !$track,  'track not got';
39
40    push @coros, async {
41        $queue->add_track(Teto::Track->from_url('http://www.nicovideo.jp/watch/sm9'));
42    };
43
44    $_->join for @coros;
45
46    done_testing(2);
47};