2017-04-10 16:54:12 +00:00
|
|
|
package influxdb
|
2016-12-15 10:10:09 +00:00
|
|
|
|
|
|
|
import (
|
2017-12-31 04:26:17 +00:00
|
|
|
"sync"
|
2016-12-15 10:10:09 +00:00
|
|
|
"testing"
|
2017-12-31 04:26:17 +00:00
|
|
|
"time"
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-12-31 04:26:17 +00:00
|
|
|
"github.com/influxdata/influxdb/client/v2"
|
2016-12-15 10:10:09 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-03-03 15:19:35 +00:00
|
|
|
|
|
|
|
"github.com/FreifunkBremen/yanic/data"
|
2017-04-10 16:54:12 +00:00
|
|
|
"github.com/FreifunkBremen/yanic/runtime"
|
2016-12-15 10:10:09 +00:00
|
|
|
)
|
|
|
|
|
2017-11-21 14:12:06 +00:00
|
|
|
const TEST_SITE = "ffxx"
|
|
|
|
|
2016-12-15 10:10:09 +00:00
|
|
|
func TestGlobalStats(t *testing.T) {
|
2017-11-21 14:12:06 +00:00
|
|
|
stats := runtime.NewGlobalStats(createTestNodes(), []string{TEST_SITE})
|
2016-12-15 10:10:09 +00:00
|
|
|
|
|
|
|
assert := assert.New(t)
|
2017-01-20 22:23:31 +00:00
|
|
|
|
2017-11-21 14:12:06 +00:00
|
|
|
// check SITE_GLOBAL fields
|
|
|
|
fields := GlobalStatsFields(stats[runtime.GLOBAL_SITE])
|
2017-01-20 22:23:31 +00:00
|
|
|
assert.EqualValues(3, fields["nodes"])
|
2017-11-21 14:12:06 +00:00
|
|
|
|
|
|
|
fields = GlobalStatsFields(stats[TEST_SITE])
|
2017-12-31 04:26:17 +00:00
|
|
|
assert.EqualValues(1, fields["nodes"])
|
|
|
|
|
|
|
|
conn := &Connection{
|
|
|
|
points: make(chan *client.Point),
|
|
|
|
}
|
|
|
|
|
|
|
|
global := 0
|
|
|
|
globalSite := 0
|
|
|
|
model := 0
|
|
|
|
modelSite := 0
|
|
|
|
firmware := 0
|
|
|
|
firmwareSite := 0
|
|
|
|
autoupdater := 0
|
|
|
|
autoupdaterSite := 0
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(9)
|
|
|
|
go func() {
|
|
|
|
for p := range conn.points {
|
|
|
|
switch p.Name() {
|
|
|
|
case MeasurementGlobal:
|
|
|
|
global++
|
|
|
|
break
|
|
|
|
case "global_site":
|
|
|
|
globalSite++
|
|
|
|
break
|
|
|
|
case CounterMeasurementModel:
|
|
|
|
model++
|
|
|
|
break
|
|
|
|
case "model_site":
|
|
|
|
modelSite++
|
|
|
|
break
|
|
|
|
case CounterMeasurementFirmware:
|
|
|
|
firmware++
|
|
|
|
break
|
|
|
|
case "firmware_site":
|
|
|
|
firmwareSite++
|
|
|
|
break
|
|
|
|
case CounterMeasurementAutoupdater:
|
|
|
|
autoupdater++
|
|
|
|
break
|
|
|
|
case "autoupdater_site":
|
|
|
|
autoupdaterSite++
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
assert.Equal("invalid p.Name found", p.Name())
|
|
|
|
}
|
|
|
|
wg.Done()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
for site, stat := range stats {
|
|
|
|
conn.InsertGlobals(stat, time.Now(), site)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
assert.Equal(1, global)
|
|
|
|
assert.Equal(1, globalSite)
|
|
|
|
assert.Equal(2, model)
|
|
|
|
assert.Equal(1, modelSite)
|
|
|
|
assert.Equal(1, firmware)
|
|
|
|
assert.Equal(0, firmwareSite)
|
|
|
|
assert.Equal(2, autoupdater)
|
|
|
|
assert.Equal(1, autoupdaterSite)
|
2016-12-15 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 16:54:12 +00:00
|
|
|
func createTestNodes() *runtime.Nodes {
|
2018-01-07 20:00:56 +00:00
|
|
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodeData := &runtime.Node{
|
|
|
|
Online: true,
|
2016-12-15 10:10:09 +00:00
|
|
|
Statistics: &data.Statistics{
|
|
|
|
Clients: data.Clients{
|
|
|
|
Total: 23,
|
|
|
|
},
|
|
|
|
},
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "abcdef012345",
|
2016-12-15 10:10:09 +00:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
2017-12-31 04:26:17 +00:00
|
|
|
System: data.System{},
|
2016-12-15 10:10:09 +00:00
|
|
|
},
|
|
|
|
}
|
2017-05-20 12:46:29 +00:00
|
|
|
nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
|
2017-11-14 18:33:50 +00:00
|
|
|
nodeData.Nodeinfo.Software.Autoupdater.Enabled = true
|
|
|
|
nodeData.Nodeinfo.Software.Autoupdater.Branch = "stable"
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(nodeData)
|
2016-12-15 10:10:09 +00:00
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(&runtime.Node{
|
|
|
|
Online: true,
|
2016-12-15 10:10:09 +00:00
|
|
|
Statistics: &data.Statistics{
|
|
|
|
Clients: data.Clients{
|
|
|
|
Total: 2,
|
|
|
|
},
|
|
|
|
},
|
2017-05-20 12:46:29 +00:00
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "112233445566",
|
2016-12-15 10:10:09 +00:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "TP-Link 841",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2017-05-20 12:46:29 +00:00
|
|
|
nodes.AddNode(&runtime.Node{
|
|
|
|
Online: true,
|
|
|
|
Nodeinfo: &data.NodeInfo{
|
|
|
|
NodeID: "0xdeadbeef0x",
|
|
|
|
VPN: true,
|
2016-12-15 10:10:09 +00:00
|
|
|
Hardware: data.Hardware{
|
|
|
|
Model: "Xeon Multi-Core",
|
|
|
|
},
|
2017-11-21 14:12:06 +00:00
|
|
|
System: data.System{
|
|
|
|
SiteCode: TEST_SITE,
|
|
|
|
},
|
2016-12-15 10:10:09 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return nodes
|
|
|
|
}
|