Beispiel #1
0
	def test_transcation(self, time_mock, statsd_timing_mock, _):
		time_start = time.time()
		time_mock.time.return_value = time_start

		transaction = carpy.transaction.Transaction(name='Test')
		self.assertEqual(transaction.app_name, carpy.config['APP_NAME'])
		self.assertEqual(transaction.name, 'Test')
		self.assertEqual(transaction.start_time, 0.0)
		self.assertEqual(transaction.duration, 0.0)

		transaction.__enter__()
		self.assertEqual(transaction.start_time, time_start)
		self.assertIs(carpy.transaction.transactions_cache[carpy.transaction.get_thread_id()], transaction)

		time_end = time_start + 5
		time_mock.time.return_value = time_end

		transaction.__exit__()
		self.assertEqual(transaction.duration, time_end - time_start)
		self.assertEqual(statsd_timing_mock.call_count, 1)

		del transaction
		gc.collect()
		self.assertFalse(carpy.transaction.get_thread_id() in carpy.transaction.transactions_cache)
		self.assertIs(carpy.transaction.transactions_cache.get(carpy.transaction.get_thread_id()), None)
Beispiel #2
0
	def test_get_transaction(self):
		transaction = carpy.transaction.Transaction('Name')
		transaction.__enter__()

		self.assertIs(carpy.transaction.get_transaction(), transaction)