Skip to content
Snippets Groups Projects
Commit 934a76c5 authored by Nick Thomas's avatar Nick Thomas
Browse files

Run the tests with gitlab-pages daemonised in the CI environment

parent 91734e88
No related branches found
No related tags found
1 merge request!20Resolve "Gitlab daemon crashing. Omnibus installation (Ubuntu 14.04)"
package main
 
import (
"bytes"
"crypto/tls"
"fmt"
"io/ioutil"
Loading
Loading
@@ -15,6 +16,16 @@ import (
"github.com/stretchr/testify/assert"
)
 
type tWriter struct {
t *testing.T
}
func (t *tWriter) Write(b []byte) (int, error) {
t.t.Log(string(bytes.TrimRight(b, "\r\n")))
return len(b), nil
}
var chdirSet = false
 
func setUpTests() {
Loading
Loading
@@ -131,6 +142,8 @@ func RunPagesProcess(t *testing.T, pagesPath string, listeners []ListenSpec, pro
 
args, tempfiles := getPagesArgs(t, listeners, promPort)
cmd := exec.Command(pagesPath, args...)
cmd.Stdout = &tWriter{t}
cmd.Stderr = &tWriter{t}
cmd.Start()
t.Logf("Running %s %v", pagesPath, args)
 
Loading
Loading
@@ -144,10 +157,10 @@ func RunPagesProcess(t *testing.T, pagesPath string, listeners []ListenSpec, pro
for _, spec := range listeners {
spec.WaitUntilListening()
}
time.Sleep(50 * time.Millisecond)
time.Sleep(500 * time.Millisecond)
 
return func() {
cmd.Process.Kill()
cmd.Process.Signal(os.Interrupt)
cmd.Process.Wait()
for _, tempfile := range tempfiles {
os.Remove(tempfile)
Loading
Loading
@@ -176,9 +189,11 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string) (args,
args = append(args, "-metrics-address", promPort)
}
 
if os.Geteuid() == 0 && os.Getenv("SUDO_UID") != "" && os.Getenv("SUDO_GID") != "" {
t.Log("Pages process will drop privileges")
args = append(args, "-daemon-uid", os.Getenv("SUDO_UID"), "-daemon-gid", os.Getenv("SUDO_GID"))
// At least one of `-daemon-uid` and `-daemon-gid` must be non-zero
if os.Geteuid() == 0 {
t.Log("Running pages as a daemon")
args = append(args, "-daemon-uid", "0")
args = append(args, "-daemon-gid", "65534") // Root user can switch to "nobody"
}
 
return
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment