-
Couldn't load subscription status.
- Fork 56
Return 200 if no hosts found #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ package mysql | |
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/github/freno/pkg/base" | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package throttle | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/github/freno/pkg/base" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func Test_checkAppMetricResult(t *testing.T) { | ||
| throttler := NewThrottler() | ||
|
|
||
| t.Run("threshold exceeded", func(t *testing.T) { | ||
| check := NewThrottlerCheck(throttler) | ||
| metricResultFunc := func() (metricResult base.MetricResult, threshold float64) { | ||
| return base.NewSimpleMetricResult(10.0), 1.0 | ||
| } | ||
| result := check.checkAppMetricResult("test-app", "mysql", "test-cluster", metricResultFunc, &CheckFlags{}) | ||
| assert.Equal(t, 10.0, result.Value) | ||
| assert.EqualError(t, result.Error, base.ThresholdExceededError.Error()) | ||
| assert.Equal(t, http.StatusTooManyRequests, result.StatusCode) | ||
| }) | ||
| t.Run("not throttled", func(t *testing.T) { | ||
| check := NewThrottlerCheck(throttler) | ||
| metricResultFunc := func() (metricResult base.MetricResult, threshold float64) { | ||
| return base.NewSimpleMetricResult(1.0), 10.0 | ||
| } | ||
| result := check.checkAppMetricResult("test-app", "mysql", "test-cluster", metricResultFunc, &CheckFlags{}) | ||
| assert.Equal(t, 1.0, result.Value) | ||
| assert.Nil(t, result.Error) | ||
| assert.Equal(t, http.StatusOK, result.StatusCode) | ||
| }) | ||
| t.Run("no hosts", func(t *testing.T) { | ||
| check := NewThrottlerCheck(throttler) | ||
| metricResultFunc := func() (metricResult base.MetricResult, threshold float64) { | ||
| return base.NoHostsMetricResult, 10.0 | ||
| } | ||
| result := check.checkAppMetricResult("test-app", "mysql", "test-cluster", metricResultFunc, &CheckFlags{}) | ||
| assert.Equal(t, 0.0, result.Value) | ||
| assert.EqualError(t, result.Error, base.NoHostsError.Error()) | ||
| assert.Equal(t, http.StatusOK, result.StatusCode) | ||
| }) | ||
| t.Run("low priority denied", func(t *testing.T) { | ||
| check := NewThrottlerCheck(throttler) | ||
| throttler.nonLowPriorityAppRequestsThrottled.SetDefault("mysql/test-cluster", true) | ||
| metricResultFunc := func() (metricResult base.MetricResult, threshold float64) { | ||
| return base.NewSimpleMetricResult(1.0), 10.0 | ||
| } | ||
| result := check.checkAppMetricResult("test-app", "mysql", "test-cluster", metricResultFunc, &CheckFlags{LowPriority: true}) | ||
| assert.EqualError(t, result.Error, base.AppDeniedError.Error()) | ||
| assert.Equal(t, http.StatusExpectationFailed, result.StatusCode) | ||
|
|
||
meiji163 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.