Skip to content

Commit 68c832b

Browse files
committed
More async/await
1 parent 61a1cec commit 68c832b

File tree

8 files changed

+267
-410
lines changed

8 files changed

+267
-410
lines changed

test/integration/errors.dart

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@ part of integrationtests;
33
void runErrorTests(String user, String password, String db, int port, String host) {
44
ConnectionPool pool;
55
group('error tests:', () {
6-
test('setup', () {
6+
test('setup', () async {
77
pool = new ConnectionPool(user:user, password:password, db:db, port:port, host:host, max:1,
88
// useCompression: false,
99
useSSL: true);
10-
pool.getConnection().then((cnx) {
11-
print("Connection secure: ${cnx.usingSSL}");
12-
cnx.release();
13-
});
10+
var cnx = await pool.getConnection();
11+
print("Connection secure: ${cnx.usingSSL}");
12+
cnx.release();
1413
return setup(pool, "stream", "create table stream (id integer, name text)");
1514
});
1615

17-
test('store data', () {
18-
var c = new Completer();
19-
pool.prepare('insert into stream (id, name) values (?, ?)').then((query) {
20-
query.execute([0, 'Bob']).then((Results results) {
21-
c.complete();
22-
});
23-
});
24-
return c.future;
16+
test('store data', () async {
17+
var query = await pool.prepare('insert into stream (id, name) values (?, ?)');
18+
await query.execute([0, 'Bob']);
2519
});
2620

2721
test('select from stream using query and listen', () {

test/integration/execute_multi.dart

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,22 @@ void runExecuteMultiTests(String user, String password, String db, int port, Str
99
"insert into stream (id, name) values (1, 'A'), (2, 'B'), (3, 'C')");
1010
});
1111

12-
test('store data', () {
13-
var c = new Completer();
14-
var theValues;
15-
pool.prepare('select * from stream where id = ?').then((query) {
16-
return query.executeMulti([[1], [2], [3]]);
17-
}).then((values) {
18-
theValues = values;
19-
expect(values, hasLength(3));
20-
return theValues[0].toList();
21-
}).then((resultList) {
22-
expect(resultList[0][0], equals(1));
23-
expect(resultList[0][1].toString(), equals('A'));
24-
return theValues[1].toList();
25-
}).then((resultList) {
26-
expect(resultList[0][0], equals(2));
27-
expect(resultList[0][1].toString(), equals('B'));
28-
return theValues[2].toList();
29-
}).then((resultList) {
30-
expect(resultList[0][0], equals(3));
31-
expect(resultList[0][1].toString(), equals('C'));
32-
c.complete(null);
33-
});
34-
return c.future;
12+
test('store data', () async {
13+
var query = await pool.prepare('select * from stream where id = ?');
14+
var values = await query.executeMulti([[1], [2], [3]]);
15+
expect(values, hasLength(3));
16+
17+
var resultList = await values[0].toList();
18+
expect(resultList[0][0], equals(1));
19+
expect(resultList[0][1].toString(), equals('A'));
20+
21+
resultList = await values[1].toList();
22+
expect(resultList[0][0], equals(2));
23+
expect(resultList[0][1].toString(), equals('B'));
24+
25+
resultList = await values[2].toList();
26+
expect(resultList[0][0], equals(3));
27+
expect(resultList[0][1].toString(), equals('C'));
3528
});
3629

3730
test('close connection', () {

test/integration/nullmap.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ void runNullMapTests(String user, String password, String db, int port, String h
88
return setup(pool, "nullmap", "create table nullmap (a text, b text, c text, d text)");
99
});
1010

11-
test('store data', () {
12-
var c = new Completer();
13-
pool.prepare('insert into nullmap (a, b, c, d) values (?, ?, ?, ?)').then((query) {
14-
query.execute([null, 'b', 'c', 'd']).then((Results results) {
15-
c.complete();
16-
});
17-
});
18-
return c.future;
11+
test('store data', () async {
12+
var query = await pool.prepare('insert into nullmap (a, b, c, d) values (?, ?, ?, ?)');
13+
await query.execute([null, 'b', 'c', 'd']);
1914
});
2015

2116
test('read data', () {

test/integration/numbers.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
part of integrationtests;
22

3-
Future deleteInsertSelect(ConnectionPool pool, table, insert, select) {
4-
return pool.query('delete from $table').then((_) {
5-
return pool.query(insert);
6-
}).then((_) {
7-
return pool.query(select);
8-
});
3+
Future deleteInsertSelect(ConnectionPool pool, table, insert, select) async {
4+
await pool.query('delete from $table');
5+
await pool.query(insert);
6+
return pool.query(select);
97
}
108

119
void runNumberTests(String user, String password, String db, int port, String host) {

0 commit comments

Comments
 (0)