Skip to content

Commit 59a67f9

Browse files
committed
Make test a tiny bit more readable
1 parent 6eb1b88 commit 59a67f9

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

test/unit/connection_test.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ part of sqljocky;
33
void runConnectionTests() {
44
group('Connection', () {
55
test('should throw error if buffer is too big', () {
6-
var cnx = new _Connection(null, 15, 10);
7-
var buffer = new Buffer(11);
6+
final MAX_PACKET_SIZE = 10;
7+
var cnx = new _Connection(null, 15, MAX_PACKET_SIZE);
8+
final PACKET_SIZE = 11;
9+
var buffer = new Buffer(PACKET_SIZE);
810
expect(() {
911
cnx._sendBuffer(buffer);
1012
}, throwsA(new isInstanceOf<MySqlClientError>()));
1113
});
1214

1315
test('should send buffer', () {
14-
var cnx = new _Connection(null, 15, 16 * 1024 * 1024);
16+
final MAX_PACKET_SIZE = 16 * 1024 * 1024;
17+
var cnx = new _Connection(null, 15, MAX_PACKET_SIZE);
1518
var socket = new MockSocket();
1619
cnx._socket = socket;
1720

@@ -41,7 +44,8 @@ void runConnectionTests() {
4144
});
4245

4346
test('should send large buffer', () {
44-
var cnx = new _Connection(null, 15, 32 * 1024 * 1024);
47+
final MAX_PACKET_SIZE = 32 * 1024 * 1024;
48+
var cnx = new _Connection(null, 15, MAX_PACKET_SIZE);
4549
var socket = new MockSocket();
4650
cnx._socket = socket;
4751

@@ -52,7 +56,8 @@ void runConnectionTests() {
5256
});
5357
socket.when(callsTo('writeBufferPart')).alwaysReturn(new Future.value());
5458

55-
var buffer = new Buffer(17 * 1024 * 1024);
59+
final PACKET_SIZE = 17 * 1024 * 1024;
60+
var buffer = new Buffer(PACKET_SIZE);
5661
return cnx._sendBuffer(buffer).then((_) {
5762
socket.getLogs(callsTo('writeBuffer')).verify(happenedExactly(2));
5863
socket.getLogs(callsTo('writeBufferPart')).verify(happenedExactly(2));
@@ -61,12 +66,13 @@ void runConnectionTests() {
6166
expect(socket.getLogs(callsTo('writeBufferPart')).logs[0].args[1], equals(0));
6267
expect(socket.getLogs(callsTo('writeBufferPart')).logs[0].args[2], equals(0xffffff));
6368
expect(socket.getLogs(callsTo('writeBufferPart')).logs[1].args[1], equals(0xffffff));
64-
expect(socket.getLogs(callsTo('writeBufferPart')).logs[1].args[2], equals(17 * 1024 * 1024 - 0xffffff));
69+
expect(socket.getLogs(callsTo('writeBufferPart')).logs[1].args[2], equals(PACKET_SIZE - 0xffffff));
6570
});
6671
});
6772

6873
test('should receive buffer', () {
69-
var cnx = new _Connection(null, 15, 16 * 1024 * 1024);
74+
final MAX_PACKET_SIZE = 16 * 1024 * 1024;
75+
var cnx = new _Connection(null, 15, MAX_PACKET_SIZE);
7076
var socket = new MockSocket();
7177
cnx._socket = socket;
7278

@@ -79,13 +85,13 @@ void runConnectionTests() {
7985
};
8086

8187
var bufferReturnCount = 0;
82-
var bufferReturn = (_) {
88+
var bufferReturn = (_) async {
8389
if (bufferReturnCount == 0) {
8490
bufferReturnCount++;
85-
return new Future.value(new Buffer.fromList([3, 0, 0, 1]));
91+
return new Buffer.fromList([3, 0, 0, 1]);
8692
} else {
8793
bufferReturnCount++;
88-
return new Future.value(new Buffer.fromList([1, 2, 3]));
94+
return new Buffer.fromList([1, 2, 3]);
8995
}
9096
};
9197
socket.when(callsTo('readBuffer')).thenCall(bufferReturn, 2);
@@ -100,7 +106,8 @@ void runConnectionTests() {
100106
});
101107

102108
test('should receive large buffer', () {
103-
var cnx = new _Connection(null, 15, 32 * 1024 * 1024);
109+
final MAX_PACKET_SIZE = 32 * 1024 * 1024;
110+
var cnx = new _Connection(null, 15, MAX_PACKET_SIZE);
104111
var socket = new MockSocket();
105112
cnx._socket = socket;
106113

0 commit comments

Comments
 (0)