MCPcopy
hub / github.com/osrg/gobgp / TestWatchUpdateCurrentDeliversInitBeforeLiveEvents

Function TestWatchUpdateCurrentDeliversInitBeforeLiveEvents

pkg/server/server_test.go:126–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestWatchUpdateCurrentDeliversInitBeforeLiveEvents(t *testing.T) {
127 ctx := context.Background()
128 s1 := runNewServer(t, 1, "1.1.1.1", 10179)
129 defer s1.StopBgp(context.Background(), &api.StopBgpRequest{})
130 s2 := runNewServer(t, 1, "2.2.2.2", 20179)
131 defer s2.StopBgp(context.Background(), &api.StopBgpRequest{})
132
133 established := newPeerStateWaiter(s1, api.PeerState_SESSION_STATE_ESTABLISHED)
134 err := peerServers(t, ctx, []*BgpServer{s1, s2}, []oc.AfiSafiType{oc.AFI_SAFI_TYPE_IPV4_UNICAST})
135 require.NoError(t, err)
136 established.Wait(t, 10*time.Second)
137
138 panh, _ := bgp.NewPathAttributeNextHop(netip.MustParseAddr("10.0.0.1"))
139 attrs := []bgp.PathAttributeInterface{
140 bgp.NewPathAttributeOrigin(0),
141 panh,
142 }
143 nlri, _ := bgp.NewIPAddrPrefix(netip.MustParsePrefix("10.10.0.0/24"))
144 path, _ := apiutil.NewPath(bgp.RF_IPv4_UC, nlri, false, attrs, time.Now())
145 _, err = s2.AddPath(apiutil.AddPathRequest{Paths: []*apiutil.Path{mustApi2apiutilPath(path)}})
146 require.NoError(t, err)
147
148 require.Eventually(t, func() bool {
149 found := false
150 _ = s1.mgmtOperation(func() error {
151 for _, peer := range s1.neighborMap {
152 if peer.adjRibIn.Count([]bgp.Family{bgp.RF_IPv4_UC}) > 0 {
153 found = true
154 break
155 }
156 }
157 return nil
158 }, true)
159 return found
160 }, 10*time.Second, 100*time.Millisecond)
161
162 enterFilter := make(chan struct{})
163 releaseFilter := make(chan struct{})
164 var filterBlocked atomic.Bool
165 var watcher *watcher
166 done := make(chan struct{})
167
168 go func() {
169 defer close(done)
170 watcher = s1.watch(func(o *watchOptions) {
171 o.preUpdate = true
172 o.initUpdate = true
173 o.preUpdateFilter = func(w watchEvent) bool {
174 if filterBlocked.CompareAndSwap(false, true) {
175 close(enterFilter)
176 <-releaseFilter
177 }
178 return true
179 }
180 })
181 }()
182
183 select {

Callers

nothing calls this directly

Calls 15

StopMethod · 0.95
EventMethod · 0.95
NewPathAttributeNextHopFunction · 0.92
NewPathAttributeOriginFunction · 0.92
NewIPAddrPrefixFunction · 0.92
NewPathFunction · 0.92
NewPathFunction · 0.92
runNewServerFunction · 0.85
newPeerStateWaiterFunction · 0.85
peerServersFunction · 0.85
mustApi2apiutilPathFunction · 0.85
WaitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…