Skip to content

Commit

Permalink
Use sleep to avoid resolution errors in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Oct 5, 2023
1 parent 3fae820 commit 6a81afa
Showing 1 changed file with 10 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from itertools import count
from platform import system
from time import sleep
from unittest import TestCase

from pytest import mark
Expand All @@ -28,14 +29,6 @@


class TestSumAggregation(TestCase):
@mark.skipif(
system() != "Linux",
reason=(
"Tests fail because Windows time_ns resolution is too low so "
"two different time measurements may end up having the exact same"
"value."
),
)
def test_asynchronous_delta_temporality(self):

eight_multiple_generator = count(start=8, step=8)
Expand Down Expand Up @@ -73,7 +66,7 @@ def observable_counter_callback(callback_options):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

self.assertEqual(counter, 10)
Expand All @@ -84,7 +77,7 @@ def observable_counter_callback(callback_options):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

self.assertEqual(counter, 20)
Expand Down Expand Up @@ -143,7 +136,7 @@ def observable_counter_callback(callback_options):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

self.assertEqual(counter, 30)
Expand All @@ -153,14 +146,6 @@ def observable_counter_callback(callback_options):
for metrics_data in results:
self.assertIsNone(metrics_data)

@mark.skipif(
system() != "Linux",
reason=(
"Tests fail because Windows time_ns resolution is too low so "
"two different time measurements may end up having the exact same"
"value."
),
)
def test_asynchronous_cumulative_temporality(self):

eight_multiple_generator = count(start=8, step=8)
Expand Down Expand Up @@ -198,7 +183,7 @@ def observable_counter_callback(callback_options):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

self.assertEqual(counter, 10)
Expand All @@ -209,7 +194,7 @@ def observable_counter_callback(callback_options):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

self.assertEqual(counter, 20)
Expand Down Expand Up @@ -240,7 +225,7 @@ def observable_counter_callback(callback_options):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

self.assertEqual(counter, 30)
Expand All @@ -250,14 +235,6 @@ def observable_counter_callback(callback_options):
for metrics_data in results:
self.assertIsNone(metrics_data)

@mark.skipif(
system() != "Linux",
reason=(
"Tests fail because Windows time_ns resolution is too low so "
"two different time measurements may end up having the exact same"
"value."
),
)
def test_synchronous_delta_temporality(self):

aggregation = SumAggregation()
Expand All @@ -275,7 +252,7 @@ def test_synchronous_delta_temporality(self):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

for metrics_data in results:
Expand All @@ -285,6 +262,7 @@ def test_synchronous_delta_temporality(self):

for _ in range(10):
counter.add(8)
sleep(0)
results.append(reader.get_metrics_data())

previous_time_unix_nano = (
Expand Down Expand Up @@ -341,22 +319,14 @@ def test_synchronous_delta_temporality(self):
results = []

for _ in range(10):

sleep(0)
results.append(reader.get_metrics_data())

provider.shutdown()

for metrics_data in results:
self.assertIsNone(metrics_data)

@mark.skipif(
system() != "Linux",
reason=(
"Tests fail because Windows time_ns resolution is too low so "
"two different time measurements may end up having the exact same"
"value."
),
)
def test_synchronous_cumulative_temporality(self):

aggregation = SumAggregation()
Expand Down

0 comments on commit 6a81afa

Please sign in to comment.