Skip to content

Commit

Permalink
同步代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobangyu committed Oct 27, 2023
1 parent f9e1796 commit 03e2d24
Show file tree
Hide file tree
Showing 16 changed files with 473 additions and 344 deletions.
2 changes: 2 additions & 0 deletions server/autotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ quanta.startup(function()
import("kernel/protobuf_mgr.lua")
import("robot/msg_mgr.lua")
import("autotest/robot_mgr.lua")
import("autotest/script_mgr.lua")
import("autotest/task_mgr.lua")
import("autotest/client.lua")
end)
41 changes: 20 additions & 21 deletions server/autotest/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local tinsert = table.insert
local update_mgr = quanta.get("update_mgr")
local http = quanta.get("http_client")
local robot_mgr = quanta.get("robot_mgr")
local task_mgr = quanta.get("task_mgr")
local script_mgr = quanta.get("script_mgr")

local BASE_API = environ.get("AUTO_TEST_API")
local USER_LOGIN = "/testtask/user_login"
Expand All @@ -21,7 +23,7 @@ local STATUS_LOGIN = 0
local STATUS_TASK = 1
local STATUS_ALLOT = 2
local STATUS_SCRIPT = 3
local STATUS_ROOT = 4
local STATUS_ROBOT = 4
local STATUS_RUN = 5
local STATUS_REPORT = 6
local STATUS_OVER = 7
Expand Down Expand Up @@ -121,12 +123,11 @@ function Client:load_task()
return
end
local resdata = json_decode(res)
self.task_list = {}
for _, task in pairs(resdata.list or {}) do
self.task_list[task.id] = task
task_mgr:create(task.task_id, task.task_name, task.srv_host, task.srv_port, task.robots, task.st_uuid)
self.st_loads[task.st_uuid] = false
end
if next(self.task_list) then
if task_mgr:get_count() > 0 then
self:set_status(STATUS_SCRIPT)
else
self:set_status(STATUS_ALLOT)
Expand All @@ -143,7 +144,7 @@ function Client:allot_task()
local resdata = json_decode(res)
if resdata.list and next(resdata.list) then
for _, task in pairs(resdata.list or {}) do
self.task_list[task.id] = task
task_mgr:create(task.task_id, task.task_name, task.srv_host, task.srv_port, task.robots)
self.st_loads[task.st_uuid] = false
end
end
Expand All @@ -161,36 +162,34 @@ function Client:load_script()
end
self.st_loads[uuid] = nil
local resdata = json_decode(res)
self.st_list[uuid] = json_decode(resdata.info.conf)
local script = json_decode(resdata.info.conf)
script_mgr:create(uuid, script)
for _, st_uuid in pairs(resdata.cases or {}) do
self.st_loads[st_uuid] = false
end
:: continue ::
end
end

if not next(self.st_loads) then
self:set_status(STATUS_ROOT)
self:set_status(STATUS_ROBOT)
end
end

-- 创建机器
function Client:create_root()
log_info("[Client][create_root]...")
for _,task in pairs(self.task_list) do
for i,open_id in pairs(task.robots) do
local ok = robot_mgr:create(task.srv_host, task.srv_port, open_id, task.task_id, task.st_uuid)
if not ok then
log_err("[Client][create_root] is fail(task_id:{} id:{})", task.task_id, open_id)
end
end
end
-- 初始化机器
function Client:robot()
log_info("[Client][robot]...")
task_mgr:init_robot()
self:set_status(STATUS_RUN)
end

-- 开始运行
function Client:run()
log_info("[Client][run]...")
if not robot_mgr then
log_info("[Client][run] is Fail(robot_mgr is nil)")
return
end
robot_mgr:update()
end

-- 上报结果
Expand All @@ -214,8 +213,8 @@ function Client:update()
self:allot_task()
elseif self.status == STATUS_SCRIPT then
self:load_script()
elseif self.status == STATUS_ROOT then
self:create_root()
elseif self.status == STATUS_ROBOT then
self:robot()
elseif self.status == STATUS_RUN then
self:run()
elseif self.status == STATUS_REPORT then
Expand Down
27 changes: 27 additions & 0 deletions server/autotest/field.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- 字段
local log_debug = logger.debug
local log_err = logger.err

