@@ -3,15 +3,18 @@ part of sqljocky;
3
3
void runConnectionTests () {
4
4
group ('Connection' , () {
5
5
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 );
8
10
expect (() {
9
11
cnx._sendBuffer (buffer);
10
12
}, throwsA (new isInstanceOf <MySqlClientError >()));
11
13
});
12
14
13
15
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 );
15
18
var socket = new MockSocket ();
16
19
cnx._socket = socket;
17
20
@@ -41,7 +44,8 @@ void runConnectionTests() {
41
44
});
42
45
43
46
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 );
45
49
var socket = new MockSocket ();
46
50
cnx._socket = socket;
47
51
@@ -52,7 +56,8 @@ void runConnectionTests() {
52
56
});
53
57
socket.when (callsTo ('writeBufferPart' )).alwaysReturn (new Future .value ());
54
58
55
- var buffer = new Buffer (17 * 1024 * 1024 );
59
+ final PACKET_SIZE = 17 * 1024 * 1024 ;
60
+ var buffer = new Buffer (PACKET_SIZE );
56
61
return cnx._sendBuffer (buffer).then ((_) {
57
62
socket.getLogs (callsTo ('writeBuffer' )).verify (happenedExactly (2 ));
58
63
socket.getLogs (callsTo ('writeBufferPart' )).verify (happenedExactly (2 ));
@@ -61,12 +66,13 @@ void runConnectionTests() {
61
66
expect (socket.getLogs (callsTo ('writeBufferPart' )).logs[0 ].args[1 ], equals (0 ));
62
67
expect (socket.getLogs (callsTo ('writeBufferPart' )).logs[0 ].args[2 ], equals (0xffffff ));
63
68
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 ));
65
70
});
66
71
});
67
72
68
73
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 );
70
76
var socket = new MockSocket ();
71
77
cnx._socket = socket;
72
78
@@ -79,13 +85,13 @@ void runConnectionTests() {
79
85
};
80
86
81
87
var bufferReturnCount = 0 ;
82
- var bufferReturn = (_) {
88
+ var bufferReturn = (_) async {
83
89
if (bufferReturnCount == 0 ) {
84
90
bufferReturnCount++ ;
85
- return new Future . value ( new Buffer .fromList ([3 , 0 , 0 , 1 ]) );
91
+ return new Buffer .fromList ([3 , 0 , 0 , 1 ]);
86
92
} else {
87
93
bufferReturnCount++ ;
88
- return new Future . value ( new Buffer .fromList ([1 , 2 , 3 ]) );
94
+ return new Buffer .fromList ([1 , 2 , 3 ]);
89
95
}
90
96
};
91
97
socket.when (callsTo ('readBuffer' )).thenCall (bufferReturn, 2 );
@@ -100,7 +106,8 @@ void runConnectionTests() {
100
106
});
101
107
102
108
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 );
104
111
var socket = new MockSocket ();
105
112
cnx._socket = socket;
106
113
0 commit comments