def test_match_line(self, mock_logger_error, sock_file): wm = WorkerMaster('sock://%s' % sock_file, filters=['grp1:aaa', 'grp1:bbb', 'grp2:ccc']) wm.run() try: wm.match_line('test line') mock_logger_error.assert_called_once_with('No workers connected - unable to process line "test line"') s1 = utils.socket_connect_from_text("sock://%s" % sock_file) f1 = s1.makefile('r') # ignore filter definitions for _ in range(3): f1.readline().strip() s2 = utils.socket_connect_from_text("sock://%s" % sock_file) f2 = s2.makefile('r') # ignore filter definitions for _ in range(3): f2.readline().strip() wm.match_line('test line2') wm.match_line('test line3') l1 = f1.readline().strip() l2 = f2.readline().strip() self.assertIn(l1, ('MATCH test line2', 'MATCH test line3', )) self.assertIn(l2, ('MATCH test line2', 'MATCH test line3', )) self.assertNotEqual(l1, l2) f1.close() s1.close() f2.close() s2.close() finally: wm.stop()
def test_match_line(self, mock_logger_error, sock_file): wm = WorkerMaster('sock://%s' % sock_file, filters=['grp1:aaa', 'grp1:bbb', 'grp2:ccc']) wm.run() try: wm.match_line('test line') mock_logger_error.assert_called_once_with( 'No workers connected - unable to process line "test line"') s1 = utils.socket_connect_from_text("sock://%s" % sock_file) f1 = s1.makefile('r') # ignore filter definitions for _ in range(3): f1.readline().strip() s2 = utils.socket_connect_from_text("sock://%s" % sock_file) f2 = s2.makefile('r') # ignore filter definitions for _ in range(3): f2.readline().strip() wm.match_line('test line2') wm.match_line('test line3') l1 = f1.readline().strip() l2 = f2.readline().strip() self.assertIn(l1, ( 'MATCH test line2', 'MATCH test line3', )) self.assertIn(l2, ( 'MATCH test line2', 'MATCH test line3', )) self.assertNotEqual(l1, l2) f1.close() s1.close() f2.close() s2.close() finally: wm.stop()
def __init__(self, server_at): self.server_at = server_at self.regex_worker = Regex() self.sock = utils.socket_connect_from_text(self.server_at) self.sock_f = self.sock.makefile(mode='r', encoding='UTF-8')