mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 22:07:27 -08:00
discovery/marathon: make test use separate instances of config
So tests can be executed in parallel without producing races. Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
This commit is contained in:
parent
2cf7479622
commit
fedcb8999b
|
@ -29,11 +29,14 @@ import (
|
||||||
var (
|
var (
|
||||||
marathonValidLabel = map[string]string{"prometheus": "yes"}
|
marathonValidLabel = map[string]string{"prometheus": "yes"}
|
||||||
testServers = []string{"http://localhost:8080"}
|
testServers = []string{"http://localhost:8080"}
|
||||||
conf = SDConfig{Servers: testServers}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func testConfig() SDConfig {
|
||||||
|
return SDConfig{Servers: testServers}
|
||||||
|
}
|
||||||
|
|
||||||
func testUpdateServices(client appListClient) ([]*targetgroup.Group, error) {
|
func testUpdateServices(client appListClient) ([]*targetgroup.Group, error) {
|
||||||
md, err := NewDiscovery(conf, nil)
|
md, err := NewDiscovery(testConfig(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -126,7 +129,7 @@ func TestMarathonSDSendGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarathonSDRemoveApp(t *testing.T) {
|
func TestMarathonSDRemoveApp(t *testing.T) {
|
||||||
md, err := NewDiscovery(conf, nil)
|
md, err := NewDiscovery(testConfig(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s", err)
|
t.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
|
@ -278,13 +281,6 @@ func Test500ErrorHttpResponseWithValidJSONBody(t *testing.T) {
|
||||||
// Create a test server with mock HTTP handler.
|
// Create a test server with mock HTTP handler.
|
||||||
ts := httptest.NewServer(http.HandlerFunc(respHandler))
|
ts := httptest.NewServer(http.HandlerFunc(respHandler))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
// Backup conf for future tests.
|
|
||||||
backupConf := conf
|
|
||||||
defer func() {
|
|
||||||
conf = backupConf
|
|
||||||
}()
|
|
||||||
// Setup conf for the test case.
|
|
||||||
conf = SDConfig{Servers: []string{ts.URL}}
|
|
||||||
// Execute test case and validate behavior.
|
// Execute test case and validate behavior.
|
||||||
_, err := testUpdateServices(nil)
|
_, err := testUpdateServices(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in a new issue