Commit f036fba7 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch 'cat-flaky-geo-poll-workhorse' into 'master'

Prevent secret path race condition when polling Geo API in tests

See merge request gitlab-org/gitlab!75342
parents c535317b a81b5d1b
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"testing" "testing"
"time" "time"
...@@ -28,6 +29,14 @@ type testCase struct { ...@@ -28,6 +29,14 @@ type testCase struct {
expectedResponse string expectedResponse string
} }
func TestMain(m *testing.M) {
// Secret should be configured before any Geo API poll happens to prevent
// race conditions where the first API call happens without a secret path
testhelper.ConfigureSecret()
os.Exit(m.Run())
}
func TestRouting(t *testing.T) { func TestRouting(t *testing.T) {
handle := func(u *upstream, regex string) routeEntry { handle := func(u *upstream, regex string) routeEntry {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
...@@ -288,11 +297,6 @@ func startWorkhorseServer(railsServerURL string, enableGeoProxyFeature bool) (*h ...@@ -288,11 +297,6 @@ func startWorkhorseServer(railsServerURL string, enableGeoProxyFeature bool) (*h
} }
cfg := newUpstreamConfig(railsServerURL) cfg := newUpstreamConfig(railsServerURL)
upstreamHandler := newUpstream(*cfg, logrus.StandardLogger(), myConfigureRoutes) upstreamHandler := newUpstream(*cfg, logrus.StandardLogger(), myConfigureRoutes)
// Secret should be configured before the first Geo API poll happens on server start
// to prevent race conditions where the first API call happens without a secret path
testhelper.ConfigureSecret()
ws := httptest.NewServer(upstreamHandler) ws := httptest.NewServer(upstreamHandler)
waitForNextApiPoll := func() {} waitForNextApiPoll := func() {}
......
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