Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-02-03 00:08:19 +0300
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-02-07 21:38:47 +0300
commitddff37bc7cecf2f73a7bb82d60391505ad96a426 (patch)
tree88bdfc87ba74866da6224ddea200062fee31e5aa /helpers_test.go
parent1e31fac9d8a60efb3b2b536a46e059f286ab62c0 (diff)
Improve complexity metrics
Also fixed the dependencies, moved metrics to its own package and updated the tests
Diffstat (limited to 'helpers_test.go')
-rw-r--r--helpers_test.go60
1 files changed, 32 insertions, 28 deletions
diff --git a/helpers_test.go b/helpers_test.go
index 4e5c3d93..e7fd744e 100644
--- a/helpers_test.go
+++ b/helpers_test.go
@@ -3,7 +3,6 @@ package main
import (
"crypto/tls"
"fmt"
- "github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"net"
@@ -12,6 +11,8 @@ import (
"os/exec"
"testing"
"time"
+
+ "github.com/stretchr/testify/assert"
)
var chdirSet = false
@@ -125,13 +126,38 @@ func (l ListenSpec) JoinHostPort() string {
//
// If run as root via sudo, the gitlab-pages process will drop privileges
func RunPagesProcess(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string) (teardown func()) {
- var tempfiles []string
- var args []string
- var hasHTTPS bool
-
_, err := os.Stat(pagesPath)
assert.NoError(t, err)
+ args, tempfiles := getPagesArgs(t, listeners, promPort)
+ cmd := exec.Command(pagesPath, args...)
+ cmd.Start()
+ t.Logf("Running %s %v", pagesPath, args)
+
+ // Wait for all TCP servers to be open. Even with this, gitlab-pages
+ // will sometimes return 404 if a HTTP request comes in before it has
+ // updated its set of domains. This usually takes < 1ms, hence the sleep
+ // for now. Without it, intermittent failures occur.
+ //
+ // TODO: replace this with explicit status from the pages binary
+ // TODO: fix the first-request race
+ for _, spec := range listeners {
+ spec.WaitUntilListening()
+ }
+ time.Sleep(50 * time.Millisecond)
+
+ return func() {
+ cmd.Process.Kill()
+ cmd.Process.Wait()
+ for _, tempfile := range tempfiles {
+ os.Remove(tempfile)
+ }
+ }
+}
+
+func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string) (args, tempfiles []string) {
+ var hasHTTPS bool
+
for _, spec := range listeners {
args = append(args, "-listen-"+spec.Type, spec.JoinHostPort())
@@ -155,29 +181,7 @@ func RunPagesProcess(t *testing.T, pagesPath string, listeners []ListenSpec, pro
args = append(args, "-daemon-uid", os.Getenv("SUDO_UID"), "-daemon-gid", os.Getenv("SUDO_GID"))
}
- cmd := exec.Command(pagesPath, args...)
- cmd.Start()
- fmt.Println("Running %s %v", pagesPath, args)
-
- // Wait for all TCP servers to be open. Even with this, gitlab-pages
- // will sometimes return 404 if a HTTP request comes in before it has
- // updated its set of domains. This usually takes < 1ms, hence the sleep
- // for now. Without it, intermittent failures occur.
- //
- // TODO: replace this with explicit status from the pages binary
- // TODO: fix the first-request race
- for _, spec := range listeners {
- spec.WaitUntilListening()
- }
- time.Sleep(50 * time.Millisecond)
-
- return func() {
- cmd.Process.Kill()
- cmd.Process.Wait()
- for _, tempfile := range tempfiles {
- os.Remove(tempfile)
- }
- }
+ return
}
// Does an insecure HTTP GET against the listener specified, setting a fake