Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
reyang committed May 10, 2019
1 parent 1ca8a00 commit e0a59bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def emit(self, batch, event=None):
if len(batch) < self.options.max_batch_size:
self._transmit_from_storage()
except Exception as ex:
logger.error('Transmission exception: %s.', ex)
logger.exception('Transmission exception: %s.', ex)

def _stop(self, timeout=None):
self.storage.close()
Expand Down
10 changes: 10 additions & 0 deletions contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ def test_emit_empty(self, request_mock):
self.assertEqual(len(os.listdir(exporter.storage.path)), 0)
exporter._stop()

@mock.patch('opencensus.ext.azure.trace_exporter.logger')
def test_emit_exception(self, mock_logger):
exporter = trace_exporter.AzureExporter(
instrumentation_key='12345678-1234-5678-abcd-12345678abcd',
storage_path=os.path.join(TEST_FOLDER, self.id()),
)
exporter.emit([1, 2, 3])
mock_logger.exception.assert_called()
exporter._stop()

@mock.patch('opencensus.ext.azure.trace_exporter.AzureExporter.span_data_to_envelope') # noqa: E501
def test_emit_failure(self, span_data_to_envelope_mock):
span_data_to_envelope_mock.return_value = ['bar']
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/common/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
TIMEOUT = .1


class TestQueueEvent(unittest.TestCase):
def test_basic(self):
evt = QueueEvent('foobar')
self.assertFalse(evt.wait(timeout=TIMEOUT))
evt.set()
self.assertTrue(evt.wait(timeout=TIMEOUT))

class TestQueue(unittest.TestCase):
def test_gets(self):
queue = Queue(capacity=100)
Expand Down

0 comments on commit e0a59bd

Please sign in to comment.