Skip to content

Commit 9cc47f3

Browse files
committed
rearrange
1 parent fe11e12 commit 9cc47f3

File tree

1 file changed

+176
-176
lines changed

1 file changed

+176
-176
lines changed

tests/test_connect.py

Lines changed: 176 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,182 @@ async def test_connect_error_no_reconnect(self) -> None:
287287
with pytest.raises(ConnectionRefusedError):
288288
await conn.connect()
289289

290+
async def test_connect_wait_tnt_started(self, tnt: TarantoolSyncInstance) -> None:
291+
tnt.stop()
292+
conn = asynctnt.Connection(
293+
host=tnt.host,
294+
port=tnt.port,
295+
username="t1",
296+
password="t1",
297+
fetch_schema=True,
298+
reconnect_timeout=0.000000001,
299+
)
300+
try:
301+
coro = asyncio.ensure_future(conn.connect())
302+
await asyncio.sleep(0.3)
303+
tnt.start()
304+
await asyncio.sleep(1)
305+
while True:
306+
try:
307+
await coro
308+
break
309+
except TarantoolDatabaseError as e:
310+
if e.code == ErrorCode.ER_NO_SUCH_USER:
311+
# Try again
312+
coro = asyncio.ensure_future(conn.connect())
313+
continue
314+
raise
315+
316+
assert conn.state == ConnectionState.CONNECTED
317+
await conn.call("box.info")
318+
finally:
319+
await conn.disconnect()
320+
321+
async def test_connect_waiting_for_spaces(
322+
self, tnt: TarantoolSyncInstance, in_docker: bool
323+
) -> None:
324+
if in_docker:
325+
pytest.skip("not running in docker")
326+
327+
with create_tarantool_instance(replication_source=["x:1"]) as instance:
328+
instance.start(wait=False)
329+
330+
conn = asynctnt.Connection(
331+
host=instance.host,
332+
port=instance.port,
333+
fetch_schema=True,
334+
reconnect_timeout=0.1,
335+
connect_timeout=10,
336+
)
337+
assert conn.connect_timeout == 10
338+
try:
339+
states: dict[ConnectionState, bool] = {}
340+
341+
async def state_checker() -> None:
342+
while True:
343+
states[conn.state] = True
344+
await asyncio.sleep(0.001)
345+
346+
checker = asyncio.ensure_future(state_checker())
347+
348+
try:
349+
await asyncio.wait_for(conn.connect(), 1)
350+
except asyncio.TimeoutError:
351+
pass # connect cancelled as expected
352+
353+
checker.cancel()
354+
355+
assert states.get(ConnectionState.CONNECTING, False), "was in connecting"
356+
357+
with pytest.raises(TarantoolNotConnectedError):
358+
await conn.call("box.info")
359+
finally:
360+
await conn.disconnect()
361+
362+
@pytest.mark.min_bin_version((1, 7))
363+
async def test_connect_waiting_for_spaces_no_reconnect(
364+
self, tnt: TarantoolSyncInstance, in_docker: bool
365+
) -> None:
366+
if in_docker:
367+
pytest.skip("not running in docker")
368+
369+
with create_tarantool_instance(replication_source=["x:1"]) as instance:
370+
instance.start(wait=False)
371+
await asyncio.sleep(1)
372+
373+
conn = asynctnt.Connection(
374+
host=instance.host,
375+
port=instance.port,
376+
fetch_schema=True,
377+
reconnect_timeout=0,
378+
connect_timeout=10,
379+
)
380+
try:
381+
with pytest.raises(TarantoolDatabaseError) as exc:
382+
await conn.connect()
383+
384+
assert exc.value.code == ErrorCode.ER_NO_SUCH_SPACE
385+
finally:
386+
await conn.disconnect()
387+
388+
@pytest.mark.max_bin_version((1, 7))
389+
async def test_connect_waiting_for_spaces_no_reconnect_1_6(
390+
self, tnt: TarantoolSyncInstance, in_docker: bool
391+
) -> None:
392+
if in_docker:
393+
pytest.skip("not running in docker")
394+
395+
with create_tarantool_instance(replication_source=["x:1"]) as instance:
396+
instance.start(wait=False)
397+
await asyncio.sleep(1)
398+
399+
conn = asynctnt.Connection(
400+
host=instance.host,
401+
port=instance.port,
402+
fetch_schema=True,
403+
reconnect_timeout=0,
404+
connect_timeout=10,
405+
)
406+
try:
407+
with pytest.raises(ConnectionRefusedError):
408+
await conn.connect()
409+
finally:
410+
await conn.disconnect()
411+
412+
@pytest.mark.min_bin_version((1, 7))
413+
async def test_connect_err_loading(
414+
self, tnt: TarantoolSyncInstance, in_docker: bool
415+
) -> None:
416+
if in_docker:
417+
pytest.skip("not running in docker")
418+
419+
with create_tarantool_instance(replication_source=["x:1"]) as instance:
420+
instance.start(wait=False)
421+
await asyncio.sleep(1)
422+
423+
conn = asynctnt.Connection(
424+
host=instance.host,
425+
port=instance.port,
426+
username="t1",
427+
password="t1",
428+
fetch_schema=True,
429+
reconnect_timeout=0,
430+
connect_timeout=10,
431+
)
432+
try:
433+
with pytest.raises(TarantoolDatabaseError) as exc:
434+
await conn.connect()
435+
436+
assert exc.value.code == ErrorCode.ER_LOADING
437+
finally:
438+
await conn.disconnect()
439+
440+
@pytest.mark.max_bin_version((1, 7))
441+
async def test_connect_err_loading_1_6(
442+
self, tnt: TarantoolSyncInstance, in_docker: bool
443+
) -> None:
444+
if in_docker:
445+
pytest.skip("not running in docker")
446+
447+
with create_tarantool_instance(replication_source=["x:1"]) as instance:
448+
instance.start(wait=False)
449+
await asyncio.sleep(1)
450+
451+
conn = asynctnt.Connection(
452+
host=instance.host,
453+
port=instance.port,
454+
username="t1",
455+
password="t1",
456+
fetch_schema=True,
457+
reconnect_timeout=0,
458+
connect_timeout=10,
459+
)
460+
try:
461+
with pytest.raises(ConnectionRefusedError):
462+
await conn.connect()
463+
finally:
464+
await conn.disconnect()
465+
290466
async def test_connect_tnt_restarted(self, tnt: TarantoolSyncInstance) -> None:
291467
conn = asynctnt.Connection(
292468
host=tnt.host,
@@ -488,182 +664,6 @@ async def test_connect_on_tnt_crash_with_reconnect(
488664
finally:
489665
await conn.disconnect()
490666

491-
async def test_connect_wait_tnt_started(self, tnt: TarantoolSyncInstance) -> None:
492-
tnt.stop()
493-
conn = asynctnt.Connection(
494-
host=tnt.host,
495-
port=tnt.port,
496-
username="t1",
497-
password="t1",
498-
fetch_schema=True,
499-
reconnect_timeout=0.000000001,
500-
)
501-
try:
502-
coro = asyncio.ensure_future(conn.connect())
503-
await asyncio.sleep(0.3)
504-
tnt.start()
505-
await asyncio.sleep(1)
506-
while True:
507-
try:
508-
await coro
509-
break
510-
except TarantoolDatabaseError as e:
511-
if e.code == ErrorCode.ER_NO_SUCH_USER:
512-
# Try again
513-
coro = asyncio.ensure_future(conn.connect())
514-
continue
515-
raise
516-
517-
assert conn.state == ConnectionState.CONNECTED
518-
await conn.call("box.info")
519-
finally:
520-
await conn.disconnect()
521-
522-
async def test_connect_waiting_for_spaces(
523-
self, tnt: TarantoolSyncInstance, in_docker: bool
524-
) -> None:
525-
if in_docker:
526-
pytest.skip("not running in docker")
527-
528-
with create_tarantool_instance(replication_source=["x:1"]) as instance:
529-
instance.start(wait=False)
530-
531-
conn = asynctnt.Connection(
532-
host=instance.host,
533-
port=instance.port,
534-
fetch_schema=True,
535-
reconnect_timeout=0.1,
536-
connect_timeout=10,
537-
)
538-
assert conn.connect_timeout == 10
539-
try:
540-
states: dict[ConnectionState, bool] = {}
541-
542-
async def state_checker() -> None:
543-
while True:
544-
states[conn.state] = True
545-
await asyncio.sleep(0.001)
546-
547-
checker = asyncio.ensure_future(state_checker())
548-
549-
try:
550-
await asyncio.wait_for(conn.connect(), 1)
551-
except asyncio.TimeoutError:
552-
pass # connect cancelled as expected
553-
554-
checker.cancel()
555-
556-
assert states.get(ConnectionState.CONNECTING, False), "was in connecting"
557-
558-
with pytest.raises(TarantoolNotConnectedError):
559-
await conn.call("box.info")
560-
finally:
561-
await conn.disconnect()
562-
563-
@pytest.mark.min_bin_version((1, 7))
564-
async def test_connect_waiting_for_spaces_no_reconnect(
565-
self, tnt: TarantoolSyncInstance, in_docker: bool
566-
) -> None:
567-
if in_docker:
568-
pytest.skip("not running in docker")
569-
570-
with create_tarantool_instance(replication_source=["x:1"]) as instance:
571-
instance.start(wait=False)
572-
await asyncio.sleep(1)
573-
574-
conn = asynctnt.Connection(
575-
host=instance.host,
576-
port=instance.port,
577-
fetch_schema=True,
578-
reconnect_timeout=0,
579-
connect_timeout=10,
580-
)
581-
try:
582-
with pytest.raises(TarantoolDatabaseError) as exc:
583-
await conn.connect()
584-
585-
assert exc.value.code == ErrorCode.ER_NO_SUCH_SPACE
586-
finally:
587-
await conn.disconnect()
588-
589-
@pytest.mark.max_bin_version((1, 7))
590-
async def test_connect_waiting_for_spaces_no_reconnect_1_6(
591-
self, tnt: TarantoolSyncInstance, in_docker: bool
592-
) -> None:
593-
if in_docker:
594-
pytest.skip("not running in docker")
595-
596-
with create_tarantool_instance(replication_source=["x:1"]) as instance:
597-
instance.start(wait=False)
598-
await asyncio.sleep(1)
599-
600-
conn = asynctnt.Connection(
601-
host=instance.host,
602-
port=instance.port,
603-
fetch_schema=True,
604-
reconnect_timeout=0,
605-
connect_timeout=10,
606-
)
607-
try:
608-
with pytest.raises(ConnectionRefusedError):
609-
await conn.connect()
610-
finally:
611-
await conn.disconnect()
612-
613-
@pytest.mark.min_bin_version((1, 7))
614-
async def test_connect_err_loading(
615-
self, tnt: TarantoolSyncInstance, in_docker: bool
616-
) -> None:
617-
if in_docker:
618-
pytest.skip("not running in docker")
619-
620-
with create_tarantool_instance(replication_source=["x:1"]) as instance:
621-
instance.start(wait=False)
622-
await asyncio.sleep(1)
623-
624-
conn = asynctnt.Connection(
625-
host=instance.host,
626-
port=instance.port,
627-
username="t1",
628-
password="t1",
629-
fetch_schema=True,
630-
reconnect_timeout=0,
631-
connect_timeout=10,
632-
)
633-
try:
634-
with pytest.raises(TarantoolDatabaseError) as exc:
635-
await conn.connect()
636-
637-
assert exc.value.code == ErrorCode.ER_LOADING
638-
finally:
639-
await conn.disconnect()
640-
641-
@pytest.mark.max_bin_version((1, 7))
642-
async def test_connect_err_loading_1_6(
643-
self, tnt: TarantoolSyncInstance, in_docker: bool
644-
) -> None:
645-
if in_docker:
646-
pytest.skip("not running in docker")
647-
648-
with create_tarantool_instance(replication_source=["x:1"]) as instance:
649-
instance.start(wait=False)
650-
await asyncio.sleep(1)
651-
652-
conn = asynctnt.Connection(
653-
host=instance.host,
654-
port=instance.port,
655-
username="t1",
656-
password="t1",
657-
fetch_schema=True,
658-
reconnect_timeout=0,
659-
connect_timeout=10,
660-
)
661-
try:
662-
with pytest.raises(ConnectionRefusedError):
663-
await conn.connect()
664-
finally:
665-
await conn.disconnect()
666-
667667
async def test_connect_invalid_user_no_reconnect(
668668
self, tnt: TarantoolSyncInstance
669669
) -> None:

0 commit comments

Comments
 (0)