/usr/share/gocode/src/github.com/influxdata/influxdb/stress/v2/statement/report_test.go is in golang-github-influxdb-influxdb-dev 1.1.1+dfsg1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | package statement
import (
"encoding/json"
"fmt"
"strings"
"testing"
"time"
)
func TestInsertReportString(t *testing.T) {
ir := newTestInsertReport()
tmplString := `Write Statement: %v
Points/Sec: %v
Resp Time Average: %v
Resp Time Standard Deviation: %v
95th Percentile Write Response: %v
Average Request Bytes: %v
Successful Write Reqs: %v
Retries: %v`
expected := fmt.Sprintf(tmplString,
ir.name,
ir.pointsPerSecond,
ir.avgResponseTime,
ir.stdDevResponseTime,
ir.percentile,
ir.avgRequestBytes,
ir.successfulWrites,
ir.numRetries)
got := ir.String()
if expected != got {
t.Fail()
}
}
func TestInsertReportPoint(t *testing.T) {
ir := newTestInsertReport()
expected := "testDefault"
got := strings.Split(ir.Point().String(), " ")[0]
if expected != got {
t.Errorf("expected: %v\ngot: %v\n", expected, got)
}
}
func TestQueryReportString(t *testing.T) {
qr := newTestQueryReport()
tmplString := `Query Statement: %v
Resp Time Average: %v
Resp Time Standard Deviation: %v
95th Percentile Read Response: %v
Query Resp Bytes Average: %v bytes
Successful Queries: %v`
expected := fmt.Sprintf(tmplString,
qr.name,
qr.avgResponseTime,
qr.stdDevResponseTime,
qr.percentile,
qr.responseBytes,
qr.successfulReads)
got := qr.String()
if expected != got {
t.Fail()
}
}
func TestQueryReportPoint(t *testing.T) {
qr := newTestQueryReport()
expected := "testDefault"
got := strings.Split(qr.Point().String(), " ")[0]
if expected != got {
t.Errorf("expected: %v\ngot: %v\n", expected, got)
}
}
func TestInfluxQLReportString(t *testing.T) {
iqlr := newTestInfluxQLReport()
expected := fmt.Sprintf("[X] '%v' -> %v", iqlr.statement, iqlr.responseTime)
got := iqlr.String()
if expected != got {
t.Fail()
}
}
func TestInfluxQLReportPoint(t *testing.T) {
iqlr := newTestInfluxQLReport()
expected := "testDefault"
got := strings.Split(iqlr.Point().String(), " ")[0]
if expected != got {
t.Errorf("expected: %v\ngot: %v\n", expected, got)
}
}
func newTestInsertReport() *insertReport {
return &insertReport{
name: "foo_name",
numRetries: 0,
pointsPerSecond: 500000,
successfulWrites: 20000,
avgRequestBytes: 18932,
avgResponseTime: time.Duration(int64(20000)),
stdDevResponseTime: time.Duration(int64(20000)),
percentile: time.Duration(int64(20000)),
}
}
func newTestQueryReport() *queryReport {
return &queryReport{
name: "foo_name",
successfulReads: 2000,
responseBytes: 39049,
stddevResponseBytes: 9091284,
avgResponseTime: 139082,
stdDevResponseTime: 29487,
percentile: 8273491,
}
}
func newTestInfluxQLReport() *influxQlReport {
return &influxQlReport{
statement: "foo_name",
responseTime: time.Duration(int64(20000)),
success: false,
}
}
func TestGetColumnIndex(t *testing.T) {
col := "thing"
columns := []string{"thing"}
expected := 0
got := getColumnIndex(col, columns)
if expected != got {
t.Fail()
}
}
func TestNumberBytes(t *testing.T) {
columns := []string{"num_bytes"}
values := [][]interface{}{[]interface{}{json.Number("1")}}
expected := 1
got := numberBytes(columns, values)
if expected != got {
t.Fail()
}
}
func TestCountSuccesses(t *testing.T) {
columns := []string{"status_code"}
values := [][]interface{}{[]interface{}{json.Number("200")}}
expected := 1
got := countSuccesses(columns, values)
if expected != got {
t.Fail()
}
}
func TestCountRetries(t *testing.T) {
columns := []string{"status_code"}
values := [][]interface{}{[]interface{}{json.Number("500")}}
expected := 1
got := countRetries(columns, values)
if expected != got {
t.Fail()
}
}
func TestResponseTimes(t *testing.T) {
columns := []string{"response_time_ns"}
values := [][]interface{}{[]interface{}{json.Number("380")}}
expected := ResponseTimes([]ResponseTime{NewResponseTime(380)})
got := responseTimes(columns, values)
if expected[0].Value != got[0].Value {
t.Fail()
}
}
func TestPercentile(t *testing.T) {
rs := createTestResponseTimes()
expected := time.Duration(21)
got := percentile(rs)
if expected != got {
t.Errorf("expected: %v\ngot: %v\n", expected, got)
}
}
func TestAvgDuration(t *testing.T) {
rs := createTestResponseTimes()
expected := time.Duration(11)
got := avgDuration(rs)
if expected != got {
t.Errorf("expected: %v\ngot: %v\n", expected, got)
}
}
func TestStddevDuration(t *testing.T) {
rs := createTestResponseTimes()
expected := time.Duration(6)
got := stddevDuration(rs)
if expected != got {
t.Errorf("expected: %v\ngot: %v\n", expected, got)
}
}
func createTestResponseTimes() ResponseTimes {
rstms := []int{1, 2, 3, 4, 5, 6, 7, 13, 14, 15, 16, 17, 18, 19, 8, 9, 10, 11, 12, 20, 21, 22}
rs := []ResponseTime{}
for _, rst := range rstms {
rs = append(rs, NewResponseTime(rst))
}
return rs
}
|