<s> import time <EOL> from mrq . job import Job <EOL> import pytest <EOL> @ pytest . mark . parametrize ( [ "<STR_LIT>" ] , [ [ "<STR_LIT>" ] , [ "<STR_LIT>" ] ] ) <EOL> def test_disconnects_service_during_task ( worker , p_service ) : <EOL> """<STR_LIT>""" <EOL> worker . start ( ) <EOL> if p_service == "<STR_LIT>" : <EOL> service = worker . fixture_mongodb <EOL> elif p_service == "<STR_LIT>" : <EOL> service = worker . fixture_redis <EOL> service_pid = service . process . pid <EOL> job_id1 = worker . send_task ( "<STR_LIT>" , { <EOL> "<STR_LIT:a>" : <NUM_LIT> , "<STR_LIT:b>" : <NUM_LIT:1> , "<STR_LIT>" : <NUM_LIT:5> } , block = False , queue = "<STR_LIT:default>" ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> service . stop ( ) <EOL> service . start ( ) <EOL> service_pid2 = service . process . pid <EOL> assert service_pid != service_pid2 <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> assert Job ( job_id1 ) . fetch ( ) . data [ "<STR_LIT:result>" ] == <NUM_LIT> <EOL> @ pytest . mark . parametrize ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , [ <EOL> ( None , None , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> ( None , None , <NUM_LIT:2> , <NUM_LIT:1> ) , <EOL> ( None , <NUM_LIT:10> , <NUM_LIT:1> , <NUM_LIT:10> ) , <EOL> ( None , <NUM_LIT:10> , <NUM_LIT:2> , <NUM_LIT:10> ) , <EOL> ( None , <NUM_LIT:200> , <NUM_LIT:1> , <NUM_LIT:100> ) , <EOL> ( None , <NUM_LIT:200> , <NUM_LIT:2> , <NUM_LIT:100> ) , <EOL> ( <NUM_LIT:4> , None , <NUM_LIT:1> , <NUM_LIT:4> ) , <EOL> ( <NUM_LIT:4> , None , <NUM_LIT:2> , <NUM_LIT:4> ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:4> ) , <EOL> ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:4> ) , <EOL> ] ) <EOL> def test_redis_disconnections ( gevent_count , subpool_size , iterations , expected_clients , worker ) : <EOL> """<STR_LIT>""" <EOL> from mrq . context import connections <EOL> worker . start_deps ( ) <EOL> gevent_count = gevent_count if gevent_count is not None else <NUM_LIT:1> <EOL> get_clients = lambda : [ c for c in connections . redis . client_list ( ) if c . get ( "<STR_LIT>" ) != "<STR_LIT>" ] <EOL> assert len ( get_clients ( ) ) == <NUM_LIT:0> <EOL> kwargs = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } <EOL> if gevent_count : <EOL> kwargs [ "<STR_LIT>" ] += "<STR_LIT>" % gevent_count <EOL> worker . start ( ** kwargs ) <EOL> for i in range ( <NUM_LIT:0> , iterations ) : <EOL> worker . send_tasks ( "<STR_LIT>" , [ { "<STR_LIT>" : subpool_size } ] * gevent_count ) <EOL> assert len ( get_clients ( ) ) == expected_clients <EOL> worker . stop ( deps = False ) <EOL> assert len ( get_clients ( ) ) == <NUM_LIT:0> <EOL> worker . stop_deps ( ) </s>
