-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootid_processing_test.go
225 lines (178 loc) · 5.1 KB
/
bootid_processing_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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package phonelab
import (
"fmt"
"testing"
"github.com/gurupras/go-easyfiles"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPhonelabSourceProcessor(t *testing.T) {
t.Parallel()
assert := assert.New(t)
require := require.New(t)
sourceInfo := &PhonelabSourceInfo{}
sourceInfo.Path = "./test/phonelab_source"
sourceInfo.DeviceId = "test-device-1"
sourceInfo.BootId = "bootid-0"
info, err := GetInfoFromFile("./test/phonelab_source/test-device-1/")
require.Nil(err)
sourceInfo.StitchInfo = info
sourceInfo.FSInterface = easyfiles.LocalFS
processor, err := NewPhonelabSourceProcessor(sourceInfo, func(e error) {
t.Log("Error: ", e)
t.FailNow()
})
assert.Nil(err, "Failed to create phonelab source processor")
logChan := processor.Process()
logs := 0
for log := range logChan {
assert.True(len(log.(string)) > 0)
//fmt.Printf("Counting ...%d\n", logs)
logs += 1
}
assert.Equal(10000, logs)
}
func TestMultPhonelabSourceProcessor(t *testing.T) {
t.Parallel()
assert := assert.New(t)
devicePaths := make(map[string][]string)
devicePaths["test-device-1"] = []string{"./test/phonelab_source"}
devicePaths["test-device-2"] = []string{"./test/phonelab_source"}
gen := NewPhonelabSourceGenerator(devicePaths, nil, func(e error) {
t.Log("Error: ", e)
t.FailNow()
})
sourceChan := gen.Process()
pos := 0
for sourceInst := range sourceChan {
pos += 1
sourceInfo, ok := sourceInst.Info.(*PhonelabSourceInfo)
assert.True(ok)
assert.Equal("phonelab-device", sourceInfo.Type())
expected := 0
switch sourceInfo.DeviceId {
case "test-device-1":
expected = 10000
case "test-device-2":
expected = 20000
default:
t.Fatal("Unexpected device: " + sourceInfo.DeviceId)
}
logs := 0
logChan := sourceInst.Processor.Process()
for log := range logChan {
assert.True(len(log.(string)) > 0)
logs += 1
}
assert.Equal(expected, logs)
}
assert.Equal(4, pos)
}
// Make sure we can open the file multiple times
func TestPhonelabSourceProcessorMux(t *testing.T) {
t.Parallel()
assert := assert.New(t)
require := require.New(t)
const NUM_OPENS = 10
sourceInfo := &PhonelabSourceInfo{}
sourceInfo.Path = "./test/phonelab_source"
sourceInfo.DeviceId = "test-device-1"
sourceInfo.BootId = "bootid-0"
info, err := GetInfoFromFile("./test/phonelab_source/test-device-1/")
require.Nil(err)
sourceInfo.StitchInfo = info
sourceInfo.FSInterface = easyfiles.LocalFS
processor, err := NewPhonelabSourceProcessor(sourceInfo, func(e error) {
t.Log("Error: ", e)
t.FailNow()
})
assert.Nil(err, "Failed to create phonelab source processor")
done := make(chan int)
for i := 0; i < NUM_OPENS; i++ {
go func() {
logChan := processor.Process()
logs := 0
for log := range logChan {
assert.True(len(log.(string)) > 0)
logs += 1
}
done <- logs
}()
}
allLogs := 0
for i := 0; i < NUM_OPENS; i++ {
allLogs += <-done
}
assert.Equal(10000*NUM_OPENS, allLogs)
}
// Make sure stuff works while parsing yamls
func TestPhonelabYaml(t *testing.T) {
t.Parallel()
require := require.New(t)
assert := assert.New(t)
manager := &countingResultsManager{
counts: make(map[string]int),
}
env := NewEnvironment()
env.Processors["counter"] = &countingProcessorGen{manager}
confString := `
source:
type: phonelab
sources: ["./test/phonelab_source/**/info.json"]
processors:
- name: counter
has_logstream: true
sink:
name: "counter"
`
conf, err := RunnerConfFromString(confString)
require.Nil(err)
require.NotNil(conf)
runner, err := conf.ToRunner(env)
require.Nil(err)
require.NotNil(runner)
t.Log(runner.Source)
errs := runner.Run()
assert.Equal(0, len(errs))
t.Log(manager.counts)
assert.Equal(10000, manager.counts["test-device-1->bootid-0"], fmt.Sprintf("%v", manager.counts))
assert.Equal(10000, manager.counts["test-device-1->bootid-1"], fmt.Sprintf("%v", manager.counts))
assert.Equal(20000, manager.counts["test-device-2->bootid-0"], fmt.Sprintf("%v", manager.counts))
assert.Equal(20000, manager.counts["test-device-2->bootid-1"], fmt.Sprintf("%v", manager.counts))
}
func TestPhonelabDateRange(t *testing.T) {
t.Parallel()
require := require.New(t)
assert := assert.New(t)
manager := &countingResultsManager{
counts: make(map[string]int),
}
env := NewEnvironment()
env.Processors["counter"] = &countingProcessorGen{manager}
// This is essentially the same as TestPhonelabYaml but with daterange
// Test device 2 should return 0
confString := `
source:
type: phonelab
sources: ["./test/phonelab_source/test-device-2/info.json"]
args:
daterange: "19700101 - 20170101"
processors:
- name: counter
has_logstream: true
sink:
name: "counter"
`
conf, err := RunnerConfFromString(confString)
require.Nil(err)
require.NotNil(conf)
runner, err := conf.ToRunner(env)
require.Nil(err)
require.NotNil(runner)
t.Log(runner.Source)
errs := runner.Run()
assert.Equal(0, len(errs))
t.Log(manager.counts)
assert.Equal(10000, manager.counts["test-device-2->bootid-0"], fmt.Sprintf("%v", manager.counts))
assert.Equal(0, manager.counts["test-device-2->bootid-1"], fmt.Sprintf("%v", manager.counts))
}