Toolchain autotest reframing debugger interfaces

Adding debugger & runtime domain interfaces and rewrite testcases for
Simplification

Issue:       #IAQCVP
Signed-off-by: huangtianzhi <huangtianzhi1@huawei.com>
This commit is contained in:
huangtianzhi 2024-09-20 09:40:08 +08:00
parent 0ca3ddde07
commit 0b8523265e
6 changed files with 477 additions and 418 deletions

View File

@ -0,0 +1,216 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2024 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description: Python Debugger Domain Interfaces
"""
import json
import logging
from http.client import responses
from aw import communicate_with_debugger_server, Utils
from aw.cdp import debugger
from aw.types import ThreadConnectionInfo, ProtocolType
class DebuggerImpl(object):
def __init__(self, id_generator):
self.dispatch_table = {"enable": (self.enable, ProtocolType.send),
"disable": (self.disable, ProtocolType.send),
"resume": (self.resume, ProtocolType.send),
"removeBreakpointsByUrl": (self.remove_breakpoints_by_url, ProtocolType.send),
"getPossibleAndSetBreakpointsByUrl": (self.get_possible_and_set_breakpoints_by_url,
ProtocolType.send),
"stepOver": (self.step_over, ProtocolType.send),
"stepInto": (self.step_into, ProtocolType.send),
"scriptParsed": (self.script_parsed, ProtocolType.recv),
"paused": (self.paused, ProtocolType.recv),
"stepOut": (self.step_out, ProtocolType.send)}
self.id_generator = id_generator
@classmethod
async def connect_to_debugger_server(cls, websocket, pid, is_main=True):
if is_main:
send_msg = {"type": "connected"}
await websocket.send_msg_to_connect_server(send_msg)
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'addInstance'
assert response['instanceId'] == 0, logging.error('InstanceId of the main thread is not 0')
assert response['tid'] == pid
else:
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'addInstance'
assert response['instanceId'] != 0
assert response['tid'] != pid
assert 'workerThread_' in response['name']
instance_id = await websocket.get_instance()
send_queue = websocket.to_send_msg_queues[instance_id]
recv_queue = websocket.received_msg_queues[instance_id]
connection = ThreadConnectionInfo(instance_id, send_queue, recv_queue)
return connection
@classmethod
async def destroy_instance(cls, websocket):
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
return response
@classmethod
async def enable(cls, message_id, connection, websocket, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.enable(), message_id)
while response.startswith('{"method":"Debugger.scriptParsed"'):
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response == {"id": message_id, "result": {"debuggerId": "0", "protocols": Utils.get_custom_protocols()}}
@classmethod
async def disable(cls, message_id, connection, websocket, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.disable(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
@classmethod
async def script_parsed(cls, connection, websocket, params=None):
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
return response
@classmethod
async def paused(cls, connection, websocket, params=None):
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
return response
@classmethod
async def resume(cls, message_id, connection, websocket, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
@classmethod
async def remove_breakpoints_by_url(cls, message_id, connection, websocket=None, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.remove_breakpoints_by_url(params.url), message_id)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
@classmethod
async def get_possible_and_set_breakpoints_by_url(cls, message_id, connection, websocket=None, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.get_possible_and_set_breakpoint_by_url(params.locations),
message_id)
response = json.loads(response)
assert response['id'] == message_id
return response
@classmethod
async def step_over(cls, message_id, connection, websocket, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.step_over(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
@classmethod
async def step_out(cls, message_id, connection, websocket, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.step_out(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
@classmethod
async def step_into(cls, message_id, connection, websocket, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
debugger.step_into(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(connection.instance_id,
connection.received_msg_queue)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
async def send(self, protocol_name, connection, websocket, params=None):
protocol = self._check_and_parse_protocol(protocol_name)
if self.dispatch_table.get(protocol) is not None:
if self.dispatch_table.get(protocol)[1] != ProtocolType.send:
raise AssertionError("DebuggerImpl send ProtocolType inconsistent: Protocol {}, calling {}, should be {}"
.format(protocol_name, "send", self.dispatch_table.get(protocol)[1]))
message_id = next(self.id_generator)
return await self.dispatch_table.get(protocol)[0](message_id, connection, websocket, params)
async def recv(self, protocol_name, connection, websocket, params=None):
protocol = self._check_and_parse_protocol(protocol_name)
if self.dispatch_table.get(protocol) is not None:
if self.dispatch_table.get(protocol)[1] != ProtocolType.recv:
raise AssertionError("DebuggerImpl recv ProtocolType inconsistent: Protocol {}, calling {}, should be {}"
.format(protocol_name, "recv", self.dispatch_table.get(protocol)[1]))
return await self.dispatch_table.get(protocol)[0](connection, websocket, params)
def _check_and_parse_protocol(self, protocol_name):
res = protocol_name.split('.')
if len(res) != 2:
raise AssertionError("DebuggerImpl parse protocol name error: protocol_name {} is invalid"
.format(protocol_name))
domain, protocol = res[0], res[1]
if domain != 'Debugger':
raise AssertionError("DebuggerImpl parse protocol name error: protocol_name {} has the wrong domain"
.format(protocol_name))
if protocol not in self.dispatch_table:
raise AssertionError("DebuggerImpl parse protocol name error: protocol_name {} has not been defined"
.format(protocol_name))
return protocol

View File

@ -0,0 +1,98 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2024 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description: Python Runtime Domain Interfaces
"""
import json
from aw import communicate_with_debugger_server
from aw.cdp import runtime
from aw.types import ProtocolType
class RuntimeImpl(object):
def __init__(self, id_generator):
self.dispatch_table = {"enable": (self.enable, ProtocolType.send),
"runIfWaitingForDebugger": (self.run_if_waiting_for_debugger, ProtocolType.send),
"getProperties": (self.get_properties, ProtocolType.send)}
self.id_generator = id_generator
@classmethod
async def enable(cls, message_id, connection, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
runtime.enable(), message_id)
response = json.loads(response)
assert response == {"id": message_id, "result": {"protocols": []}}
return response
@classmethod
async def run_if_waiting_for_debugger(cls, message_id, connection, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
runtime.run_if_waiting_for_debugger(), message_id)
response = json.loads(response)
assert response == {"id": message_id, "result": {}}
return response
@classmethod
async def get_properties(cls, message_id, connection, params=None):
response = await communicate_with_debugger_server(connection.instance_id,
connection.send_msg_queue,
connection.received_msg_queue,
runtime.get_properties(object_id=params.object_id,
own_properties=params.own_properties,
accessor_properties_only=params.accessor_properties_only,
generate_preview=params.generate_preview), message_id)
response = json.loads(response)
assert response["id"] == message_id
return response
async def send(self, protocol_name, connection, params=None):
protocol = self._check_and_parse_protocol(protocol_name)
if self.dispatch_table.get(protocol) is not None:
if self.dispatch_table.get(protocol)[1] != ProtocolType.send:
raise AssertionError("RuntimeImpl send ProtocolType inconsistent: Protocol {}, calling {}, should be {}"
.format(protocol_name, "send", self.dispatch_table.get(protocol)[1]))
message_id = next(self.id_generator)
return await self.dispatch_table.get(protocol)[0](message_id, connection, params)
async def recv(self, protocol_name, connection, params=None):
protocol = self._check_and_parse_protocol(protocol_name)
if self.dispatch_table.get(protocol) is not None:
if self.dispatch_table.get(protocol)[1] != ProtocolType.recv:
raise AssertionError("RuntimeImpl recv ProtocolType inconsistent: Protocol {}, calling {}, should be {}"
.format(protocol_name, "recv", self.dispatch_table.get(protocol)[1]))
message_id = next(self.id_generator)
return await self.dispatch_table.get(protocol)[0](message_id, connection, params)
def _check_and_parse_protocol(self, protocol_name):
res = protocol_name.split('.')
if len(res) != 2:
raise AssertionError("RuntimeImpl parse protocol name error: protocol_name {} is invalid"
.format(protocol_name))
domain, protocol = res[0], res[1]
if domain != 'Runtime':
raise AssertionError("RuntimeImpl parse protocol name error: protocol_name {} has the wrong domain"
.format(protocol_name))
if protocol not in self.dispatch_table:
raise AssertionError("RuntimeImpl parse protocol name error: protocol_name {} has not been defined"
.format(protocol_name))
return protocol

