forked from plainblack/Lacuna-Server-Open
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path510_bs_building.t
69 lines (49 loc) · 1.52 KB
/
510_bs_building.t
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use lib '../lib';
use strict;
use warnings;
use Test::More tests => 7;
use Test::Deep;
use Test::Memory::Cycle;
use Data::Dumper;
use 5.010;
use DateTime;
use Lacuna;
use TestHelper;
my $now = DateTime->now;
my $later = DateTime->now->add( seconds => 3);
my $dur = $later->subtract_datetime_absolute($now);
my $seconds = $dur->in_units('seconds');
is($seconds, 3, "CPAN modules agree on seconds");
my $db = Lacuna->db;
my $thing = $db->resultset('ApiKey')->create({
public_key => 'foo',
private_key => 'bar',
name => 'iain',
ip_address => '10.11.12.13',
email => '[email protected]',
});
my $schedule = $db->resultset('Schedule')->create({
queue => 'default',
delivery => $later,
parent_table => 'ApiKey',
parent_id => $thing->id,
task => 'bar',
args => {this => 'siht', that => 'taht'},
});
isa_ok($schedule, 'Lacuna::DB::Result::Schedule', 'Correct class');
exit;
# Now test against beanstalk (it must be running)
#
my $queue = Lacuna::Queue->new;
isa_ok($queue, 'Lacuna::Queue', 'Correct queue class');
my $job = $queue->consume('foo');
isa_ok($job, 'Lacuna::Queue::Job', 'Correct job class');
my $payload = $job->payload;
isa_ok($payload, 'Lacuna::DB::Result::ApiKey', 'Got back an ApiKey');
is($payload->public_key,'foo', 'foo found');
is($payload->name,'iain', 'iain found');
$now = DateTime->now;
diag("later = [$later] now = [$now]");
# Delete this job, we no longer need it
$job->delete;
1;