Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
97764f10
Commit
97764f10
authored
Mar 03, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added integration testing for long polling route
parent
c9d49ca9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
builds_test.go
builds_test.go
+44
-0
internal/builds/register.go
internal/builds/register.go
+6
-2
No files found.
builds_test.go
0 → 100644
View file @
97764f10
package
main
import
(
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func
startWorkhorseServerWithLongPolling
(
authBackend
string
,
pollingDuration
time
.
Duration
)
*
httptest
.
Server
{
uc
:=
newUpstreamConfig
(
authBackend
)
uc
.
APICILongPollingDuration
=
pollingDuration
return
startWorkhorseServerWithConfig
(
uc
)
}
func
postBuildsRegister
(
url
string
,
body
io
.
Reader
)
(
*
http
.
Response
,
error
)
{
resource
:=
`/ci/api/v1/builds/register.json`
return
http
.
Post
(
url
+
resource
,
`application/json`
,
body
)
}
func
TestBuildsLongPullingEndpointDisabled
(
t
*
testing
.
T
)
{
ws
:=
startWorkhorseServerWithLongPolling
(
"http://localhost/"
,
0
)
defer
ws
.
Close
()
resp
,
err
:=
postBuildsRegister
(
ws
.
URL
,
nil
)
assert
.
NoError
(
t
,
err
)
defer
resp
.
Body
.
Close
()
assert
.
NotEqual
(
t
,
"yes"
,
resp
.
Header
.
Get
(
"Gitlab-Ci-Builds-Polling"
))
}
func
TestBuildsLongPullingEndpoint
(
t
*
testing
.
T
)
{
ws
:=
startWorkhorseServerWithLongPolling
(
"http://localhost/"
,
time
.
Minute
)
defer
ws
.
Close
()
resp
,
err
:=
postBuildsRegister
(
ws
.
URL
,
nil
)
assert
.
NoError
(
t
,
err
)
defer
resp
.
Body
.
Close
()
assert
.
Equal
(
t
,
"yes"
,
resp
.
Header
.
Get
(
"Gitlab-Ci-Builds-Polling"
))
}
internal/builds/register.go
View file @
97764f10
...
@@ -12,8 +12,10 @@ import (
...
@@ -12,8 +12,10 @@ import (
)
)
const
(
const
(
maxRegisterBodySize
=
32
*
1024
maxRegisterBodySize
=
32
*
1024
runnerBuildQueue
=
"runner:build_queue:"
runnerBuildQueue
=
"runner:build_queue:"
runnerBuildQueueHeaderKey
=
"Gitlab-Ci-Builds-Polling"
runnerBuildQueueHeaderValue
=
"yes"
)
)
var
(
var
(
...
@@ -104,6 +106,8 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
...
@@ -104,6 +106,8 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
}
}
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
runnerBuildQueueHeaderKey
,
runnerBuildQueueHeaderValue
)
requestBody
,
err
:=
readRunnerBody
(
w
,
r
)
requestBody
,
err
:=
readRunnerBody
(
w
,
r
)
if
err
!=
nil
{
if
err
!=
nil
{
registerHandlerBodyReadErrors
.
Inc
()
registerHandlerBodyReadErrors
.
Inc
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment