Esempio n. 1
0
 def test_TransactionTimer(self):
     """Test basic interface of TransactionTimer."""
     transaction_timer = TransactionTimer()
     self.assertEqual(transaction_timer.get_transaction_time(), None)
     transaction_timer.start_transaction()
     self.assertNotEqual(transaction_timer.get_transaction_time(), None)
     transaction_timer.end_transaction()
     self.assertEqual(transaction_timer.get_transaction_time(), None)
 def test_TransactionTimer(self):
     """Test basic interface of TransactionTimer."""
     transaction_timer = TransactionTimer()
     self.assertEqual(transaction_timer.get_transaction_time(), None)
     transaction_timer.start_transaction()
     self.assertNotEqual(transaction_timer.get_transaction_time(), None)
     transaction_timer.end_transaction()
     self.assertEqual(transaction_timer.get_transaction_time(), None)
Esempio n. 3
0
    def test_thread_isolation(self):
        """Different threads do not interfere with each other."""
        transaction_timer = TransactionTimer()
        event1 = threading.Event()
        event2 = threading.Event()

        def worker():
            """Start and finish a transaction in a thread."""
            self.assertEqual(transaction_timer.get_transaction_time(), None)
            transaction_timer.start_transaction()
            event1.set()
            event2.wait()
            self.assertNotEqual(transaction_timer.get_transaction_time(), None)
            transaction_timer.end_transaction()

        transaction_timer.start_transaction()
        thread = threading.Thread(target=worker)
        thread.start()
        event1.wait()
        transaction_timer.end_transaction()
        event2.set()
        thread.join()
    def test_thread_isolation(self):
        """Different threads do not interfere with each other."""
        transaction_timer = TransactionTimer()
        event1 = threading.Event()
        event2 = threading.Event()

        def worker():
            """Start and finish a transaction in a thread."""
            self.assertEqual(transaction_timer.get_transaction_time(), None)
            transaction_timer.start_transaction()
            event1.set()
            event2.wait()
            self.assertNotEqual(transaction_timer.get_transaction_time(), None)
            transaction_timer.end_transaction()

        transaction_timer.start_transaction()
        thread = threading.Thread(target=worker)
        thread.start()
        event1.wait()
        transaction_timer.end_transaction()
        event2.set()
        thread.join()