@@ -2,10 +2,40 @@ package modbus
22
33import (
44 "testing"
5+ "time"
56
67 "github.com/stretchr/testify/require"
78)
89
10+ // TestSharedSettings ensures the largest delay and timeout wins for all
11+ // connections sharing the same physical connection
12+ func TestSharedSettings (t * testing.T ) {
13+ ctx := t .Context ()
14+ uri := "localhost:15020"
15+
16+ c1 , err := Settings {URI : uri , ID : 1 , Delay : 2 * time .Second , Timeout : time .Second }.Connection (ctx )
17+ require .NoError (t , err )
18+
19+ c2 , err := Settings {URI : uri , ID : 2 , Delay : time .Second , Timeout : 3 * time .Second }.Connection (ctx )
20+ require .NoError (t , err )
21+
22+ // unset settings don't reset the shared values
23+ c3 , err := Settings {URI : uri , ID : 3 }.Connection (ctx )
24+ require .NoError (t , err )
25+
26+ require .Same (t , c1 .physical , c2 .physical )
27+ require .Same (t , c1 .physical , c3 .physical )
28+ require .Same (t , c1 .physical , c1 .Clone (4 ).physical )
29+
30+ for _ , c := range []* Connection {c1 , c2 , c3 } {
31+ require .Equal (t , 2 * time .Second , c .physical .getDelay ())
32+ require .Equal (t , 3 * time .Second , c .physical .timeout )
33+ }
34+
35+ // timeout has been applied to the physical connection
36+ require .Equal (t , 3 * time .Second , c1 .physical .Connection .Timeout (3 * time .Second ))
37+ }
38+
939func TestParsePoint (t * testing.T ) {
1040 tc := []struct {
1141 in string
0 commit comments