forked from konimarti/opc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datamodel_test.go
97 lines (70 loc) · 1.77 KB
/
datamodel_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
package opc
import (
// "log"
// "fmt"
"testing"
"time"
)
func TestOPCDataSync(t *testing.T) {
odata := NewDataModel()
running := odata.Sync(&OpcMockServerStatic{TagList: []string{"tag1", "tag2", "tag3"}}, 50*time.Millisecond)
defer running.Close()
time.Sleep(200 * time.Millisecond)
var value interface{}
var ok bool
for i := 0; i < 5; i++ {
value, ok = odata.Get("tag1")
if value.(float64) != 1.0 || !ok {
t.Fatal("tag1 does not match")
}
value, ok = odata.Get("tag2")
if value.(float64) != 2.0 || !ok {
t.Fatal("tag2 does not match")
}
value, ok = odata.Get("tag3")
if value.(float64) != 3.0 || !ok {
t.Fatal("tag3 does not match")
}
_, ok = odata.Get("tag4")
if ok {
t.Fatal("tag4 should not be found")
}
time.Sleep(100 * time.Millisecond)
}
}
func TestOPCDataStop(t *testing.T) {
odata := NewDataModel()
running := odata.Sync(&OpcMockServerRandom{TagList: []string{"tag1"}}, 50*time.Millisecond)
time.Sleep(200 * time.Millisecond)
value1, _ := odata.Get("tag1")
time.Sleep(200 * time.Millisecond)
value2, _ := odata.Get("tag1")
if value1 == value2 {
t.Fatal("values should be different")
}
running.Close()
time.Sleep(200 * time.Millisecond)
value1, _ = odata.Get("tag1")
time.Sleep(200 * time.Millisecond)
value2, _ = odata.Get("tag1")
if value1 != value2 {
t.Fatal("values should be the same if no more updating")
}
}
func TestOPCDataStopAfterRecord(t *testing.T) {
c := make(chan bool)
go func() {
odata := NewDataModel()
running := odata.Sync(&OpcMockServerRandom{TagList: []string{"tag1", "tag2", "tag3"}}, 50*time.Millisecond)
running.Close()
c <- true
}()
for {
select {
case <-c:
return
case <-time.After(2 * time.Second):
t.Fatal("time out while closing after syncronizing")
}
}
}