-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync.t
72 lines (54 loc) · 1.75 KB
/
async.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
69
70
71
72
use Test2::V0;
use lib 't/lib';
use DBIx::QuickORM::Tester qw/dbs_do all_dbs/;
use DBIx::QuickORM;
#use Test2::Plugin::BailOnFail;
dbs_do db => sub {
my ($dbname, $dbc, $st) = @_;
my $orm = orm sub {
db sub {
db_class $dbname;
db_name 'quickdb';
db_connect sub { $dbc->connect };
};
schema sub {
table person => sub {
column person_id => sub {
primary_key;
serial('BIG');
};
column name => sub {
unique;
sql_spec(type => 'VARCHAR(128)');
};
};
};
};
skip_all "$dbname does not support async" unless $orm->connection->supports_async;
ok(lives { $orm->generate_and_load_schema() }, "Generate and load schema");
is([$orm->connection->tables], ['person'], "Table person was added");
my $s = $orm->source('person');
my $bob = $s->insert(name => 'bob');
my $ted = $s->insert(name => 'ted');
my $ann = $s->insert(name => 'ann');
my $as = $orm->source('person')->async({}, 'name')->start;
ok(!$as->{rows}, "No rows yet");
ok($as->started, "Query has been started");
ok($s->busy, "Source is currently busy");
ok($as->busy, "Select is currently busy");
like(
dies { $s->first },
qr/This database connection is currently engaged in an async query/,
"Cannot issue another query while an async query is in progress"
);
#sleep(1) while !$as->ready;
sleep 1;
ok($as->ready, "We are ready!");
is(
[$as->all],
[$ann, $bob, $ted],
"Got all 3 rows"
);
ok($s->first, "Now we can do other queries again");
};
done_testing;