Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6bb1a2ab
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6bb1a2ab
编写于
11月 23, 2018
作者:
H
Heinrich Lee Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update tests
上级
3b49a794
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
82 deletion
+17
-82
spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb
spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb
+13
-81
spec/tasks/cache/clear/redis_spec.rb
spec/tasks/cache/clear/redis_spec.rb
+4
-1
未找到文件。
spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb
浏览文件 @
6bb1a2ab
...
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
Cache
::
Ci
::
ProjectPipelineStatus
,
:clean_gitlab_redis_cache
do
let!
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:pipeline_status
)
{
described_class
.
new
(
project
)
}
let
(
:cache_key
)
{
described_class
.
cache_key_for_project
(
project
)
}
let
(
:cache_key
)
{
pipeline_status
.
cache_key
}
describe
'.load_for_project'
do
it
"loads the status"
do
...
...
@@ -14,94 +14,24 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do
end
describe
'loading in batches'
do
let
(
:status
)
{
'success'
}
let
(
:sha
)
{
'424d1b73bc0d3cb726eb7dc4ce17a4d48552f8c6'
}
let
(
:ref
)
{
'master'
}
let
(
:pipeline_info
)
{
{
sha:
sha
,
status:
status
,
ref:
ref
}
}
let!
(
:project_without_status
)
{
create
(
:project
,
:repository
)
}
describe
'.load_in_batch_for_projects'
do
it
'
pre
loads pipeline_status on projects'
do
it
'loads pipeline_status on projects'
do
described_class
.
load_in_batch_for_projects
([
project
])
# Don't call the accessor that would lazy load the variable
expect
(
project
.
instance_variable_get
(
'@pipeline_status'
)).
to
be_a
(
described_class
)
end
describe
'without a status in redis_cache'
do
it
'loads the status from a commit when it was not in redis_cache'
do
empty_status
=
{
sha:
nil
,
status:
nil
,
ref:
nil
}
fake_pipeline
=
described_class
.
new
(
project_without_status
,
pipeline_info:
empty_status
,
loaded_from_cache:
false
)
expect
(
described_class
).
to
receive
(
:new
)
.
with
(
project_without_status
,
pipeline_info:
empty_status
,
loaded_from_cache:
false
)
.
and_return
(
fake_pipeline
)
expect
(
fake_pipeline
).
to
receive
(
:load_from_project
)
expect
(
fake_pipeline
).
to
receive
(
:store_in_cache
)
described_class
.
load_in_batch_for_projects
([
project_without_status
])
end
it
'only connects to redis twice'
do
expect
(
Gitlab
::
Redis
::
Cache
).
to
receive
(
:with
).
exactly
(
2
).
and_call_original
described_class
.
load_in_batch_for_projects
([
project_without_status
])
expect
(
project_without_status
.
pipeline_status
).
not_to
be_nil
end
end
describe
'when a status was cached in redis_cache'
do
before
do
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
redis
.
mapped_hmset
(
cache_key
,
{
sha:
sha
,
status:
status
,
ref:
ref
})
end
end
it
'loads the correct status'
do
described_class
.
load_in_batch_for_projects
([
project
])
pipeline_status
=
project
.
instance_variable_get
(
'@pipeline_status'
)
expect
(
pipeline_status
.
sha
).
to
eq
(
sha
)
expect
(
pipeline_status
.
status
).
to
eq
(
status
)
expect
(
pipeline_status
.
ref
).
to
eq
(
ref
)
end
it
'only connects to redis_cache once'
do
expect
(
Gitlab
::
Redis
::
Cache
).
to
receive
(
:with
).
exactly
(
1
).
and_call_original
project_pipeline_status
=
project
.
instance_variable_get
(
'@pipeline_status'
)
described_class
.
load_in_batch_for_projects
([
project
])
expect
(
project
.
pipeline_status
).
not_to
be_nil
end
it
"doesn't load the status separatly"
do
expect_any_instance_of
(
described_class
).
not_to
receive
(
:load_from_project
)
expect_any_instance_of
(
described_class
).
not_to
receive
(
:load_from_cache
)
described_class
.
load_in_batch_for_projects
([
project
])
end
expect
(
project_pipeline_status
).
to
be_a
(
described_class
)
expect
(
project_pipeline_status
).
to
be_loaded
end
end
describe
'.cached_results_for_projects'
do
it
'loads a status from caching for all projects'
do
Gitlab
::
Redis
::
Cache
.
with
do
|
redis
|
redis
.
mapped_hmset
(
cache_key
,
{
sha:
sha
,
status:
status
,
ref:
ref
})
it
'loads 10 projects without hitting Gitaly call limit'
,
:request_store
do
projects
=
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
(
1
..
10
).
map
{
create
(
:project
,
:repository
)
}
end
Gitlab
::
GitalyClient
.
reset_counts
result
=
[{
loaded_from_cache:
false
,
pipeline_info:
{
sha:
nil
,
status:
nil
,
ref:
nil
}
},
{
loaded_from_cache:
true
,
pipeline_info:
pipeline_info
}]
expect
(
described_class
.
cached_results_for_projects
([
project_without_status
,
project
])).
to
eq
(
result
)
expect
{
described_class
.
load_in_batch_for_projects
(
projects
)
}.
not_to
raise_error
end
end
end
...
...
@@ -198,7 +128,9 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do
status_for_empty_commit
.
load_status
expect
(
status_for_empty_commit
).
to
be_loaded
expect
(
status_for_empty_commit
.
sha
).
to
be_nil
expect
(
status_for_empty_commit
.
status
).
to
be_nil
expect
(
status_for_empty_commit
.
ref
).
to
be_nil
end
end
...
...
spec/tasks/cache/clear/redis_spec.rb
浏览文件 @
6bb1a2ab
...
...
@@ -6,7 +6,10 @@ describe 'clearing redis cache' do
end
describe
'clearing pipeline status cache'
do
let
(
:pipeline_status
)
{
create
(
:ci_pipeline
).
project
.
pipeline_status
}
let
(
:pipeline_status
)
do
project
=
create
(
:project
,
:repository
)
create
(
:ci_pipeline
,
project:
project
).
project
.
pipeline_status
end
before
do
allow
(
pipeline_status
).
to
receive
(
:loaded
).
and_return
(
nil
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录