forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(inputs.mongodb): add an option to bypass connection errors on sta…
…rt (influxdata#11629)
- Loading branch information
1 parent
b85486c
commit 2f61762
Showing
5 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
) | ||
|
||
var ServicePort = "27017" | ||
var unreachableMongoEndpoint = "mongodb://user:[email protected]:27017/nop" | ||
|
||
func createTestServer(t *testing.T) *testutil.Container { | ||
container := testutil.Container{ | ||
|
@@ -46,6 +47,8 @@ func TestGetDefaultTagsIntegration(t *testing.T) { | |
} | ||
err := m.Init() | ||
require.NoError(t, err) | ||
err = m.Start() | ||
require.NoError(t, err) | ||
|
||
server := m.clients[0] | ||
|
||
|
@@ -81,6 +84,8 @@ func TestAddDefaultStatsIntegration(t *testing.T) { | |
} | ||
err := m.Init() | ||
require.NoError(t, err) | ||
err = m.Start() | ||
require.NoError(t, err) | ||
|
||
server := m.clients[0] | ||
|
||
|
@@ -97,6 +102,55 @@ func TestAddDefaultStatsIntegration(t *testing.T) { | |
} | ||
} | ||
|
||
func TestSkipBehaviorIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping integration test in short mode") | ||
} | ||
|
||
m := &MongoDB{ | ||
Log: &testutil.CaptureLogger{}, | ||
Servers: []string{unreachableMongoEndpoint}, | ||
} | ||
|
||
m.DisconnectedServersBehavior = "skip" | ||
err := m.Init() | ||
require.NoError(t, err) | ||
err = m.Start() | ||
require.NoError(t, err) | ||
|
||
var acc testutil.Accumulator | ||
err = m.Gather(&acc) | ||
require.NoError(t, err) | ||
require.NotContains(t, m.Log.(*testutil.CaptureLogger).LastError, "failed to gather data: ") | ||
} | ||
|
||
func TestErrorBehaviorIntegration(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping integration test in short mode") | ||
} | ||
|
||
m := &MongoDB{ | ||
Log: &testutil.CaptureLogger{}, | ||
Servers: []string{unreachableMongoEndpoint}, | ||
} | ||
|
||
err := m.Init() | ||
require.NoError(t, err) | ||
err = m.Start() | ||
require.Error(t, err) | ||
|
||
// set to skip to bypass start error | ||
m.DisconnectedServersBehavior = "skip" | ||
err = m.Start() | ||
require.NoError(t, err) | ||
m.DisconnectedServersBehavior = "error" | ||
|
||
var acc testutil.Accumulator | ||
err = m.Gather(&acc) | ||
require.NoError(t, err) | ||
require.Contains(t, m.Log.(*testutil.CaptureLogger).LastError, "failed to gather data: ") | ||
} | ||
|
||
func TestPoolStatsVersionCompatibility(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters