Added profile target for running profiled benchmarks

This commit is contained in:
James Mills 2018-05-13 23:54:35 -07:00
parent d25d41ad2a
commit 2691a13825
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
3 changed files with 16 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*~*
dist
*.bak
*.prof
coverage.txt
cmd/msgbus/msgbus
cmd/msgbusd/msgbusd

View File

@ -37,6 +37,8 @@ image:
@docker build --build-arg TAG=$(TAG) --build-arg BUILD=$(BUILD) -t $(REPO):$(TAG) .
@echo "Image created: $(REPO):$(TAG)"
profile:
@go test -cpuprofile cpu.prof -memprofile mem.prof -v -bench=. $(TEST_ARGS)
bench:
@go test -v -bench=. $(TEST_ARGS)

View File

@ -78,19 +78,6 @@ func TestServeHTTPPOST(t *testing.T) {
assert.Regexp(`message successfully published to hello with sequence \d+`, w.Body.String())
}
func TestServeHTTPPUT(t *testing.T) {
assert := assert.New(t)
mb := New(nil)
w := httptest.NewRecorder()
b := bytes.NewBufferString("hello world")
r, _ := http.NewRequest("PUT", "/hello", b)
mb.ServeHTTP(w, r)
assert.Equal(w.Code, http.StatusOK)
assert.Regexp(`message successfully published to hello with sequence \d+`, w.Body.String())
}
func TestServeHTTPMaxPayloadSize(t *testing.T) {
assert := assert.New(t)
@ -130,6 +117,19 @@ func TestServeHTTPSimple(t *testing.T) {
assert.Equal(msg.Payload, []byte("hello world"))
}
func BenchmarkServeHTTPPOST(b *testing.B) {
mb := New(nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
w := httptest.NewRecorder()
b := bytes.NewBufferString("hello world")
r, _ := http.NewRequest("POST", "/hello", b)
mb.ServeHTTP(w, r)
}
}
func TestServeHTTPSubscriber(t *testing.T) {
assert := assert.New(t)