def test_geosquizzy_sockets(self): """ It testing listening to messages broadcasted by socket server(which receive it from geosquizzy algorithm client) by another client """ # Starting server thread self.socket_server.create_connection() server_thread = threading.Thread(target=self.socket_server.run) server_thread.daemon = True server_thread.start() second_client_data = queue.Queue() def second_client_listen(client, q): while True: data = client.read(1024) if data: q.put(str(data, 'utf-8')) q.task_done() else: break time.sleep(0.5) # Starting second client thread self.socket_client.connect() second_client_thread = threading.Thread(target=second_client_listen, args=(self.socket_client, second_client_data)) second_client_thread.start() # Starting geosquizzy socket client and algorithm execution self.geosquizzy = GeoSquizzy(**self.geojson_options) self.geosquizzy.start(geojson=self.data) # self.socket_client.disconnect() time.sleep(0.5) self.socket_client.disconnect() # Waiting for second_client to receive all data second_client_thread.join() # Waiting for second_client data second_client_data.join() # Getting second client second_client_res = [] while True: if not second_client_data.empty(): val = second_client_data.get() if bool(val): val = eval(val) second_client_res = second_client_res + val else: break # Getting geosquizzy result geosquizzy_res = self.geosquizzy.get_results() # Compare test org_len = len(geosquizzy_res) sock_len = 0 for x in geosquizzy_res: for y in second_client_res: if y['keys'] == x['keys']: sock_len += 1 break # [print(x, '\n') for x in geosquizzy_res] # [print(x, '\n') for x in second_client_res] # TODO difference is with one key, which is gathered after leaving features array self.assertTrue(org_len - 1 == sock_len)