data_sender_go/data_sender_test.go

65 lines
957 B
Go
Raw Permalink Normal View History

2017-04-26 06:47:40 +00:00
package data_sender_go
import (
2017-05-29 11:07:08 +00:00
"git.loafle.net/overflow/agent_api/observer"
2017-04-27 11:22:19 +00:00
"strconv"
2017-04-26 06:47:40 +00:00
"testing"
"time"
)
2017-04-26 09:07:44 +00:00
type Result struct {
Data []byte
}
2017-04-26 06:47:40 +00:00
2017-04-27 11:22:19 +00:00
func TestTotal(t *testing.T) {
time.Sleep(time.Second * 5)
observer.Notify("CONFIGMANAGER_LOADED", nil)
time.Sleep(time.Second * 5)
for i := 0; i < 20; i++ {
testNotify(strconv.Itoa(i))
}
time.Sleep(time.Second * 12)
for i := 20; i < 30; i++ {
testNotify(strconv.Itoa(i))
}
time.Sleep(time.Second * 100)
}
2017-04-26 09:07:44 +00:00
func TestSend(t *testing.T) {
2017-04-26 06:47:40 +00:00
2017-04-26 09:07:44 +00:00
ds := &DataSender{}
2017-04-27 11:22:19 +00:00
ds.start()
for i := 0; i < 20; i++ {
testNotify(strconv.Itoa(i))
}
time.Sleep(time.Second * 12)
for i := 20; i < 30; i++ {
testNotify(strconv.Itoa(i))
}
2017-04-26 06:47:40 +00:00
2017-04-26 09:07:44 +00:00
time.Sleep(time.Second * 100)
2017-04-26 06:47:40 +00:00
}
2017-04-27 11:22:19 +00:00
func testNotify(val string) {
2017-04-26 09:07:44 +00:00
result := make(map[string]string)
2017-04-27 11:22:19 +00:00
result["a"] = val
result["b"] = val
result["c"] = val
2017-04-26 09:07:44 +00:00
cd := &Data{
SensorId: "insanity",
Data: result,
}
2017-04-27 11:22:19 +00:00
observer.Notify(messages.QUEUE_DATA, cd)
2017-04-26 09:07:44 +00:00
}