Example #1
0
 def testMultiThreadedCounterUpdates(self):
     n = 250000  # perform this many increment/decrement/get operations per thread
     c = Counter()
     value = 1000000
     c.set(value)
     self.assertEqual(value, c.get())
     threads = []
     for i in range(8):
         ops = ['+' for x in range(n)] + ['-' for x in range(n)
                                          ] + ['R' for x in range(n)]
         random.shuffle(ops)
         threads.append(
             threading.Thread(target=self._updateThread, args=(c, ops)))
     for t in threads:
         t.start()
     for t in threads:
         t.join()
     self.assertEqual(value, c.get())
Example #2
0
 def testDecrementValue(self):
     c = Counter()
     c.set(1)
     c.decrement()
     self.assertEqual(0, c.get())
Example #3
0
 def testIncrementValue(self):
     c = Counter()
     c.set(1)
     c.increment()
     self.assertEqual(2, c.get())
Example #4
0
 def testSetValue(self):
     c = Counter()
     c.set(1)
     self.assertEqual(1, c.get())
Example #5
0
 def testDecrementNoneValue(self):
     c = Counter()
     c.decrement()
     self.assertEqual(None, c.get())
Example #6
0
 def testInitSetsValueToNone(self):
     c = Counter()
     self.assertEqual(None, c.get())