Commit 97764f10 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Added integration testing for long polling route

parent c9d49ca9
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"))
}
......@@ -12,8 +12,10 @@ import (
)
const (
maxRegisterBodySize = 32 * 1024
runnerBuildQueue = "runner:build_queue:"
maxRegisterBodySize = 32 * 1024
runnerBuildQueue = "runner:build_queue:"
runnerBuildQueueHeaderKey = "Gitlab-Ci-Builds-Polling"
runnerBuildQueueHeaderValue = "yes"
)
var (
......@@ -104,6 +106,8 @@ func RegisterHandler(h http.Handler, watchHandler WatchKeyHandler, pollingDurati
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set(runnerBuildQueueHeaderKey, runnerBuildQueueHeaderValue)
requestBody, err := readRunnerBody(w, r)
if err != nil {
registerHandlerBodyReadErrors.Inc()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment