event test

This commit is contained in:
geek 2017-04-28 11:11:37 +09:00
parent d5815eb71a
commit fffeb2ff41
2 changed files with 10 additions and 6 deletions

View File

@ -40,6 +40,7 @@ func (es *EventSender) Start() {
func (es *EventSender) Stop() { func (es *EventSender) Stop() {
if es.sc != nil { if es.sc != nil {
close(es.sc) close(es.sc)
es.sc = nil
} }
} }
@ -59,7 +60,7 @@ func (es *EventSender) checkQueue() {
collectedData := tempCollectedData.Value.(*Data) collectedData := tempCollectedData.Value.(*Data)
collectedData.AgentId = agentIdentifier() collectedData.AgentId = agentIdentifier()
result = append(result, collectedData) result = append(result, collectedData)
log.Println("Result Len: ", len(result)) //log.Println("Result Len: ", len(result))
} }
es.send(result) es.send(result)
result = nil result = nil

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"testing" "testing"
"time" "time"
"strconv"
) )
func TestEventSender_Start(t *testing.T) { func TestEventSender_Start(t *testing.T) {
@ -14,23 +15,25 @@ func TestEventSender_Start(t *testing.T) {
es.Start() es.Start()
testNotify() testNotify()
time.Sleep(time.Second * 100) time.Sleep(time.Second * 1000)
} }
func testNotify() { func testNotify() {
//time.Sleep(time.Second * 5) //time.Sleep(time.Second * 5)
for i := 0; i < 20; i ++{
result := make(map[string]string) result := make(map[string]string)
result["ab"] = "123" result["ab"] = "123 ( " + strconv.Itoa(i) + ")"
result["cd"] = "456" result["cd"] = "456 ( "+ strconv.Itoa(i) + ")"
result["ef"] = "789" result["ef"] = "789 ( "+ strconv.Itoa(i) + ")"
cd := &Data{ cd := &Data{
SensorId: "insanity", SensorId: "insanity",
Data: result, Data: result,
} }
log.Println("New data Notify")
observer.Notify(messages.QUEUE_EVENT, cd) observer.Notify(messages.QUEUE_EVENT, cd)
} }
log.Println("New data Notify")
}