local Node = class()
local prop = property(Node)
prop:accessor("name", "") -- name
prop:accessor("entity", "") -- 实体对象
prop:accessor("bind_type", "") -- 绑定类型(0 属性关联 1 协议关联 2 自定义)
prop:accessor("property_module", "") -- 属性-模块
prop:accessor("property_name", "") -- 属性-名称
prop:accessor("accord_msg_id", "") -- 协议消息id
prop:accessor("accord_field", "") -- 协议消息字段
prop:accessor("custom_language", "") -- 自定义语言
prop:accessor("custom_content", "") -- 自定义内容
function Node:__init(conf)
self.name = conf.name
self.bind_type = conf.bind_type
self.entity = conf.entity
self.property_module = conf.property.module
self.property_name = conf.property.name
self.accord_msg_id = conf.accord.msg_id
self.accord_field = conf.accord.fields
self.custom_language = conf.custom.language
self.custom_content = conf.custom.content
end
return Node
26 changes: 26 additions & 0 deletions server/autotest/line.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- 流程
local log_debug = logger.debug
local log_err = logger.err

local Line = class()
local prop = property(Line)
prop:accessor("from", nil) -- 起始节点
prop:accessor("from_name", nil) -- 起始节点名称
prop:accessor("to", nil) -- 目标节点
prop:accessor("to_name", nil) -- 目标节点名称
prop:accessor("operator", "") -- 运算符
prop:accessor("value", "") -- 运算值
prop:accessor("done", false) -- 完成标记(未完成 false 完成 true)
function Line:__init(conf)
self.from = conf.from
self.from_name = conf.from_name
self.to = conf.to
self.to_name = conf.to_name
self.operator = conf.operator
self.value = conf.value
end

function Line:is_done()
return self.done
end
return Line
120 changes: 120 additions & 0 deletions server/autotest/node.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
-- 节点
local log_debug = logger.debug
local log_err = logger.err

local Field = import("autotest/field.lua")

local Node = class()
local prop = property(Node)
prop:accessor("id", "") -- id
prop:accessor("name", "") -- 名称
prop:accessor("type", 0) -- 类型(req、ntf、case、if、switch、gm、delayer)
prop:accessor("msg_id", 0) -- 消息号
prop:accessor("msg_name", "") -- 消息名称
prop:accessor("case_uuid", "") -- 用例id
prop:accessor("case_name", "") -- 用例名称
prop:accessor("cond_operator", "") -- 条件运算符
prop:accessor("cond_value", 0) -- 条件值
prop:accessor("gm_command", "") -- gm命令
prop:accessor("delayer_time", 0) -- 延迟时间
prop:accessor("fields", {}) -- 字段
prop:accessor("conds", {}) -- 条件
prop:accessor("in_node", {}) -- 输入节点
prop:accessor("out_node", {}) -- 输出节点

function Node:__init(conf)
self.id = conf.id
self.name = conf.name
self.type = conf.type
self.msg_id = conf.form.accord.id
self.case_uuid = conf.form.case.uuid
self.case_name = conf.form.case.name
self.cond_operator = conf.form.cond.operator
self.cond_value = conf.form.cond.cond_value
self.gm_command = conf.form.gm.command
self.delayer_time = conf.form.delayer.time
self:init_fields(conf)
self:init_in_node(conf)
self:init_out_node(conf)
self:init_conds(conf)
end

-- 初始化字段
function Node:init_fields(conf)
-- 字段数据
for _, item in pairs(conf.form.dSourceFormMap) do
local field = Field(item)
self.fields[field:get_name()] = field
end
end

-- 初始化输入节点
function Node:init_in_node(conf)
for key,line in pairs(conf.inLine) do
local node = {
from = line.from,
to = line.to,
from_name = line.from_name,
to_name = line.to_name,
}
if line.operator then
node.operator = line.operator
node.value = line.value
node.label = line.label
end
self.in_node[key] = node
end
end

-- 初始化输出节点
function Node:init_out_node(conf)
for key,line in pairs(conf.outLine) do
local node = {
from = line.from,
to = line.to,
from_name = line.from_name,
to_name = line.to_name,
}
if line.operator then
node.operator = line.operator
node.value = line.value
node.label = line.label
end
self.out_node[key] = node
end
end

-- 初始化条件
function Node:init_conds(conf)
self.conds = Field(conf.form.dSourceForm)
end

-- 获取发送数据包
function Node:send_data(robot)
local data = {}
for name,field in pairs(self.fields) do
local bind_type = 0
local value = nil
-- 属性关联
if bind_type == 0 then
data[name] = value
-- 协议关联
elseif bind_type == 1 then
data[name] = robot:msg_package(field.accord_msg_id)
if not data[name] then
log_err("[Node][send_data] msg is error, robot:{} task_id:{} name:{} bind_type:{} msg:{}",
robot:get_openid(), robot:get_task_id(), name, bind_type, data[name])
return false
end
-- 自定义
elseif bind_type == 2 then
else
log_err("[Node][send_data] bind_type is error, robot:{} task_id:{} name:{} bind_type:{}",
robot:get_openid(), robot:get_task_id(), name, bind_type)
return false
end
end
return data
end

return Node
Loading

0 comments on commit 03e2d24

Please sign in to comment.