root/trunk/t/dead-dbs.t @ 36

Revision 36, 1.2 kB (checked in by bradfitz, 4 years ago)

make tests test both sqlite and mysql

Line 
1# $Id$
2# -*-perl-*-
3
4use strict;
5use warnings;
6
7require 't/lib/db-common.pl';
8
9use TheSchwartz;
10use Test::More tests => 4;
11
12run_tests(2, sub {
13    setup_dbs('ts1');
14    teardown_dbs('ts2');  # doesn't exist
15
16    my $client = test_client(dbs => ['ts2', 'ts1'],
17                             init => 0);
18
19    # insert a job
20    my $n_handles = 0;
21    for (1..50) {
22        my $handle = $client->insert("Worker::Addition", { numbers => [1, 2] });
23        $n_handles++ if $handle;
24    }
25    is($n_handles, 50, "got 50 handles");
26
27    # let's do some work.  the tedious way, specifying which class should grab a job
28    my $n_grabbed = 0;
29    while (my $job = Worker::Addition->grab_job($client)) {
30        $n_grabbed++;
31    }
32    is($n_grabbed, 50, "grabbed 50 times");
33
34    teardown_dbs('ts1');
35});
36
37############################################################################
38package Worker::Addition;
39use base 'TheSchwartz::Worker';
40
41sub work {
42    my ($class, $job) = @_;
43
44    # ....
45}
46
47# tell framework to set 'grabbed_until' to time() + 60.  because if
48# we can't  add some numbers in 30 seconds, our process probably
49# failed and work should be reassigned.
50sub grab_for { 30 }
51
Note: See TracBrowser for help on using the browser.