@@ -155,33 +155,54 @@ func TestSync(t *testing.T) {
155155 var expectedSyncedNodesCounter = 0
156156 firstNode := testNode ()
157157 secondNode := testNode ()
158+ thirdNode := testNode ()
158159 secondNode .Name = "secondNode"
160+ thirdNode .Name = "thirdNode"
159161
160- // Add two nodes
162+ // Freeze queue processing by running other long-running sync
161163 fakeKubeClient .CoreV1 ().Nodes ().Create (context .TODO (), firstNode , meta_v1.CreateOptions {})
162- // wait time > resync period
163- time .Sleep (2 * time .Second )
164+ time .Sleep (time .Second ) // ensure sync started
165+
166+ // Add two nodes
164167 fakeKubeClient .CoreV1 ().Nodes ().Create (context .TODO (), secondNode , meta_v1.CreateOptions {})
165- // The counter = 1 because it synced only once (for the first Create() call)
166- expectedSyncedNodesCounter += 1
168+ fakeKubeClient .CoreV1 ().Nodes ().Create (context .TODO (), thirdNode , meta_v1.CreateOptions {})
169+ time .Sleep (7 * time .Second ) // wait until both syncs complete
170+ // Second and third nodes should trigger only a single sync (+1 for the first)
171+ expectedSyncedNodesCounter += 2
167172 verifyExpectedSyncerCount (t , fakeManager .syncedNodes , expectedSyncedNodesCounter )
168173
169- // Update both nodes
170- firstNode .Annotations ["key" ] = "true"
171- firstNode .Spec .Unschedulable = false
172- secondNode .Annotations ["key" ] = "true"
174+ // Freeze queue processing by running other long-running sync
175+ firstNode .Spec .Unschedulable = true
173176 fakeKubeClient .CoreV1 ().Nodes ().Update (context .TODO (), firstNode , meta_v1.UpdateOptions {})
177+ time .Sleep (time .Second ) // ensure sync started
178+
179+ // Update two nodes
180+ secondNode .Spec .Unschedulable = true
181+ thirdNode .Spec .Unschedulable = true
174182 fakeKubeClient .CoreV1 ().Nodes ().Update (context .TODO (), secondNode , meta_v1.UpdateOptions {})
175- time .Sleep (2 * time .Second )
176- // nodes were updated
177- expectedSyncedNodesCounter += 1
183+ fakeKubeClient .CoreV1 ().Nodes ().Update (context .TODO (), thirdNode , meta_v1.UpdateOptions {})
184+ time .Sleep (7 * time .Second ) // wait until both syncs complete
185+ // Second and third nodes should trigger only a single sync (+1 for the first)
186+ expectedSyncedNodesCounter += 2
178187 verifyExpectedSyncerCount (t , fakeManager .syncedNodes , expectedSyncedNodesCounter )
179188
180189 // no real update
181190 fakeKubeClient .CoreV1 ().Nodes ().Update (context .TODO (), firstNode , meta_v1.UpdateOptions {})
182191 // Nothing should change
183192 time .Sleep (2 * time .Second )
184193 verifyExpectedSyncerCount (t , fakeManager .syncedNodes , expectedSyncedNodesCounter )
194+
195+ // Freeze queue processing by running other long-running sync
196+ fakeKubeClient .CoreV1 ().Nodes ().Delete (context .TODO (), firstNode .Name , meta_v1.DeleteOptions {})
197+ time .Sleep (time .Second ) // ensure sync started
198+
199+ // Delete two nodes
200+ fakeKubeClient .CoreV1 ().Nodes ().Delete (context .TODO (), secondNode .Name , meta_v1.DeleteOptions {})
201+ fakeKubeClient .CoreV1 ().Nodes ().Delete (context .TODO (), thirdNode .Name , meta_v1.DeleteOptions {})
202+ time .Sleep (7 * time .Second ) // wait until both syncs complete
203+ // Second and third nodes should trigger only a single sync (+1 for the first)
204+ expectedSyncedNodesCounter += 2
205+ verifyExpectedSyncerCount (t , fakeManager .syncedNodes , expectedSyncedNodesCounter )
185206}
186207
187208func verifyExpectedSyncerCount (t * testing.T , syncedNodes [][]string , expectedCount int ) {
@@ -195,6 +216,7 @@ type IGManagerFake struct {
195216}
196217
197218func (igmf * IGManagerFake ) Sync (nodeNames []string , logger klog.Logger ) error {
219+ time .Sleep (2 * time .Second )
198220 igmf .syncedNodes = append (igmf .syncedNodes , nodeNames )
199221 return nil
200222}
0 commit comments