Skip to content

Commit

Permalink
chore: extract exporter wait code
Browse files Browse the repository at this point in the history
  • Loading branch information
therightstuff committed Aug 29, 2023
1 parent 84177a1 commit 61b95ae
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 44 deletions.
5 changes: 2 additions & 3 deletions src/test/components/tests/test_attr_max_size.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand All @@ -14,8 +14,7 @@ def test_large_span_attribute_size_max_size_env_var_was_set(self):

assert body is not None

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(4, len(spans_container.spans))
Expand Down
5 changes: 2 additions & 3 deletions src/test/components/tests/test_execution_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand All @@ -14,8 +14,7 @@ def test_execution_tag(self):

assert body is not None

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(4, len(spans_container.spans))
Expand Down
5 changes: 2 additions & 3 deletions src/test/integration/boto3/tests/test_boto3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand Down Expand Up @@ -35,8 +35,7 @@ def test_boto3_instrumentation(self):

self.assertEqual(body, {"status": "ok"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(4, len(spans_container.spans))
Expand Down
11 changes: 4 additions & 7 deletions src/test/integration/fastapi/tests/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand All @@ -14,8 +14,7 @@ def test_200_OK(self):

self.assertEqual(body, {"message": "Hello FastAPI!"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(3, len(spans_container.spans))
Expand Down Expand Up @@ -50,8 +49,7 @@ def test_requests_instrumentation(self):

self.assertIn("https://api.chucknorris.io/jokes/", body["url"])

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(4, len(spans_container.spans))
Expand Down Expand Up @@ -86,8 +84,7 @@ def test_large_span_attribute_size_default_max_size(self):

assert body is not None

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(4, len(spans_container.spans))
Expand Down
8 changes: 3 additions & 5 deletions src/test/integration/flask/tests/test_flask.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand All @@ -14,8 +14,7 @@ def test_200_OK(self):

self.assertEqual(body, {"message": "Hello Flask!"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(1, len(spans_container.spans))
Expand All @@ -37,8 +36,7 @@ def test_requests_instrumentation(self):

self.assertIn("https://api.chucknorris.io/jokes/", body["url"])

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()
self.assertEqual(2, len(spans_container.spans))
Expand Down
9 changes: 4 additions & 5 deletions src/test/integration/grpcio/tests/test_grpcio.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
import unittest
import sys
import os
import sys
import unittest
from test.test_utils.span_exporter import wait_for_exporter

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "app"))

Expand All @@ -20,8 +20,7 @@ def tearDownClass(cls) -> None:
stub.SayHelloUnaryUnary(helloworld_pb2.HelloRequest(name="exit"))

def check_spans(self, method: str, request_payload: str, response_payload: str):
# TODO Do something deterministic
time.sleep(5) # allow the exporter to catch up
wait_for_exporter(5)

server_file = os.getenv("SERVER_SPANDUMP")
server_spans = SpansContainer.get_spans_from_file(server_file)
Expand Down
5 changes: 2 additions & 3 deletions src/test/integration/kafka_python/tests/test_kafka_python.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand Down Expand Up @@ -43,8 +43,7 @@ def test_kafka_python_instrumentation(self):

self.assertEqual(body, {"status": "ok"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()

Expand Down
1 change: 1 addition & 0 deletions src/test/integration/pika/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def invoke_pika_consumer(request: Request):
except Exception as e:
print(f"Exception while consuming messages: {e}")
channel.stop_consuming()
raise e
return {"status": "ok"}


Expand Down
5 changes: 2 additions & 3 deletions src/test/integration/pika/tests/test_pika.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand Down Expand Up @@ -48,8 +48,7 @@ def test_pika_instrumentation(self):

self.assertEqual(body, {"status": "ok"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()

Expand Down
5 changes: 2 additions & 3 deletions src/test/integration/pymongo/tests/test_pymongo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand All @@ -15,8 +15,7 @@ def test_mongo_instrumentation(self):

self.assertEqual(body, {"status": "ok"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()

Expand Down
5 changes: 2 additions & 3 deletions src/test/integration/pymysql/tests/test_pymysql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import unittest
from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

import requests
Expand All @@ -15,8 +15,7 @@ def test_pymysql_instrumentation(self):

self.assertEqual(body, {"status": "ok"})

# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up
wait_for_exporter()

spans_container = SpansContainer.get_spans_from_file()

Expand Down
13 changes: 7 additions & 6 deletions src/test/integration/redis/tests/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import subprocess
import sys
import time
import unittest
from testcontainers.redis import RedisContainer
import subprocess

from test.test_utils.span_exporter import wait_for_exporter
from test.test_utils.spans_parser import SpansContainer

from testcontainers.redis import RedisContainer


class TestRedisSpans(unittest.TestCase):
def test_redis_instrumentation(self):
Expand All @@ -25,8 +25,9 @@ def test_redis_instrumentation(self):
"OTEL_SERVICE_NAME": "app",
},
)
# TODO Do something deterministic
time.sleep(3) # Sleep to allow the exporter to catch up

wait_for_exporter()

spans_container = SpansContainer.parse_spans_from_file()

self.assertGreaterEqual(len(spans_container.spans), 2)
Expand Down
8 changes: 8 additions & 0 deletions src/test/test_utils/span_exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import time


def wait_for_exporter(wait_time_sec: int = 3):
"""Wait for the exporter to have collected all the spans."""

# TODO Do something deterministic
time.sleep(wait_time_sec) # Sleep to allow the exporter to catch up

0 comments on commit 61b95ae

Please sign in to comment.