github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/bench/tools/aisloader/stats/stats_test.go (about) 1 // Package stats_test provides tests of aisloader stats package 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package stats_test 6 7 import ( 8 "testing" 9 "time" 10 11 "github.com/NVIDIA/aistore/bench/tools/aisloader/stats" 12 ) 13 14 func verify(t *testing.T, msg string, exp, act int64) { 15 if exp != act { 16 t.Fatalf("Error: %s, expected = %d, actual = %d", msg, exp, act) 17 } 18 } 19 20 func TestStats(t *testing.T) { 21 start := time.Now() 22 s := stats.NewHTTPReq(start) 23 24 // basic put 25 s.Add(100, 100*time.Millisecond) 26 s.Add(200, 20*time.Millisecond) 27 s.AddErr() 28 s.Add(50, 30*time.Millisecond) 29 30 verify(t, "Total", 3, s.Total()) 31 verify(t, "Total bytes", 350, s.TotalBytes()) 32 verify(t, "Min latency", 20000000, s.MinLatency()) 33 verify(t, "Avg latency", 50000000, s.AvgLatency()) 34 verify(t, "Max latency", 100000000, s.MaxLatency()) 35 verify(t, "Throughput", 5, s.Throughput(start, start.Add(70*time.Second))) 36 verify(t, "Failed", 1, s.TotalErrs()) 37 38 // accumulate non empty stats on top of empty stats 39 total := stats.NewHTTPReq(start) 40 total.Aggregate(s) 41 verify(t, "Total", 3, total.Total()) 42 verify(t, "Total bytes", 350, total.TotalBytes()) 43 verify(t, "Min latency", 20000000, total.MinLatency()) 44 verify(t, "Avg latency", 50000000, total.AvgLatency()) 45 verify(t, "Max latency", 100000000, total.MaxLatency()) 46 verify(t, "Throughput", 5, total.Throughput(start, start.Add(70*time.Second))) 47 verify(t, "Failed", 1, total.TotalErrs()) 48 49 // accumulate empty stats on top of non empty stats 50 s = stats.NewHTTPReq(start) 51 total.Aggregate(s) 52 verify(t, "Total", 3, total.Total()) 53 verify(t, "Total bytes", 350, total.TotalBytes()) 54 verify(t, "Min latency", 20000000, total.MinLatency()) 55 verify(t, "Avg latency", 50000000, total.AvgLatency()) 56 verify(t, "Max latency", 100000000, total.MaxLatency()) 57 verify(t, "Throughput", 5, total.Throughput(start, start.Add(70*time.Second))) 58 verify(t, "Failed", 1, total.TotalErrs()) 59 60 // accumulate non empty stats on top of non empty stats 61 s.AddErr() 62 total.Aggregate(s) 63 verify(t, "Failed err", 2, total.TotalErrs()) 64 s.Add(1, 5*time.Millisecond) 65 total.Aggregate(s) 66 verify(t, "Total", 4, total.Total()) 67 verify(t, "Total bytes", 351, total.TotalBytes()) 68 verify(t, "Min latency", 5000000, total.MinLatency()) 69 verify(t, "Avg latency", 38750000, total.AvgLatency()) 70 verify(t, "Max latency", 100000000, total.MaxLatency()) 71 verify(t, "Throughput", 5, total.Throughput(start, start.Add(70*time.Second))) 72 }