File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package agentapi_test
2
2
3
3
import (
4
4
"context"
5
+ "sync"
5
6
"testing"
6
7
"time"
7
8
@@ -45,10 +46,13 @@ func TestStreamDERPMaps(t *testing.T) {
45
46
t .Run ("OK" , func (t * testing.T ) {
46
47
t .Parallel ()
47
48
49
+ derpMapMu := sync.Mutex {}
48
50
derpMap := tailcfg.DERPMap {}
49
51
api := & agentapi.TailnetAPI {
50
52
Ctx : context .Background (),
51
53
DerpMapFn : func () * tailcfg.DERPMap {
54
+ derpMapMu .Lock ()
55
+ defer derpMapMu .Unlock ()
52
56
derp := (& derpMap ).Clone ()
53
57
return derp
54
58
},
@@ -91,14 +95,18 @@ func TestStreamDERPMaps(t *testing.T) {
91
95
require .Equal (t , tailnet .DERPMapToProto (& derpMap ), gotMap )
92
96
93
97
// Update the map, should get an update.
98
+ derpMapMu .Lock ()
94
99
derpMap .Regions = map [int ]* tailcfg.DERPRegion {
95
100
1 : {},
96
101
}
102
+ derpMapMu .Unlock ()
97
103
gotMap = <- maps
98
104
require .Equal (t , tailnet .DERPMapToProto (& derpMap ), gotMap )
99
105
100
106
// Update the map again, should get an update.
107
+ derpMapMu .Lock ()
101
108
derpMap .Regions = nil
109
+ derpMapMu .Unlock ()
102
110
gotMap = <- maps
103
111
require .Equal (t , tailnet .DERPMapToProto (& derpMap ), gotMap )
104
112
You can’t perform that action at this time.
0 commit comments