View File

@ -17,7 +17,7 @@ limitations under the License.
Description: Python CDP Debugger.
"""
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Optional, List
@ -34,6 +34,16 @@ class BreakLocationUrl:
return json
@dataclass
class RemoveBreakpointsUrl:
url: str = ""
@dataclass
class SetBreakpointsLocations:
locations: list = field(default_factory=list)
def enable(max_scripts_cache_size: Optional[float] = None):
command = {'method': 'Debugger.enable'}
if max_scripts_cache_size:

View File

@ -16,10 +16,18 @@ limitations under the License.
Description: Python CDP Runtime.
"""
from dataclasses import dataclass
from typing import Optional
@dataclass
class GetPropertiesParams:
object_id: str = ""
own_properties: bool = True
accessor_properties_only: bool = False
generate_preview: bool = True
def enable():
command = {'method': 'Runtime.enable'}
return command

34
test/autotest/aw/types.py Normal file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2024 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description: Data Transferring Classes & Types.
"""
import asyncio
from dataclasses import dataclass
from enum import Enum
@dataclass(init=True)
class ThreadConnectionInfo:
instance_id: int
send_msg_queue: asyncio.Queue
received_msg_queue: asyncio.Queue
class ProtocolType(Enum):
send = "send",
recv = "recv"

View File

@ -17,7 +17,6 @@ limitations under the License.
Description: Scenario test case.
"""
import json
import logging
import os
import time
@ -26,8 +25,8 @@ import pytest
from aw import Application
from aw import Utils
from aw import communicate_with_debugger_server
from aw import debugger, runtime
from aw.api import debugger_api, runtime_api
@pytest.mark.debug
@ -72,6 +71,8 @@ class TestDebug01:
self.hilog_process, self.write_thread = Utils.save_hilog(log_path=self.log_path,
file_name=self.hilog_file_name,
debug_on=True)
self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator)
self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator)
def teardown_method(self):
Application.uninstall(self.config['bundle_name'])
@ -103,289 +104,151 @@ class TestDebug01:
################################################################################################################
# main thread: connect the debugger server
################################################################################################################
send_msg = {"type": "connected"}
await websocket.send_msg_to_connect_server(send_msg)
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'addInstance'
assert response['instanceId'] == 0, logging.error('instance id of the main thread not equal to 0')
assert response['tid'] == self.config['pid']
main_thread_instance_id = await websocket.get_instance()
main_thread_to_send_queue = websocket.to_send_msg_queues[main_thread_instance_id]
main_thread_received_queue = websocket.received_msg_queues[main_thread_instance_id]
logging.info(f'Connect to the debugger server of instance: {main_thread_instance_id}')
main_thread = await self.debugger_impl.connect_to_debugger_server(websocket, self.config['pid'], True)
logging.info(f'Connect to the debugger server of instance: {main_thread.instance_id}')
################################################################################################################
# main thread: Runtime.enable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
runtime.enable(), message_id)
assert json.loads(response) == {"id": message_id, "result": {"protocols": []}}
await self.runtime_impl.send("Runtime.enable", main_thread)
################################################################################################################
# main thread: Debugger.enable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.enable(), message_id)
assert json.loads(response) == {"id": message_id, "result": {"debuggerId": "0",
"protocols": Utils.get_custom_protocols()}}
await self.debugger_impl.send("Debugger.enable", main_thread, websocket)
################################################################################################################
# main thread: Runtime.runIfWaitingForDebugger
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
runtime.run_if_waiting_for_debugger(), message_id)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", main_thread)
################################################################################################################
# main thread: Debugger.scriptParsed
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.scriptParsed'
response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread, websocket)
assert response['params']['url'] == self.config['file_path']['entry_ability']
assert response['params']['endLine'] == 0
################################################################################################################
# main thread: Debugger.paused
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['entry_ability']
assert response['params']['reason'] == 'Break on start'
################################################################################################################
# main thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", main_thread, websocket)
################################################################################################################
# main thread: Debugger.scriptParsed
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.scriptParsed'
response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread, websocket)
assert response['params']['url'] == self.config['file_path']['index']
assert response['params']['endLine'] == 0
################################################################################################################
# main thread: Debugger.paused
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['reason'] == 'Break on start'
################################################################################################################
# main thread: Debugger.removeBreakpointsByUrl
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.remove_breakpoints_by_url(
self.config['file_path']['index']),
message_id)
assert json.loads(response) == {"id": message_id, "result": {}}
params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index'])
await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, websocket, params)
################################################################################################################
# main thread: Debugger.getPossibleAndSetBreakpointByUrl
################################################################################################################
message_id = next(self.id_generator)
locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=12),
debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=53),
debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=57)]
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.get_possible_and_set_breakpoint_by_url(locations),
message_id)
response = json.loads(response)
assert response['id'] == message_id
params = debugger.SetBreakpointsLocations(locations)
response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl",
main_thread, websocket, params)
assert response['result']['locations'][0]['id'] == 'id:12:0:' + self.config['file_path']['index']
assert response['result']['locations'][1]['id'] == 'id:53:0:' + self.config['file_path']['index']
assert response['result']['locations'][2]['id'] == 'id:57:0:' + self.config['file_path']['index']
################################################################################################################
# main thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", main_thread, websocket)
################################################################################################################
# main thread: Debugger.paused, hit breakpoint
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['hitBreakpoints'] == ['id:12:4:' + self.config['file_path']['index']]
################################################################################################################
# main thread: Debugger.stepOut
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.step_out(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
await self.debugger_impl.send("Debugger.stepOut", main_thread, websocket)
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['hitBreakpoints'] == ['id:12:4:' + self.config['file_path']['index']]
################################################################################################################
# worker thread: connect the debugger server
################################################################################################################
workers_num = 2
worker_instances_id = []
worker_thread_to_send_queues = []
worker_thread_received_queues = []
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'addInstance'
assert response['instanceId'] != 0
assert response['tid'] != self.config['pid']
assert 'workerThread_' in response['name']
worker_instance_id = await websocket.get_instance()
worker_instances_id.append(worker_instance_id)
worker_thread_to_send_queues.append(websocket.to_send_msg_queues[worker_instance_id])
worker_thread_received_queues.append(websocket.received_msg_queues[worker_instance_id])
logging.info(f'Connect to the debugger server of instance: {worker_instance_id}')
worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(websocket, self.config['pid'], False)
logging.info(f'Connect to the debugger server of instance: {worker_thread_1.instance_id}')
################################################################################################################
# main thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", main_thread, websocket)
################################################################################################################
# worker thread: connect the debugger server
################################################################################################################
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'addInstance'
assert response['instanceId'] != 0
assert response['tid'] != self.config['pid']
assert 'workerThread_' in response['name']
worker_instance_id = await websocket.get_instance()
worker_instances_id.append(worker_instance_id)
worker_thread_to_send_queues.append(websocket.to_send_msg_queues[worker_instance_id])
worker_thread_received_queues.append(websocket.received_msg_queues[worker_instance_id])
logging.info(f'Connect to the debugger server of instance: {worker_instance_id}')
worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(websocket, self.config['pid'], False)
logging.info(f'Connect to the debugger server of instance: {worker_thread_2.instance_id}')
################################################################################################################
# worker thread: Runtime.enable
################################################################################################################
for i in range(workers_num):
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[i],
worker_thread_to_send_queues[i],
worker_thread_received_queues[i],
runtime.enable(), message_id)
assert json.loads(response) == {"id": message_id, "result": {"protocols": []}}
await self.runtime_impl.send("Runtime.enable", worker_thread_1)
await self.runtime_impl.send("Runtime.enable", worker_thread_2)
################################################################################################################
# worker thread: Debugger.enable
################################################################################################################
for i in range(workers_num):
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[i],
worker_thread_to_send_queues[i],
worker_thread_received_queues[i],
debugger.enable(), message_id)
assert json.loads(response) == {"id": message_id, "result": {"debuggerId": "0",
"protocols": Utils.get_custom_protocols()}}
await self.debugger_impl.send("Debugger.enable", worker_thread_1, websocket)
await self.debugger_impl.send("Debugger.enable", worker_thread_2, websocket)
################################################################################################################
# worker thread: Runtime.runIfWaitingForDebugger
################################################################################################################
for i in range(workers_num):
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[i],
worker_thread_to_send_queues[i],
worker_thread_received_queues[i],
runtime.run_if_waiting_for_debugger(), message_id)
assert json.loads(response) == {"id": message_id, "result": {}}
# worker thread: Debugger.scriptParsed
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[i],
worker_thread_received_queues[i])
response = json.loads(response)
assert response['method'] == 'Debugger.scriptParsed'
assert response['params']['url'] == self.config['file_path']['worker']
assert response['params']['endLine'] == 0
# worker thread: Debugger.paused
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[i],
worker_thread_received_queues[i])
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'Break on start'
# worker1 thread: Runtime.runIfWaitingForDebugger
await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_1)
# worker1 thread: Debugger.scriptParsed
response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_1, websocket)
assert response['params']['url'] == self.config['file_path']['worker']
assert response['params']['endLine'] == 0
# worker1 thread: Debugger.paused
response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'Break on start'
# worker2 thread: Runtime.runIfWaitingForDebugger
await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2)
# worker2 thread: Debugger.scriptParsed
response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2, websocket)
assert response['params']['url'] == self.config['file_path']['worker']
assert response['params']['endLine'] == 0
# worker2 thread: Debugger.paused
response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'Break on start'
################################################################################################################
# worker thread: Debugger.removeBreakpointsByUrl
################################################################################################################
for i in range(workers_num):
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[i],
worker_thread_to_send_queues[i],
worker_thread_received_queues[i],
debugger.remove_breakpoints_by_url(
self.config['file_path']['worker']),
message_id)
assert json.loads(response) == {"id": message_id, "result": {}}
params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker'])
await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, websocket, params)
await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_2, websocket, params)
################################################################################################################
# worker thread: Debugger.getPossibleAndSetBreakpointByUrl
################################################################################################################
for i in range(workers_num):
message_id = next(self.id_generator)
locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)]
response = await communicate_with_debugger_server(worker_instances_id[i],
worker_thread_to_send_queues[i],
worker_thread_received_queues[i],
debugger.get_possible_and_set_breakpoint_by_url(
locations),
message_id)
response = json.loads(response)
assert response['id'] == message_id
assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker']
locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)]
params = debugger.SetBreakpointsLocations(locations)
response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl",
worker_thread_1, websocket, params)
assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker']
response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl",
worker_thread_2, websocket, params)
assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker']
################################################################################################################
# worker thread: Debugger.resume
################################################################################################################
for i in range(workers_num):
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[i],
worker_thread_to_send_queues[i],
worker_thread_received_queues[i],
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[i],
worker_thread_received_queues[i])
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", worker_thread_1, websocket)
await self.debugger_impl.send("Debugger.resume", worker_thread_2, websocket)
################################################################################################################
# main thread: click on the screen
################################################################################################################
@ -393,51 +256,25 @@ class TestDebug01:
################################################################################################################
# main thread: Debugger.paused, hit breakpoint
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['hitBreakpoints'] == ['id:53:16:' + self.config['file_path']['index']]
################################################################################################################
# worker thread: destroy instance
################################################################################################################
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
# worker thread 2 destroyed
response = await self.debugger_impl.destroy_instance(websocket)
assert response['type'] == 'destroyInstance'
if response['instanceId'] == worker_instances_id[0]:
worker_instances_id[0] = worker_instances_id[1]
worker_thread_to_send_queues[0] = worker_thread_to_send_queues[1]
worker_thread_received_queues[0] = worker_thread_received_queues[1]
################################################################################################################
# main thread: Debugger.stepInto
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.step_into(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response)['method'] == 'Debugger.paused'
await self.debugger_impl.send("Debugger.stepInto", main_thread, websocket)
await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
################################################################################################################
# main thread: Runtime.getProperties
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
runtime.get_properties(object_id='0',
own_properties=True,
accessor_properties_only=False,
generate_preview=True),
message_id)
response = json.loads(response)
assert response['id'] == message_id
params = runtime.GetPropertiesParams('0', True, False, True)
response = await self.runtime_impl.send("Runtime.getProperties", main_thread, params)
assert response['result']['result'][0]['name'] == 'set message'
assert response['result']['result'][0]['value']['type'] == 'function'
assert response['result']['result'][1]['name'] == 'newValue'
@ -445,155 +282,72 @@ class TestDebug01:
################################################################################################################
# main thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", main_thread, websocket)
################################################################################################################
# main thread: Debugger.paused, hit breakpoint
################################################################################################################
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['hitBreakpoints'] == ['id:57:20:' + self.config['file_path']['index']]
################################################################################################################
# worker thread: connect the debugger server
################################################################################################################
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'addInstance'
assert response['instanceId'] != 0
assert response['tid'] != self.config['pid']
assert 'workerThread_' in response['name']
worker_instances_id[1] = await websocket.get_instance()
worker_thread_to_send_queues[1] = websocket.to_send_msg_queues[worker_instances_id[1]]
worker_thread_received_queues[1] = websocket.received_msg_queues[worker_instances_id[1]]
logging.info(f'Connect to the debugger server of instance: {worker_instances_id[1]}')
worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(websocket, self.config['pid'], False)
logging.info(f'Connect to the debugger server of instance: {worker_thread_2.instance_id}')
################################################################################################################
# worker thread: Runtime.enable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
runtime.enable(), message_id)
assert json.loads(response) == {"id": message_id, "result": {"protocols": []}}
await self.runtime_impl.send("Runtime.enable", worker_thread_2)
################################################################################################################
# worker thread: Debugger.enable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
debugger.enable(), message_id)
assert json.loads(response) == {"id": message_id, "result": {"debuggerId": "0",
"protocols": Utils.get_custom_protocols()}}
await self.debugger_impl.send("Debugger.enable", worker_thread_2, websocket)
################################################################################################################
# worker thread: Runtime.runIfWaitingForDebugger
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
runtime.run_if_waiting_for_debugger(), message_id)
assert json.loads(response) == {"id": message_id, "result": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[1],
worker_thread_received_queues[1])
response = json.loads(response)
assert response['method'] == 'Debugger.scriptParsed'
await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2)
response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2, websocket)
assert response['params']['url'] == self.config['file_path']['worker']
assert response['params']['endLine'] == 0
response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'Break on start'
################################################################################################################
# worker thread: Debugger.removeBreakpointsByUrl
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
debugger.remove_breakpoints_by_url(
self.config['file_path']['worker']),
message_id)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'Break on start'
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[1],
worker_thread_received_queues[1])
assert json.loads(response) == {"id": message_id, "result": {}}
params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker'])
await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_2, websocket, params)
################################################################################################################
# worker thread: Debugger.getPossibleAndSetBreakpointByUrl
################################################################################################################
message_id = next(self.id_generator)
locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)]
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
debugger.get_possible_and_set_breakpoint_by_url(locations),
message_id)
response = json.loads(response)
assert response['id'] == message_id
params = debugger.SetBreakpointsLocations(locations)
response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl",
worker_thread_2, websocket, params)
assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker']
################################################################################################################
# worker thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[1],
worker_thread_received_queues[1])
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", worker_thread_2, websocket)
################################################################################################################
# main thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", main_thread, websocket)
# main thread: Debugger.paused
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['reason'] == 'other'
assert response['params']['hitBreakpoints'] == ['id:57:20:' + self.config['file_path']['index']]
# worker thread: Debugger.paused
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[0],
worker_thread_received_queues[0])
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'other'
assert response['params']['hitBreakpoints'] == ['id:11:4:' + self.config['file_path']['worker']]
################################################################################################################
# worker thread: Runtime.getProperties
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[0],
worker_thread_to_send_queues[0],
worker_thread_received_queues[0],
runtime.get_properties(object_id='0',
own_properties=True,
accessor_properties_only=False,
generate_preview=True),
message_id)
response = json.loads(response)
assert response['id'] == message_id
params = runtime.GetPropertiesParams('0', True, False, True)
response = await self.runtime_impl.send("Runtime.getProperties", worker_thread_1, params)
assert response['result']['result'][0]['name'] == ''
assert response['result']['result'][0]['value']['type'] == 'function'
assert response['result']['result'][1]['name'] == 'e'
@ -601,114 +355,53 @@ class TestDebug01:
################################################################################################################
# worker thread: Debugger.stepOut
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[0],
worker_thread_to_send_queues[0],
worker_thread_received_queues[0],
debugger.step_out(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[0],
worker_thread_received_queues[0])
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.stepOut", worker_thread_1, websocket)
################################################################################################################
# worker thread: Debugger.disable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[0],
worker_thread_to_send_queues[0],
worker_thread_received_queues[0],
debugger.disable(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[0],
worker_thread_received_queues[0])
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.disable", worker_thread_1, websocket)
################################################################################################################
# main thread: Debugger.stepOver
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.step_over(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.stepOver", main_thread, websocket)
# main thread: Debugger.paused
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", main_thread, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index']
assert response['params']['reason'] == 'other'
assert response['params']['hitBreakpoints'] == []
# worker thread: Debugger.paused
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[1],
worker_thread_received_queues[1])
response = json.loads(response)
assert response['method'] == 'Debugger.paused'
response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2, websocket)
assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker']
assert response['params']['reason'] == 'other'
assert response['params']['hitBreakpoints'] == ['id:11:4:' + self.config['file_path']['worker']]
################################################################################################################
# worker thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[1],
worker_thread_received_queues[1])
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", worker_thread_2, websocket)
################################################################################################################
# worker thread: Debugger.disable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(worker_instances_id[1],
worker_thread_to_send_queues[1],
worker_thread_received_queues[1],
debugger.disable(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(worker_instances_id[1],
worker_thread_received_queues[1])
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.disable", worker_thread_2, websocket)
################################################################################################################
# main thread: Debugger.resume
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.resume(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.resume", main_thread, websocket)
################################################################################################################
# worker thread: destroy instance
################################################################################################################
for i in range(workers_num):
response = await websocket.recv_msg_of_connect_server()
response = json.loads(response)
assert response['type'] == 'destroyInstance'
assert response['instanceId'] in worker_instances_id
response = await self.debugger_impl.destroy_instance(websocket)
assert response['type'] == 'destroyInstance'
assert response['instanceId'] != self.config['pid']
response = await self.debugger_impl.destroy_instance(websocket)
assert response['type'] == 'destroyInstance'
assert response['instanceId'] != self.config['pid']
################################################################################################################
# main thread: Debugger.disable
################################################################################################################
message_id = next(self.id_generator)
response = await communicate_with_debugger_server(main_thread_instance_id,
main_thread_to_send_queue,
main_thread_received_queue,
debugger.disable(), message_id)
assert json.loads(response) == {"method": "Debugger.resumed", "params": {}}
response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id,
main_thread_received_queue)
assert json.loads(response) == {"id": message_id, "result": {}}
await self.debugger_impl.send("Debugger.disable", main_thread, websocket)
################################################################################################################
# close the websocket connections
################################################################################################################
await websocket.send_msg_to_debugger_server(main_thread_instance_id, main_thread_to_send_queue, 'close')
await websocket.send_msg_to_debugger_server(main_thread.instance_id, main_thread.send_msg_queue, 'close')
await websocket.send_msg_to_connect_server('close')
################################################################################################################