Revision 27caa993 test/ganeti.workerpool_unittest.py

b/test/ganeti.workerpool_unittest.py
170 170
      wp.TerminateWorkers()
171 171
      self._CheckWorkerCount(wp, 0)
172 172

  
173
  def testActive(self):
174
    ctx = CountingContext()
175
    wp = workerpool.WorkerPool("TestActive", 5, CountingBaseWorker)
176
    try:
177
      self._CheckWorkerCount(wp, 5)
178
      self.assertTrue(wp._active)
179

  
180
      # Process some tasks
181
      for _ in range(10):
182
        wp.AddTask((ctx, None))
183

  
184
      wp.Quiesce()
185
      self._CheckNoTasks(wp)
186
      self.assertEquals(ctx.GetDoneTasks(), 10)
187

  
188
      # Repeat a few times
189
      for count in range(10):
190
        # Deactivate pool
191
        wp.SetActive(False)
192
        self._CheckNoTasks(wp)
193

  
194
        # Queue some more tasks
195
        for _ in range(10):
196
          wp.AddTask((ctx, None))
197

  
198
        for _ in range(5):
199
          # Short delays to give other threads a chance to cause breakage
200
          time.sleep(.01)
201
          wp.AddTask((ctx, "Hello world %s" % 999))
202
          self.assertFalse(wp._active)
203

  
204
        self.assertEquals(ctx.GetDoneTasks(), 10 + (count * 15))
205

  
206
        # Start processing again
207
        wp.SetActive(True)
208
        self.assertTrue(wp._active)
209

  
210
        # Wait for tasks to finish
211
        wp.Quiesce()
212
        self._CheckNoTasks(wp)
213
        self.assertEquals(ctx.GetDoneTasks(), 10 + (count * 15) + 15)
214

  
215
        self._CheckWorkerCount(wp, 5)
216
    finally:
217
      wp.TerminateWorkers()
218
      self._CheckWorkerCount(wp, 0)
219

  
173 220
  def testChecksum(self):
174 221
    # Tests whether all tasks are run and, since we're only using a single
175 222
    # thread, whether everything is started in order.

Also available in: Unified diff