Commit a81b5d1b authored by Catalin Irimie's avatar Catalin Irimie

Prevent secret path race condition when polling Geo API in tests

The newUpstream method starts the goroutine that polls the Geo API,
which expects the secret to be configured, thus the ConfigureSecret
method should be called before this, instead of the NewServer method.
parent 48c542d5
......@@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
......@@ -28,6 +29,14 @@ type testCase struct {
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) {
handle := func(u *upstream, regex string) routeEntry {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
......@@ -288,11 +297,6 @@ func startWorkhorseServer(railsServerURL string, enableGeoProxyFeature bool) (*h
}
cfg := newUpstreamConfig(railsServerURL)
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)
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