close the clients before testing stats

This commit is contained in:
risk danger olson 2017-04-28 08:24:32 -06:00
parent 81eb75c41a
commit 3f6072de8b
2 changed files with 14 additions and 2 deletions

@ -133,7 +133,7 @@ func (l *syncLogger) LogResponse(req *http.Request, status int, bodySize int64)
if v := req.Context().Value(transferKey); v != nil {
t := v.(*httpTransfer)
now := time.Now().UnixNano()
l.logTransfer(t, "request",
l.logTransfer(t, "response",
fmt.Sprintf(" status=%d body=%d conntime=%d dnstime=%d tlstime=%d restime=%d time=%d",
status,
bodySize,

@ -48,6 +48,7 @@ func TestStatsWithKey(t *testing.T) {
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
assert.Nil(t, c.Close())
assert.Equal(t, 200, res.StatusCode)
assert.EqualValues(t, 1, called)
@ -55,7 +56,7 @@ func TestStatsWithKey(t *testing.T) {
stats := strings.TrimSpace(out.String())
t.Log(stats)
lines := strings.Split(stats, "\n")
assert.Equal(t, 2, len(lines))
require.Equal(t, 3, len(lines))
assert.True(t, strings.Contains(lines[0], "concurrent=5"))
expected := []string{
"key=stats-test",
@ -67,6 +68,16 @@ func TestStatsWithKey(t *testing.T) {
for _, substr := range expected {
assert.True(t, strings.Contains(lines[1], substr), "missing: "+substr)
}
expected = []string{
"key=stats-test",
"event=response",
"url=" + srv.URL,
}
for _, substr := range expected {
assert.True(t, strings.Contains(lines[2], substr), "missing: "+substr)
}
}
func TestStatsWithoutKey(t *testing.T) {
@ -100,6 +111,7 @@ func TestStatsWithoutKey(t *testing.T) {
require.Nil(t, err)
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
assert.Nil(t, c.Close())
assert.Equal(t, 200, res.StatusCode)
assert.EqualValues(t, 1, called)