|
1 | 1 | from nutkit.frontend import Driver
|
2 | 2 | import nutkit.protocol as types
|
3 |
| -from tests.shared import ( |
4 |
| - driver_feature, |
5 |
| - TestkitTestCase, |
6 |
| -) |
| 3 | +from tests.shared import TestkitTestCase |
7 | 4 | from tests.stub.shared import StubServer
|
8 | 5 |
|
9 | 6 |
|
@@ -47,6 +44,22 @@ def _start_server(self, server, script):
|
47 | 44 | server.start(self.script_path(script),
|
48 | 45 | vars_={"#HOST#": self._router.host})
|
49 | 46 |
|
| 47 | + def test_should_work_when_every_step_is_done_in_time(self): |
| 48 | + """Everything in time.""" |
| 49 | + self._start_server(self._router, "router.script") |
| 50 | + self._start_server(self._server, "session_run.script") |
| 51 | + uri = "neo4j://10.255.255.255" |
| 52 | + auth = types.AuthorizationToken("basic", principal="neo4j", |
| 53 | + credentials="pass") |
| 54 | + |
| 55 | + uri = "neo4j://%s" % self._router.address |
| 56 | + self._driver = Driver(self._backend, uri, auth, |
| 57 | + update_routing_table_timeout_ms=2000) |
| 58 | + |
| 59 | + self._session = self._driver.session("r") |
| 60 | + |
| 61 | + list(self._session.run("RETURN 1 AS n")) |
| 62 | + |
50 | 63 | def test_encompasses_router_connection_time(self):
|
51 | 64 | """Router connection times out."""
|
52 | 65 | uri = "neo4j://10.255.255.255"
|
@@ -128,187 +141,3 @@ def test_does_not_encompass_reader_connection_time(self):
|
128 | 141 | self._driver = None
|
129 | 142 | self._router.done()
|
130 | 143 | self._server.done()
|
131 |
| - |
132 |
| - def test_should_work_when_every_step_is_done_in_time(self): |
133 |
| - """ |
134 |
| - Everything in time scenario. |
135 |
| -
|
136 |
| - This test scenario tests the case where: |
137 |
| -
|
138 |
| - 1. the connection acquisition timeout is higher than |
139 |
| - the connection creation timeout |
140 |
| - 2. the connection is successfully created and in due time |
141 |
| -
|
142 |
| - Then the query is executed successfully |
143 |
| - """ |
144 |
| - self._start_server(self._server, "session_run_auth_delay.script") |
145 |
| - |
146 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
147 |
| - credentials="pass") |
148 |
| - uri = "bolt://%s" % self._server.address |
149 |
| - self._driver = Driver(self._backend, uri, auth, |
150 |
| - connection_acquisition_timeout_ms=10000, |
151 |
| - connection_timeout_ms=5000) |
152 |
| - |
153 |
| - self._session = self._driver.session("r") |
154 |
| - |
155 |
| - list(self._session.run("RETURN 1 AS n")) |
156 |
| - |
157 |
| - def test_should_encompass_the_handshake_time(self): |
158 |
| - """ |
159 |
| - Handshake takes longer scenario. |
160 |
| -
|
161 |
| - This test scenario tests the case where: |
162 |
| -
|
163 |
| - 1. the connection acquisition timeout is smaller than |
164 |
| - the connection creation timeout |
165 |
| - 2. the connection is successfully created and in due time |
166 |
| - 3. the handshake takes longer than the connection acquisition timeout |
167 |
| -
|
168 |
| - Then the query is not executed since the connection acquisition |
169 |
| - timed out. |
170 |
| - """ |
171 |
| - self._start_server(self._server, "session_run_auth_delay.script") |
172 |
| - |
173 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
174 |
| - credentials="pass") |
175 |
| - uri = "bolt://%s" % self._server.address |
176 |
| - self._driver = Driver(self._backend, uri, auth, |
177 |
| - connection_acquisition_timeout_ms=2000, |
178 |
| - connection_timeout_ms=720000) |
179 |
| - |
180 |
| - self._session = self._driver.session("r") |
181 |
| - |
182 |
| - with self.assertRaises(types.DriverError): |
183 |
| - list(self._session.run("RETURN 1 AS n")) |
184 |
| - |
185 |
| - def test_should_fail_when_acquisition_timeout_is_reached_first(self): |
186 |
| - """ |
187 |
| - Connection creation bigger than acquisition timeout scenario. |
188 |
| -
|
189 |
| - This test scenario tests the case where: |
190 |
| -
|
191 |
| - 1. the connection acquisition timeout is smaller than |
192 |
| - the connection creation timeout |
193 |
| - 2. the connection takes longer than the |
194 |
| - acquisition timeout to be created |
195 |
| -
|
196 |
| - Then the query is not executed since the connection acquisition |
197 |
| - times out. |
198 |
| - """ |
199 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
200 |
| - credentials="pass") |
201 |
| - |
202 |
| - # Non routable address |
203 |
| - uri = "bolt://10.255.255.255" |
204 |
| - self._driver = Driver(self._backend, uri, auth, |
205 |
| - connection_acquisition_timeout_ms=2000, |
206 |
| - connection_timeout_ms=720000) |
207 |
| - |
208 |
| - self._session = self._driver.session("r") |
209 |
| - |
210 |
| - with self.assertRaises(types.DriverError): |
211 |
| - list(self._session.run("RETURN 1 AS n")) |
212 |
| - |
213 |
| - def test_should_fail_when_connection_timeout_is_reached_first(self): |
214 |
| - """ |
215 |
| - Acquisition timeout bigger than connection creation timeout scenario. |
216 |
| -
|
217 |
| - This test scenario tests the case where: |
218 |
| -
|
219 |
| - 1. the connection acquisition timeout is bigger than |
220 |
| - the connection creation timeout |
221 |
| - 2. the connection is successfully takes longer than the |
222 |
| - connection timeout to be created |
223 |
| -
|
224 |
| - Then the query is not executed since the connection creation |
225 |
| - times out. |
226 |
| - """ |
227 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
228 |
| - credentials="pass") |
229 |
| - |
230 |
| - # Non routable address |
231 |
| - uri = "bolt://10.255.255.255" |
232 |
| - self._driver = Driver(self._backend, uri, auth, |
233 |
| - connection_acquisition_timeout_ms=72000, |
234 |
| - connection_timeout_ms=2000) |
235 |
| - |
236 |
| - self._session = self._driver.session("r") |
237 |
| - |
238 |
| - with self.assertRaises(types.DriverError): |
239 |
| - list(self._session.run("RETURN 1 AS n")) |
240 |
| - |
241 |
| - def test_does_not_encompass_router_handshake(self): |
242 |
| - self._start_server(self._router, "router_hello_delay.script") |
243 |
| - self._start_server(self._server, "session_run.script") |
244 |
| - |
245 |
| - uri = "neo4j://%s" % self._router.address |
246 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
247 |
| - credentials="pass") |
248 |
| - self._driver = Driver(self._backend, uri, auth, |
249 |
| - connection_acquisition_timeout_ms=2000, |
250 |
| - connection_timeout_ms=720000) |
251 |
| - self._session = self._driver.session("r") |
252 |
| - list(self._session.run("RETURN 1 AS n")) |
253 |
| - |
254 |
| - self._session.close() |
255 |
| - self._session = None |
256 |
| - self._driver.close() |
257 |
| - self._driver = None |
258 |
| - self._router.done() |
259 |
| - self._server.done() |
260 |
| - |
261 |
| - def test_does_not_encompass_router_route_response(self): |
262 |
| - self._start_server(self._router, "router_route_delay.script") |
263 |
| - self._start_server(self._server, "session_run.script") |
264 |
| - |
265 |
| - uri = "neo4j://%s" % self._router.address |
266 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
267 |
| - credentials="pass") |
268 |
| - self._driver = Driver(self._backend, uri, auth, |
269 |
| - connection_acquisition_timeout_ms=2000, |
270 |
| - connection_timeout_ms=720000) |
271 |
| - self._session = self._driver.session("r") |
272 |
| - list(self._session.run("RETURN 1 AS n")) |
273 |
| - |
274 |
| - self._session.close() |
275 |
| - self._session = None |
276 |
| - self._driver.close() |
277 |
| - self._driver = None |
278 |
| - self._router.done() |
279 |
| - self._server.done() |
280 |
| - |
281 |
| - @driver_feature(types.Feature.OPT_EAGER_TX_BEGIN) |
282 |
| - def test_should_regulate_the_time_for_acquiring_connections(self): |
283 |
| - """ |
284 |
| - No connection available scenario. |
285 |
| -
|
286 |
| - This test scenario tests the case where: |
287 |
| - 1. The connection pool is configured for max 1 connection |
288 |
| - 2. A connection is acquired and locked by another transaction |
289 |
| - 3. When the new session try to acquire a connection, the connection |
290 |
| - pool doesn't have connections available in suitable time |
291 |
| -
|
292 |
| - Then the begin transaction is not executed |
293 |
| - since the connection acquisition times out. |
294 |
| - """ |
295 |
| - self._start_server(self._server, |
296 |
| - "tx_without_commit_or_rollback.script") |
297 |
| - |
298 |
| - auth = types.AuthorizationToken("basic", principal="neo4j", |
299 |
| - credentials="pass") |
300 |
| - uri = "bolt://%s" % self._server.address |
301 |
| - self._driver = Driver(self._backend, uri, auth, |
302 |
| - connection_acquisition_timeout_ms=2000, |
303 |
| - connection_timeout_ms=720000, |
304 |
| - max_connection_pool_size=1) |
305 |
| - |
306 |
| - self._sessions = [ |
307 |
| - self._driver.session("r"), |
308 |
| - self._driver.session("r"), |
309 |
| - ] |
310 |
| - |
311 |
| - self._txs = [self._sessions[0].begin_transaction()] |
312 |
| - |
313 |
| - with self.assertRaises(types.DriverError): |
314 |
| - self._txs.append(self._sessions[1].begin_transaction()) |
0 commit comments