Files
tendermint/test/loadtime/report/report_test.go
mergify[bot] e914fe40ec ci: Fix linter complaint (backport #9645) (#9647)
* ci: Fix linter complaint (#9645)

Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.

---

#### PR checklist

- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed

(cherry picked from commit 83b7f4ad5b)

# Conflicts:
#	.github/workflows/lint.yml
#	.golangci.yml
#	cmd/tendermint/commands/debug/util.go

* Resolve conflicts

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Sync golangci-lint config with main

Minus the spelling configuration that restricts spelling to US English
only.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* make format

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove usage of deprecated io/ioutil package

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove unused mockBlockStore

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* blockchain/v2: Remove unused method

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Bulk fix lints

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* lint: Ignore auto-generated query PEG

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
2022-10-29 08:58:18 -04:00

126 lines
3.2 KiB
Go

package report_test
import (
"testing"
"time"
"github.com/google/uuid"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/tendermint/tendermint/test/loadtime/payload"
"github.com/tendermint/tendermint/test/loadtime/report"
"github.com/tendermint/tendermint/types"
)
type mockBlockStore struct {
base int64
blocks []*types.Block
}
func (m *mockBlockStore) Height() int64 {
return m.base + int64(len(m.blocks))
}
func (m *mockBlockStore) Base() int64 {
return m.base
}
func (m *mockBlockStore) LoadBlock(i int64) *types.Block {
return m.blocks[i-m.base]
}
func TestGenerateReport(t *testing.T) {
t1 := time.Now()
u := [16]byte(uuid.New())
b1, err := payload.NewBytes(&payload.Payload{
Id: u[:],
Time: timestamppb.New(t1.Add(-10 * time.Second)),
Size: 1024,
})
if err != nil {
t.Fatalf("generating payload %s", err)
}
b2, err := payload.NewBytes(&payload.Payload{
Id: u[:],
Time: timestamppb.New(t1.Add(-4 * time.Second)),
Size: 1024,
})
if err != nil {
t.Fatalf("generating payload %s", err)
}
b3, err := payload.NewBytes(&payload.Payload{
Id: u[:],
Time: timestamppb.New(t1.Add(2 * time.Second)),
Size: 1024,
})
t2 := t1.Add(time.Second)
if err != nil {
t.Fatalf("generating payload %s", err)
}
s := &mockBlockStore{
blocks: []*types.Block{
{
Data: types.Data{
Txs: []types.Tx{b1, b2},
},
},
{
// The timestamp from block H+1 is used to calculate the
// latency for the transactions in block H.
Header: types.Header{
Time: t1,
},
Data: types.Data{
Txs: []types.Tx{[]byte("error")},
},
},
{
Data: types.Data{
Txs: []types.Tx{b3, b3},
},
},
{
Header: types.Header{
Time: t2,
},
Data: types.Data{
Txs: []types.Tx{},
},
},
},
}
rs, err := report.GenerateFromBlockStore(s)
if err != nil {
t.Fatalf("generating report %s", err)
}
if rs.ErrorCount() != 1 {
t.Fatalf("ErrorCount did not match expected. Expected %d but contained %d", 1, rs.ErrorCount())
}
rl := rs.List()
if len(rl) != 1 {
t.Fatalf("number of reports did not match expected. Expected %d but contained %d", 1, len(rl))
}
r := rl[0]
if len(r.All) != 4 {
t.Fatalf("report contained different number of data points from expected. Expected %d but contained %d", 4, len(r.All)) //nolint:lll
}
if r.NegativeCount != 2 {
t.Fatalf("NegativeCount did not match expected. Expected %d but contained %d", 2, r.NegativeCount)
}
if r.Avg != 3*time.Second {
t.Fatalf("Avg did not match expected. Expected %s but contained %s", 3*time.Second, r.Avg)
}
if r.Min != -time.Second {
t.Fatalf("Min did not match expected. Expected %s but contained %s", time.Second, r.Min)
}
if r.Max != 10*time.Second {
t.Fatalf("Max did not match expected. Expected %s but contained %s", 10*time.Second, r.Max)
}
// Verified using online standard deviation calculator:
// https://www.calculator.net/standard-deviation-calculator.html?numberinputs=10%2C+4%2C+-1%2C+-1&ctype=s&x=45&y=12
expectedStdDev := 5228129047 * time.Nanosecond
if r.StdDev != expectedStdDev {
t.Fatalf("StdDev did not match expected. Expected %s but contained %s", expectedStdDev, r.StdDev)
}
}