Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
9e96ee75
提交
9e96ee75
编辑于
8 years ago
作者:
Kamil Trzciński
浏览文件
操作
下载
补丁
差异文件
Improve readability of tests
上级
3f90655c
No related branches found
No related tags found
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
README.md
+6
-0
6 个添加, 0 个删除
README.md
internal/queueing/queue.go
+2
-5
2 个添加, 5 个删除
internal/queueing/queue.go
internal/queueing/requests_test.go
+18
-9
18 个添加, 9 个删除
internal/queueing/requests_test.go
有
26 个添加
和
14 个删除
README.md
+
6
−
0
浏览文件 @
9e96ee75
...
@@ -13,6 +13,12 @@ gitlab-workhorse'][brief-history-blog].
...
@@ -13,6 +13,12 @@ gitlab-workhorse'][brief-history-blog].
gitlab-workhorse [OPTIONS]
gitlab-workhorse [OPTIONS]
Options:
Options:
-apiLimit uint
Number of API requests allowed at single time
-apiQueueDuration duration
Maximum queueing duration of requests (default 30s)
-apiQueueLimit uint
Number of API requests allowed to be queued
-authBackend string
-authBackend string
Authentication/authorization backend (default "http://localhost:8080")
Authentication/authorization backend (default "http://localhost:8080")
-authSocket string
-authSocket string
...
...
此差异已折叠。
点击以展开。
internal/queueing/queue.go
+
2
−
5
浏览文件 @
9e96ee75
...
@@ -23,7 +23,7 @@ type Queue struct {
...
@@ -23,7 +23,7 @@ type Queue struct {
func
NewQueue
(
limit
,
queueLimit
uint
)
*
Queue
{
func
NewQueue
(
limit
,
queueLimit
uint
)
*
Queue
{
return
&
Queue
{
return
&
Queue
{
busyCh
:
make
(
chan
struct
{},
limit
),
busyCh
:
make
(
chan
struct
{},
limit
),
waitingCh
:
make
(
chan
struct
{},
limit
+
queueLimit
),
waitingCh
:
make
(
chan
struct
{},
queueLimit
),
}
}
}
}
...
@@ -41,9 +41,7 @@ func (s *Queue) Acquire(timeout time.Duration) (err error) {
...
@@ -41,9 +41,7 @@ func (s *Queue) Acquire(timeout time.Duration) (err error) {
}
}
defer
func
()
{
defer
func
()
{
if
err
!=
nil
{
<-
s
.
waitingCh
<-
s
.
waitingCh
}
}()
}()
// fast path: push item to current processed items (non-blocking)
// fast path: push item to current processed items (non-blocking)
...
@@ -71,6 +69,5 @@ func (s *Queue) Acquire(timeout time.Duration) (err error) {
...
@@ -71,6 +69,5 @@ func (s *Queue) Acquire(timeout time.Duration) (err error) {
// It triggers next request to be processed if it's in queue
// It triggers next request to be processed if it's in queue
func
(
s
*
Queue
)
Release
()
{
func
(
s
*
Queue
)
Release
()
{
// dequeue from queue to allow next request to be processed
// dequeue from queue to allow next request to be processed
<-
s
.
waitingCh
<-
s
.
busyCh
<-
s
.
busyCh
}
}
此差异已折叠。
点击以展开。
internal/queueing/requests_test.go
+
18
−
9
浏览文件 @
9e96ee75
...
@@ -12,14 +12,14 @@ var httpHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request)
...
@@ -12,14 +12,14 @@ var httpHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request)
fmt
.
Fprintln
(
w
,
"OK"
)
fmt
.
Fprintln
(
w
,
"OK"
)
})
})
func
slow
HttpHandler
(
clo
seCh
chan
struct
{})
http
.
Handler
{
func
paused
HttpHandler
(
pau
seCh
chan
struct
{})
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
<-
clo
seCh
<-
pau
seCh
fmt
.
Fprintln
(
w
,
"OK"
)
fmt
.
Fprintln
(
w
,
"OK"
)
})
})
}
}
func
Test
Queue
Request
s
(
t
*
testing
.
T
)
{
func
Test
Normal
Request
Processing
(
t
*
testing
.
T
)
{
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
h
:=
QueueRequests
(
httpHandler
,
1
,
1
,
time
.
Second
)
h
:=
QueueRequests
(
httpHandler
,
1
,
1
,
time
.
Second
)
h
.
ServeHTTP
(
w
,
nil
)
h
.
ServeHTTP
(
w
,
nil
)
...
@@ -28,28 +28,34 @@ func TestQueueRequests(t *testing.T) {
...
@@ -28,28 +28,34 @@ func TestQueueRequests(t *testing.T) {
}
}
}
}
// testSlowRequestProcessing creates a new queue,
// then it runs a number of requests that are going through queue,
// we return the response of first finished request,
// where status of request can be 200, 429 or 503
func
testSlowRequestProcessing
(
count
,
limit
,
queueLimit
uint
,
queueTimeout
time
.
Duration
)
*
httptest
.
ResponseRecorder
{
func
testSlowRequestProcessing
(
count
,
limit
,
queueLimit
uint
,
queueTimeout
time
.
Duration
)
*
httptest
.
ResponseRecorder
{
clo
seCh
:=
make
(
chan
struct
{})
pau
seCh
:=
make
(
chan
struct
{})
defer
close
(
clo
seCh
)
defer
close
(
pau
seCh
)
handler
:=
QueueRequests
(
slow
HttpHandler
(
clo
seCh
),
limit
,
queueLimit
,
queueTimeout
)
handler
:=
QueueRequests
(
paused
HttpHandler
(
pau
seCh
),
limit
,
queueLimit
,
queueTimeout
)
respCh
:=
make
(
chan
*
httptest
.
ResponseRecorder
,
count
)
respCh
:=
make
(
chan
*
httptest
.
ResponseRecorder
,
count
)
// queue requests to use up the queue
// queue requests to use up the queue
for
count
>
0
{
for
i
:=
0
;
i
<
count
;
i
++
{
go
func
()
{
go
func
()
{
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
handler
.
ServeHTTP
(
w
,
nil
)
handler
.
ServeHTTP
(
w
,
nil
)
respCh
<-
w
respCh
<-
w
}()
}()
count
--
}
}
// dequeue first request
// dequeue first request
return
<-
respCh
return
<-
respCh
}
}
// TestQueueingTimeout performs 2 requests
// the queue limit and length is 1,
// the second request gets timed-out
func
TestQueueingTimeout
(
t
*
testing
.
T
)
{
func
TestQueueingTimeout
(
t
*
testing
.
T
)
{
w
:=
testSlowRequestProcessing
(
2
,
1
,
1
,
time
.
Microsecond
)
w
:=
testSlowRequestProcessing
(
2
,
1
,
1
,
time
.
Microsecond
)
...
@@ -58,7 +64,10 @@ func TestQueueingTimeout(t *testing.T) {
...
@@ -58,7 +64,10 @@ func TestQueueingTimeout(t *testing.T) {
}
}
}
}
func
TestQueuedRequests
(
t
*
testing
.
T
)
{
// TestQueueingTooManyRequests performs 3 requests
// the queue limit and length is 1,
// so the third request has to be rejected with 429
func
TestQueueingTooManyRequests
(
t
*
testing
.
T
)
{
w
:=
testSlowRequestProcessing
(
3
,
1
,
1
,
time
.
Minute
)
w
:=
testSlowRequestProcessing
(
3
,
1
,
1
,
time
.
Minute
)
if
w
.
Code
!=
429
{
if
w
.
Code
!=
429
{
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录