Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0dd4c306
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,发现更多精彩内容 >>
提交
0dd4c306
编写于
8月 03, 2017
作者:
B
Bob Van Landuyt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Only track accessibility once
上级
022c38e6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
11 deletion
+46
-11
lib/gitlab/git/storage/circuit_breaker.rb
lib/gitlab/git/storage/circuit_breaker.rb
+14
-8
spec/lib/gitlab/git/storage/circuit_breaker_spec.rb
spec/lib/gitlab/git/storage/circuit_breaker_spec.rb
+32
-3
未找到文件。
lib/gitlab/git/storage/circuit_breaker.rb
浏览文件 @
0dd4c306
...
...
@@ -46,10 +46,6 @@ module Gitlab
def
perform
return
yield
unless
Feature
.
enabled?
(
'git_storage_circuit_breaker'
)
if
circuit_broken?
raise
Gitlab
::
Git
::
Storage
::
CircuitOpen
.
new
(
"Circuit for
#{
storage
}
open"
,
failure_wait_time
)
end
check_storage_accessible!
yield
...
...
@@ -70,14 +66,24 @@ module Gitlab
# When the storage appears not available, and the memoized value is `false`
# we might want to try again.
def
storage_available?
@storage_available
||=
Gitlab
::
Git
::
Storage
::
ForkedStorageCheck
.
storage_available?
(
storage_path
,
storage_timeout
)
end
return
@storage_available
if
@storage_available
def
check_storage_accessible!
if
storage_available?
if
@storage_available
=
Gitlab
::
Git
::
Storage
::
ForkedStorageCheck
.
storage_available?
(
storage_path
,
storage_timeout
)
track_storage_accessible
else
track_storage_inaccessible
end
@storage_available
end
def
check_storage_accessible!
if
circuit_broken?
raise
Gitlab
::
Git
::
Storage
::
CircuitOpen
.
new
(
"Circuit for
#{
storage
}
is broken"
,
failure_wait_time
)
end
unless
storage_available?
raise
Gitlab
::
Git
::
Storage
::
Inaccessible
.
new
(
"
#{
storage
}
not accessible"
,
failure_wait_time
)
end
end
...
...
spec/lib/gitlab/git/storage/circuit_breaker_spec.rb
浏览文件 @
0dd4c306
...
...
@@ -120,19 +120,48 @@ describe Gitlab::Git::Storage::CircuitBreaker, clean_gitlab_redis_shared_state:
end
end
describe
'#check_storage_accessible!'
do
describe
"storage_available?"
do
context
'when the storage is available'
do
it
'tracks that the storage was accessible an raises the error'
do
expect
(
circuit_breaker
).
to
receive
(
:track_storage_accessible
)
circuit_breaker
.
check_storage_accessible!
circuit_breaker
.
storage_available?
end
it
'only performs the check once'
do
expect
(
Gitlab
::
Git
::
Storage
::
ForkedStorageCheck
)
.
to
receive
(
:storage_available?
).
once
.
and_call_original
2
.
times
{
circuit_breaker
.
storage_available?
}
end
end
context
'when storage is not available'
do
let
(
:circuit_breaker
)
{
described_class
.
new
(
'broken'
)
}
it
'tracks that the storage was inaccessible'
do
expect
(
circuit_breaker
).
to
receive
(
:track_storage_inaccessible
)
circuit_breaker
.
storage_available?
end
end
end
describe
'#check_storage_accessible!'
do
it
'raises an exception with retry time when the circuit is open'
do
allow
(
circuit_breaker
).
to
receive
(
:circuit_broken?
).
and_return
(
true
)
expect
{
circuit_breaker
.
check_storage_accessible!
}
.
to
raise_error
do
|
exception
|
expect
(
exception
).
to
be_kind_of
(
Gitlab
::
Git
::
Storage
::
CircuitOpen
)
expect
(
exception
.
retry_after
).
to
eq
(
30
)
end
end
context
'when the storage is not available'
do
let
(
:circuit_breaker
)
{
described_class
.
new
(
'broken'
)
}
it
'
tracks that the storage was unavailable and raises an error with retry time
'
do
it
'
raises an error
'
do
expect
(
circuit_breaker
).
to
receive
(
:track_storage_inaccessible
)
expect
{
circuit_breaker
.
check_storage_accessible!
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录