(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func 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 { |
nothing calls this directly
no test coverage detected
searching dependent graphs…