-
Notifications
You must be signed in to change notification settings - Fork 287
/
generate_data_test.go
102 lines (92 loc) · 3.19 KB
/
generate_data_test.go
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
package devops
import (
"testing"
"time"
"github.com/timescale/tsbs/cmd/tsbs_generate_data/serialize"
)
const testDevopsHostCount = 100
var testDevopsConf = &DevopsSimulatorConfig{
Start: testTime,
End: testTime.Add(3 * time.Second),
InitHostCount: 10,
HostCount: testDevopsHostCount,
HostConstructor: NewHost,
}
func TestDevopsSimulatorNext(t *testing.T) {
s := testDevopsConf.NewSimulator(time.Second, 0).(*DevopsSimulator)
// There are two epochs for the test configuration, and a difference of 90
// from init to final, so each epoch should add 45 devices to be written.
writtenIdx := []int{10, 55, 100}
p := serialize.NewPoint()
totalPerRun := testDevopsHostCount * 9 // 9 subsystems per device
runFn := func(run int) {
for i := 0; i < totalPerRun; i++ {
write := s.Next(p)
hostIdx := i % testDevopsHostCount
if got := int(s.hostIndex); got != hostIdx+1 {
t.Errorf("run %d: host index incorrect, i = %d: got %d want %d", run, i, got, i+1)
}
if hostIdx < writtenIdx[run-1] && !write {
t.Errorf("run %d: should write point at i = %d, but not", run, i)
} else if hostIdx >= writtenIdx[run-1] && write {
t.Errorf("run %d: should not write point at i = %d, but am", run, i)
}
if got := int(s.epoch); got != run-1 {
t.Errorf("run %d: epoch prematurely turned over", run)
}
}
}
// First run through:
runFn(1)
// Second run through, should wrap around and do hosts again
runFn(2)
// Final run through, should be all hosts:
runFn(3)
}
func TestDevopsSimulatorConfigNewSimulator(t *testing.T) {
duration := time.Second
start := time.Now()
end := start.Add(10 * time.Second)
numHosts := uint64(100)
initHosts := uint64(0)
conf := &DevopsSimulatorConfig{
Start: start,
End: end,
InitHostCount: initHosts,
HostCount: numHosts,
HostConstructor: NewHost,
}
sim := conf.NewSimulator(duration, 0).(*DevopsSimulator)
if got := sim.madePoints; got != 0 {
t.Errorf("incorrect initial points: got %d want %d", got, 0)
}
if got := sim.epoch; got != 0 {
t.Errorf("incorrect initial epoch: got %d want %d", got, 0)
}
if got := sim.hostIndex; got != 0 {
t.Errorf("incorrect initial host index: got %d want %d", got, 0)
}
if got := sim.simulatedMeasurementIndex; got != 0 {
t.Errorf("incorrect simulated measurement index: got %d want %d", got, 0)
}
if got := sim.epochHosts; got != initHosts {
t.Errorf("incorrect initial epoch hosts: got %d want %d", got, initHosts)
}
if got := sim.initHosts; got != initHosts {
t.Errorf("incorrect initial init hosts: got %d want %d", got, initHosts)
}
if got := sim.timestampStart; got != start {
t.Errorf("incorrect start time: got %v want %v", got, start)
}
if got := sim.timestampEnd; got != end {
t.Errorf("incorrect end time: got %v want %v", got, end)
}
wantEpochs := uint64(10) // 10 seconds between start & end, interval is 1s, so 10 / 1 = 10
if got := sim.epochs; got != wantEpochs {
t.Errorf("incorrect epochs: got %d want %d", got, wantEpochs)
}
wantMaxPoints := wantEpochs * numHosts * 9 // 9 measurements per host
if got := sim.maxPoints; got != wantMaxPoints {
t.Errorf("incorrect max points: got %d want %d", got, wantMaxPoints)
}
}