Skip to content

Commit c298f2e

Browse files
rastislavsYutaroHayakawa
authored andcommitted
operator/bgpv2: Avoid race in TestRouterIDAllocation test
Workaround conceptual race between resource.Events and resource.Store, where store can contain outdated resource version even after receiving an event for the new version. In this case, after upserting a change in BGPCC, the old version of BGPCC was present in the store during the reconciliation triggered by this change in about 2% of the test runs. Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
1 parent b1d70aa commit c298f2e

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

operator/pkg/bgpv2/cluster_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,14 +1568,16 @@ func TestRouterIDAllocation(t *testing.T) {
15681568
}
15691569
assert.Equal(c, tt.InitExpectedRouterIDs, InitNodesRouterIDs)
15701570
}, TestTimeout, 100*time.Millisecond)
1571-
// cleanup the cluster configs
1572-
if tt.FinalClusterConfigs != nil {
1573-
for _, clusterConfig := range tt.FinalClusterConfigs {
1574-
config := clusterConfig
1575-
upsertBGPCC(req, ctx, f, config)
1576-
}
1577-
}
1571+
15781572
assert.EventuallyWithT(t, func(c *assert.CollectT) {
1573+
// NOTE: upserting cluster configs in "eventually" to workaround race between
1574+
// resource.Events and resource.Store, where store can contain outdated resource
1575+
// version even after receiving an event for the new version.
1576+
if tt.FinalClusterConfigs != nil {
1577+
for _, clusterConfig := range tt.FinalClusterConfigs {
1578+
upsertBGPCC(req, ctx, f, clusterConfig)
1579+
}
1580+
}
15791581
NodeConfigs, err := f.bgpnClient.List(ctx, meta_v1.ListOptions{})
15801582
if !assert.NoError(c, err) {
15811583
return

0 commit comments

Comments
 (0)