def test_reregister_all_bails_when_control_register_raises(self): address = "ipc:///tmp/nmos-nodefacade.dummy.for.test" srv_type = "dummy_type" UUT = Facade(srv_type, address=address) self.mocks[ 'nmosnode.facade.Proxy'].return_value.srv_register.return_value = FAC_SUCCESS href = "http://dummy.example.com" proxy_path = "http://dummyproxy.example.com" UUT.register_service(href, proxy_path) resources = [("type0", "key0", "val0"), ("type0", "key1", "val1"), ("type2", "key2", "val2")] controls = [("id0", { "href": "href0" }), ("id1", { "href": "href1" }), ("id2", { "href": "href2" })] for res in resources: UUT.addResource(*res) UUT.addResource("receiver", "rkey", { "pipel_id": "DUMMY0", "pipeline_id": "DUMMY1", "dummy": "DUMMY2" }) expected_res_register_calls = [ mock.call(srv_type, mock.ANY, *res) for res in resources ] + [ mock.call(srv_type, mock.ANY, "receiver", "rkey", {"dummy": "DUMMY2"}) ] for con in controls: UUT.addControl(*con) UUT.ipc.res_register.reset_mock() UUT.ipc.control_register.reset_mock() UUT.ipc.control_register.side_effect = Exception with mock.patch('gevent.sleep'): UUT.reregister_all() self.assertIsNone(UUT.ipc) self.assertCountEqual( self.mocks['nmosnode.facade.Proxy'].return_value.res_register. mock_calls, expected_res_register_calls) self.assertEqual( len(self.mocks['nmosnode.facade.Proxy'].return_value. control_register.mock_calls), 1)
def test_reregister_all(self): address = "ipc:///tmp/nmos-nodefacade.dummy.for.test" srv_type = "dummy_type" UUT = Facade(srv_type, address=address) self.mocks[ 'nmosnode.facade.Proxy'].return_value.srv_register.return_value = FAC_SUCCESS href = "http://dummy.example.com" proxy_path = "http://dummyproxy.example.com" UUT.register_service(href, proxy_path) resources = [("type0", "key0", "val0"), ("type0", "key1", "val1"), ("type2", "key2", "val2")] controls = [("id0", { "href": "href0" }), ("id1", { "href": "href1" }), ("id2", { "href": "href2" })] for res in resources: UUT.addResource(*res) UUT.addResource("receiver", "rkey", { "pipel_id": "DUMMY0", "pipeline_id": "DUMMY1", "dummy": "DUMMY2" }) for con in controls: UUT.addControl(*con) expected_res_register_calls = [ mock.call(srv_type, mock.ANY, *res) for res in resources ] + [ mock.call(srv_type, mock.ANY, "receiver", "rkey", {"dummy": "DUMMY2"}) ] expected_control_register_calls = [ mock.call(srv_type, mock.ANY, *con) for con in controls ] UUT.ipc.res_register.reset_mock() UUT.ipc.control_register.reset_mock() UUT.reregister_all() self.assertFalse(UUT.reregister) self.assertTrue(UUT.srv_registered) self.assertCountEqual(UUT.ipc.res_register.mock_calls, expected_res_register_calls) self.assertCountEqual(UUT.ipc.control_register.mock_calls, expected_control_register_calls)