@@ -1121,12 +1121,7 @@ var _ = Describe("controller", func() {
1121
1121
}),
1122
1122
}
1123
1123
1124
- err := ctrl .Warmup (ctx )
1125
- Expect (err ).NotTo (HaveOccurred ())
1126
-
1127
- // Verify WaitForWarmupComplete returns true for successful sync
1128
- result := ctrl .WaitForWarmupComplete (ctx )
1129
- Expect (result ).To (BeTrue ())
1124
+ Expect (ctrl .Warmup (ctx )).To (Succeed ())
1130
1125
})
1131
1126
1132
1127
It ("should track warmup status correctly with unsuccessful sync" , func () {
@@ -1144,10 +1139,6 @@ var _ = Describe("controller", func() {
1144
1139
err := ctrl .Warmup (ctx )
1145
1140
Expect (err ).To (HaveOccurred ())
1146
1141
Expect (err .Error ()).To (ContainSubstring ("sync error" ))
1147
-
1148
- // Verify WaitForWarmupComplete returns false for unsuccessful sync
1149
- result := ctrl .WaitForWarmupComplete (ctx )
1150
- Expect (result ).To (BeFalse ())
1151
1142
})
1152
1143
1153
1144
It ("should return true if context is cancelled while waiting for source to start" , func () {
@@ -1163,27 +1154,19 @@ var _ = Describe("controller", func() {
1163
1154
}),
1164
1155
}
1165
1156
1166
- resultChan := make (chan bool )
1167
-
1168
1157
// Wait for the goroutines to finish before returning to avoid racing with the
1169
1158
// assignment in BeforeEach block.
1170
1159
var wg sync.WaitGroup
1171
1160
1172
- // Invoked in goroutines because the Warmup / WaitForWarmupComplete will block forever.
1173
- wg .Add (2 )
1161
+ // Invoked in a goroutine because Warmup will block
1162
+ wg .Add (1 )
1174
1163
go func () {
1175
1164
defer GinkgoRecover ()
1176
1165
defer wg .Done ()
1177
1166
Expect (ctrl .Warmup (ctx )).To (Succeed ())
1178
1167
}()
1179
- go func () {
1180
- defer GinkgoRecover ()
1181
- defer wg .Done ()
1182
- resultChan <- ctrl .WaitForWarmupComplete (ctx )
1183
- }()
1184
1168
1185
1169
cancel ()
1186
- Expect (<- resultChan ).To (BeTrue ())
1187
1170
wg .Wait ()
1188
1171
})
1189
1172
@@ -1196,16 +1179,15 @@ var _ = Describe("controller", func() {
1196
1179
ctx , cancel := context .WithCancel (context .Background ())
1197
1180
defer cancel ()
1198
1181
1199
- hasCtrlWatchStarted , hasNonWarmupCtrlWatchStarted := atomic. Bool {}, atomic. Bool {}
1200
-
1201
- // ctrl watch will block from finishing until the channel is produced to
1202
- ctrlWatchBlockingChan := make ( chan struct {})
1182
+ By ( "Creating a channel to track execution order" )
1183
+ runnableExecutionOrderChan := make ( chan string , 2 )
1184
+ const nonWarmupRunnableName = "nonWarmupRunnable"
1185
+ const warmupRunnableName = "warmupRunnable"
1203
1186
1204
1187
ctrl .CacheSyncTimeout = time .Second
1205
1188
ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
1206
1189
source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1207
- hasCtrlWatchStarted .Store (true )
1208
- <- ctrlWatchBlockingChan
1190
+ runnableExecutionOrderChan <- warmupRunnableName
1209
1191
return nil
1210
1192
}),
1211
1193
}
@@ -1225,7 +1207,7 @@ var _ = Describe("controller", func() {
1225
1207
})
1226
1208
nonWarmupCtrl .startWatches = []source.TypedSource [reconcile.Request ]{
1227
1209
source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1228
- hasNonWarmupCtrlWatchStarted . Store ( true )
1210
+ runnableExecutionOrderChan <- nonWarmupRunnableName
1229
1211
return nil
1230
1212
}),
1231
1213
}
@@ -1249,13 +1231,9 @@ var _ = Describe("controller", func() {
1249
1231
Expect (m .Start (ctx )).To (Succeed ())
1250
1232
}()
1251
1233
1252
- By ("Waiting for the warmup controller to start" )
1253
- Eventually (hasCtrlWatchStarted .Load ).Should (BeTrue ())
1254
- Expect (hasNonWarmupCtrlWatchStarted .Load ()).To (BeFalse ())
1255
-
1256
- By ("Unblocking the warmup controller source start" )
1257
- close (ctrlWatchBlockingChan )
1258
- Eventually (hasNonWarmupCtrlWatchStarted .Load ).Should (BeTrue ())
1234
+ <- m .Elected ()
1235
+ Expect (<- runnableExecutionOrderChan ).To (Equal (warmupRunnableName ))
1236
+ Expect (<- runnableExecutionOrderChan ).To (Equal (nonWarmupRunnableName ))
1259
1237
})
1260
1238
1261
1239
It ("should not race with Start and only start sources once" , func () {
@@ -1326,58 +1304,6 @@ var _ = Describe("controller", func() {
1326
1304
Eventually (isSourceStarted .Load ).Should (BeTrue ())
1327
1305
})
1328
1306
})
1329
-
1330
- Describe ("WaitForWarmupComplete" , func () {
1331
- It ("should short circuit without blocking if warmup is disabled" , func () {
1332
- ctrl .EnableWarmup = ptr .To (false )
1333
-
1334
- ctx , cancel := context .WithCancel (context .Background ())
1335
- defer cancel ()
1336
-
1337
- // Call WaitForWarmupComplete and expect it to return immediately
1338
- result := ctrl .WaitForWarmupComplete (ctx )
1339
- Expect (result ).To (BeTrue ())
1340
- })
1341
-
1342
- It ("should block until warmup is complete if warmup is enabled" , func () {
1343
- ctrl .EnableWarmup = ptr .To (true )
1344
- // Setup controller with sources that complete successfully
1345
- ctx , cancel := context .WithCancel (context .Background ())
1346
- defer cancel ()
1347
-
1348
- // Close the channel to signal watch completion
1349
- shouldWatchCompleteChan := make (chan struct {})
1350
-
1351
- ctrl .CacheSyncTimeout = time .Second
1352
- ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
1353
- source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1354
- <- shouldWatchCompleteChan
1355
- return nil
1356
- }),
1357
- }
1358
-
1359
- By ("Starting a blocking warmup" )
1360
- go func () {
1361
- defer GinkgoRecover ()
1362
- Expect (ctrl .Warmup (ctx )).To (Succeed ())
1363
- }()
1364
-
1365
- // didWaitForWarmupCompleteReturn is true when the call to WaitForWarmupComplete returns
1366
- didWaitForWarmupCompleteReturn := atomic.Bool {}
1367
- go func () {
1368
- defer GinkgoRecover ()
1369
- // Verify WaitForWarmupComplete returns true for successful sync
1370
- Expect (ctrl .WaitForWarmupComplete (ctx )).To (BeTrue ())
1371
- didWaitForWarmupCompleteReturn .Store (true )
1372
- }()
1373
- Consistently (didWaitForWarmupCompleteReturn .Load ).Should (BeFalse ())
1374
-
1375
- By ("Unblocking the watch to simulate initial sync completion" )
1376
- close (shouldWatchCompleteChan )
1377
- Eventually (didWaitForWarmupCompleteReturn .Load ).Should (BeTrue ())
1378
- })
1379
-
1380
- })
1381
1307
})
1382
1308
1383
1309
var _ = Describe ("ReconcileIDFromContext function" , func () {
0 commit comments