-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add load testing harness, coder loadtest command #4853
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02ec880
feat: add load testing harness
deansheather b63d7e8
feat: add workspacebuild load test runner
deansheather 4839db7
feat: add coder loadtest command
deansheather dde7ad8
fixup! feat: add coder loadtest command
deansheather df7866c
fixup! feat: add coder loadtest command
deansheather 124f252
fix: fix races in loadtest tests
deansheather e5d2f97
chore: pr comments
deansheather File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixup! feat: add coder loadtest command
- Loading branch information
commit df7866cfe0a4ab362f23efc1464ef3295a3aa006
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package httpapi | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
|
||
"golang.org/x/xerrors" | ||
) | ||
|
||
// Duration wraps time.Duration and provides better JSON marshaling and | ||
// unmarshaling. | ||
type Duration time.Duration | ||
|
||
var _ json.Marshaler = Duration(0) | ||
var _ json.Unmarshaler = (*Duration)(nil) | ||
|
||
// MarshalJSON implements json.Marshaler. | ||
func (d Duration) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(time.Duration(d).String()) | ||
} | ||
|
||
// UnmarshalJSON implements json.Unmarshaler. | ||
func (d *Duration) UnmarshalJSON(b []byte) error { | ||
var v interface{} | ||
err := json.Unmarshal(b, &v) | ||
if err != nil { | ||
return xerrors.Errorf("unmarshal JSON value: %w", err) | ||
} | ||
|
||
switch value := v.(type) { | ||
case float64: | ||
*d = Duration(time.Duration(value)) | ||
return nil | ||
case string: | ||
tmp, err := time.ParseDuration(value) | ||
if err != nil { | ||
return xerrors.Errorf("parse duration %q: %w", value, err) | ||
} | ||
|
||
*d = Duration(tmp) | ||
return nil | ||
} | ||
|
||
return xerrors.New("invalid duration") | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package httpapi_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/coderd/httpapi" | ||
) | ||
|
||
func TestDuration(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("MarshalJSON", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
value time.Duration | ||
expected string | ||
}{ | ||
{ | ||
value: 0, | ||
expected: "0s", | ||
}, | ||
{ | ||
value: 1 * time.Millisecond, | ||
expected: "1ms", | ||
}, | ||
{ | ||
value: 1 * time.Second, | ||
expected: "1s", | ||
}, | ||
{ | ||
value: 1 * time.Minute, | ||
expected: "1m0s", | ||
}, | ||
{ | ||
value: 1 * time.Hour, | ||
expected: "1h0m0s", | ||
}, | ||
{ | ||
value: 1*time.Hour + 1*time.Minute + 1*time.Second + 1*time.Millisecond, | ||
expected: "1h1m1.001s", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
|
||
t.Run(c.expected, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
d := httpapi.Duration(c.value) | ||
b, err := d.MarshalJSON() | ||
require.NoError(t, err) | ||
require.Equal(t, `"`+c.expected+`"`, string(b)) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("UnmarshalJSON", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
value string | ||
expected time.Duration | ||
}{ | ||
{ | ||
value: "0ms", | ||
expected: 0, | ||
}, | ||
{ | ||
value: "0s", | ||
expected: 0, | ||
}, | ||
{ | ||
value: "1ms", | ||
expected: 1 * time.Millisecond, | ||
}, | ||
{ | ||
value: "1s", | ||
expected: 1 * time.Second, | ||
}, | ||
{ | ||
value: "1m", | ||
expected: 1 * time.Minute, | ||
}, | ||
{ | ||
value: "1m0s", | ||
expected: 1 * time.Minute, | ||
}, | ||
{ | ||
value: "1h", | ||
expected: 1 * time.Hour, | ||
}, | ||
{ | ||
value: "1h0m0s", | ||
expected: 1 * time.Hour, | ||
}, | ||
{ | ||
value: "1h1m1.001s", | ||
expected: 1*time.Hour + 1*time.Minute + 1*time.Second + 1*time.Millisecond, | ||
}, | ||
{ | ||
value: "1h1m1s1ms", | ||
expected: 1*time.Hour + 1*time.Minute + 1*time.Second + 1*time.Millisecond, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
|
||
t.Run(c.value, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
var d httpapi.Duration | ||
err := d.UnmarshalJSON([]byte(`"` + c.value + `"`)) | ||
require.NoError(t, err) | ||
require.Equal(t, c.expected, time.Duration(d)) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("UnmarshalJSONInt", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
var d httpapi.Duration | ||
err := d.UnmarshalJSON([]byte("12345")) | ||
require.NoError(t, err) | ||
require.EqualValues(t, 12345, d) | ||
}) | ||
|
||
t.Run("UnmarshalJSONErrors", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
value string | ||
errContains string | ||
}{ | ||
{ | ||
value: "not valid json (no double quotes)", | ||
errContains: "unmarshal JSON value", | ||
}, | ||
{ | ||
value: `"not valid duration"`, | ||
errContains: "parse duration", | ||
}, | ||
{ | ||
value: "{}", | ||
errContains: "invalid duration", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
|
||
t.Run(c.value, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
var d httpapi.Duration | ||
err := d.UnmarshalJSON([]byte(c.value)) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), c.errContains) | ||
}) | ||
} | ||
}) | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.