<s> import socket <EOL> import uuid <EOL> try : <EOL> from unittest import mock <EOL> except ImportError : <EOL> import mock <EOL> from testtools import testcase <EOL> from tooz import coordination <EOL> class TestMemcacheDriverFailures ( testcase . TestCase ) : <EOL> FAKE_URL = "<STR_LIT>" <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_client_failure_start ( self , mock_client_cls ) : <EOL> mock_client_cls . side_effect = socket . timeout ( '<STR_LIT>' ) <EOL> member_id = str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) <EOL> coord = coordination . get_coordinator ( self . FAKE_URL , member_id ) <EOL> self . assertRaises ( coordination . ToozConnectionError , coord . start ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_client_failure_join ( self , mock_client_cls ) : <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client_cls . return_value = mock_client <EOL> member_id = str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) <EOL> coord = coordination . get_coordinator ( self . FAKE_URL , member_id ) <EOL> coord . start ( ) <EOL> mock_client . gets . side_effect = socket . timeout ( '<STR_LIT>' ) <EOL> fut = coord . join_group ( str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) ) <EOL> self . assertRaises ( coordination . ToozConnectionError , fut . get ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_client_failure_leave ( self , mock_client_cls ) : <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client_cls . return_value = mock_client <EOL> member_id = str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) <EOL> coord = coordination . get_coordinator ( self . FAKE_URL , member_id ) <EOL> coord . start ( ) <EOL> mock_client . gets . side_effect = socket . timeout ( '<STR_LIT>' ) <EOL> fut = coord . leave_group ( str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) ) <EOL> self . assertRaises ( coordination . ToozConnectionError , fut . get ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_client_failure_heartbeat ( self , mock_client_cls ) : <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client_cls . return_value = mock_client <EOL> member_id = str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) <EOL> coord = coordination . get_coordinator ( self . FAKE_URL , member_id ) <EOL> coord . start ( ) <EOL> mock_client . set . side_effect = socket . timeout ( '<STR_LIT>' ) <EOL> self . assertRaises ( coordination . ToozConnectionError , coord . heartbeat ) <EOL> @ mock . patch ( '<STR_LIT>' , <EOL> autospec = True ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_client_run_watchers_mixin ( self , mock_client_cls , <EOL> mock_run_watchers ) : <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client_cls . return_value = mock_client <EOL> member_id = str ( uuid . uuid4 ( ) ) . encode ( '<STR_LIT:ascii>' ) <EOL> coord = coordination . get_coordinator ( self . FAKE_URL , member_id ) <EOL> coord . start ( ) <EOL> coord . run_watchers ( ) <EOL> self . assertTrue ( mock_run_watchers . called ) </s>
