Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
构建
流水线
作业
流水线计划
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
杨林
GitLab
提交
c31f1c4a
提交
c31f1c4a
编辑于
1 year ago
作者:
Jennifer Li
提交者:
Peter Leitzen
1 year ago
浏览文件
操作
下载
补丁
差异文件
Add expected rspec duration
上级
76104d08
No related branches found
No related tags found
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
spec/support/rspec_run_time.rb
+56
-9
56 个添加, 9 个删除
spec/support/rspec_run_time.rb
有
56 个添加
和
9 个删除
spec/support/rspec_run_time.rb
+
56
−
9
浏览文件 @
c31f1c4a
...
...
@@ -14,25 +14,72 @@ class RSpecFormatter < RSpec::Core::Formatters::BaseFormatter
def
start
(
_notification
)
@group_level
=
0
@rspec_test_suite_start_time
=
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
)
output
.
puts
"
\n
# Starting RSpec timer..."
output
.
puts
"
\n
# [RSpecRunTime] Starting RSpec timer..."
init_expected_duration_report
end
def
example_group_started
(
_notification
)
@start_time
=
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
)
if
@group_level
==
0
def
example_group_started
(
notification
)
if
@group_level
==
0
@current_group_start_time
=
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
)
file_path
=
spec_file_path
(
notification
)
output
.
puts
"# [RSpecRunTime] Starting example group
#{
file_path
}
.
#{
expected_run_time
(
file_path
)
}
"
end
@group_level
+=
1
end
def
example_group_finished
(
notification
)
@group_level
-=
1
if
@group_level
>
0
return
unless
@group_level
==
0
if
@group_level
==
0
file_path
=
spec_file_path
(
notification
)
time_now
=
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
)
actual_duration
=
time_now
-
@current_group_start_time
output
.
puts
"
\n
# [RSpecRunTime]
#{
file_path
}
took
#{
readable_duration
(
actual_duration
)
}
. "
\
"
#{
expected_run_time
(
file_path
)
}
"
end
output_elapsed_time
end
private
def
expected_duration_report
report_path
=
ENV
[
'KNAPSACK_RSPEC_SUITE_REPORT_PATH'
]
return
unless
report_path
&&
File
.
exist?
(
report_path
)
# rubocop:disable Gitlab/Json -- regular JSON is sufficient
@expected_duration_report
||=
JSON
.
parse
(
File
.
read
(
report_path
))
# rubocop:enable Gitlab/Json
end
alias_method
:init_expected_duration_report
,
:expected_duration_report
def
spec_file_path
(
notification
)
notification
.
group
.
metadata
[
:file_path
].
sub
(
'./'
,
''
)
end
def
expected_run_time
(
spec_file_path
)
return
''
unless
expected_duration_report
expected_duration
=
expected_duration_report
[
spec_file_path
]
return
"Missing expected duration from Knapsack report for
#{
spec_file_path
}
."
unless
expected_duration
"Expected to take
#{
readable_duration
(
expected_duration
)
}
."
end
def
output_elapsed_time
time_now
=
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
)
duration
=
time_now
-
@start_time
elapsed_time
=
time_now
-
@rspec_test_suite_start_time
elapsed_seconds
=
time_now
-
@rspec_test_suite_start_time
# skip the output unless the duration increased by at least 1 second
unless
@last_elapsed_seconds
.
nil?
||
elapsed_seconds
-
@last_elapsed_seconds
<
1
output
.
puts
"# [RSpecRunTime] RSpec elapsed time:
#{
readable_duration
(
elapsed_seconds
)
}
.
\n\n
"
end
output
.
puts
"
\n
# Example group
#{
notification
.
group
.
description
}
"
\
"(
#{
notification
.
group
.
metadata
[
:file_path
]
}
) took
#{
readable_duration
(
duration
)
}
."
output
.
puts
"# RSpec elapsed time:
#{
readable_duration
(
elapsed_time
)
}
.
\n\n
"
@last_elapsed_seconds
=
elapsed_seconds
end
end
end
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录