Skip to content

Commit

Permalink
- Fix shim tests on windows
Browse files Browse the repository at this point in the history
- Add helper methods to base test class
  • Loading branch information
owais committed Aug 29, 2021
1 parent 6b41c2f commit 59f41a4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ jobs:
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: .tox
key: tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
path: |
.tox
~/.cache/pip
key: v1-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
# tox fails on windows and Python3.6 when tox dir is reused between builds so we remove it
- name: fix for windows + py3.6
if: ${{ matrix.os == 'windows-latest' && matrix.python-version == 'py36' }}
shell: pwsh
run: Remove-Item .\.tox\ -Force -Recurse -ErrorAction Ignore
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
- name: Find and merge benchmarks
Expand Down Expand Up @@ -101,8 +108,10 @@ jobs:
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: .tox
key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
path: |
.tox
~/.cache/pip
key: v1-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-core
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
contrib-build:
Expand Down Expand Up @@ -141,8 +150,10 @@ jobs:
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: .tox
key: tox-cache-${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
path: |
.tox
~/.cache/pip
key: v1-tox-cache-${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }}
contrib-misc:
Expand Down Expand Up @@ -173,7 +184,9 @@ jobs:
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v2
with:
path: .tox
key: tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
path: |
.tox
~/.cache/pip
key: v1-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}-contrib
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ async def do_task():
spans = self.tracer.finished_spans()
self.assertEqual(len(spans), 3)

spans = sorted(spans, key=lambda x: x.start_time)
parent_span = get_one_by_operation_name(spans, "parent")
self.assertIsNotNone(parent_span)

self.assertIsChildOf(spans[1], parent_span)
self.assertIsNotChildOf(spans[2], parent_span)
spans = [span for span in spans if span != parent_span]
self.assertIsChildOf(spans[0], parent_span)
self.assertIsNotChildOf(spans[1], parent_span)
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@ def test_bad_solution_to_set_parent(self):
parent_span = get_one_by_operation_name(spans, "parent")
self.assertIsNotNone(parent_span)

self.assertIsChildOf(spans[1], parent_span)
self.assertIsChildOf(spans[2], parent_span)
spans = [s for s in spans if s.name == "send"]
for span in spans:
if span == parent_span:
continue
self.assertIsChildOf(span, parent_span)
33 changes: 31 additions & 2 deletions tests/util/src/opentelemetry/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,27 @@ def tearDownClass(cls):
def setUp(self):
self.memory_exporter.clear()

def check_span_instrumentation_info(self, span, module):
def get_finished_spans(self):
return FinishedTestSpans(
self, self.memory_exporter.get_finished_spans()
)

def assertSpanInstrumentationInfo(self, span, module):
self.assertEqual(span.instrumentation_info.name, module.__name__)
self.assertEqual(span.instrumentation_info.version, module.__version__)

def assert_span_has_attributes(self, span, attributes):
def assertSpanHasAttributes(self, span, attributes):
for key, val in attributes.items():
self.assertIn(key, span.attributes)
self.assertEqual(val, span.attributes[key])

def sorted_spans(self, spans): # pylint: disable=R0201
"""
Sorts spans by span creation time.
Note: This method should not be used to sort spans in a deterministic way as the
order depends on timing precision provided by the platform.
"""
return sorted(
spans,
key=lambda s: s._start_time, # pylint: disable=W0212
Expand Down Expand Up @@ -89,3 +100,21 @@ def disable_logging(highest_level=logging.CRITICAL):
yield
finally:
logging.disable(logging.NOTSET)


class FinishedTestSpans(list):
def __init__(self, test, spans):
super().__init__(spans)
self.test = test

def by_name(self, name):
for span in self:
if span.name == name:
return span
self.test.fail("Did not find span with name {}".format(name))

def by_attr(self, key, value):
for span in self:
if span.attributes.get(key) == value:
return span
self.test.fail("Did not find span with attrs {}={}".format(key, value))

0 comments on commit 59f41a4

Please sign in to comment.