Skip to content

Commit fde15c1

Browse files
committed
refactor: Remove TestAgent from the production code.
Remove the TestAgent and the if-blocks that check if running in a test environment from the production code. Signed-off-by: Paulo Vital <[email protected]>
1 parent aaaf954 commit fde15c1

File tree

16 files changed

+93
-106
lines changed

16 files changed

+93
-106
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ commands:
5656
- run:
5757
name: Run Tests With Coverage Report
5858
environment:
59-
INSTANA_TEST: "true"
6059
CASSANDRA_TEST: "<<parameters.cassandra>>"
6160
COUCHBASE_TEST: "<<parameters.couchbase>>"
6261
GEVENT_STARLETTE_TEST: "<<parameters.gevent>>"

.tekton/run_unittests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ esac
5252

5353
echo -n "Configuration is '${TEST_CONFIGURATION}' on ${PYTHON_VERSION} "
5454
echo "with dependencies in '${REQUIREMENTS}'"
55-
export INSTANA_TEST='true'
5655
ls -lah .
5756
if [[ -n "${COUCHBASE_TEST}" ]]; then
5857
echo "Install Couchbase Dependencies"

src/instana/agent/host.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ def can_send(self):
104104
Are we in a state where we can send data?
105105
@return: Boolean
106106
"""
107-
if "INSTANA_TEST" in os.environ:
108-
return True
109-
110107
# Watch for pid change (fork)
111108
self.last_fork_check = datetime.now()
112109
current_pid = os.getpid()

src/instana/agent/test.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/instana/collector/aws_fargate.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from instana.collector.helpers.runtime import RuntimeHelper
2020
from instana.collector.utils import format_span
2121
from instana.log import logger
22-
from instana.singletons import env_is_test
2322
from instana.util import DictionaryOfStan, validate_url
2423

2524

@@ -100,10 +99,6 @@ def get_ecs_metadata(self):
10099
Get the latest data from the ECS metadata container API and store on the class
101100
@return: Boolean
102101
"""
103-
if env_is_test is True:
104-
# For test, we are using mock ECS metadata
105-
return
106-
107102
try:
108103
self.fetching_start_time = int(time())
109104
delta = self.fetching_start_time - self.last_ecmu_full_fetch

src/instana/collector/base.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
import queue # pylint: disable=import-error
1010
import threading
11-
from os import environ
1211

1312
from instana.log import logger
1413
from instana.util import DictionaryOfStan, every
1514

16-
# TODO: Use mock.patch() or unittest.mock to mock the testing env
17-
env_is_test = "INSTANA_TEST" in environ
18-
1915

2016
class BaseCollector(object):
2117
"""
@@ -31,16 +27,7 @@ def __init__(self, agent):
3127
self.THREAD_NAME = "Instana Collector"
3228

3329
# The Queue where we store finished spans before they are sent
34-
if env_is_test:
35-
# Override span queue with a multiprocessing version
36-
# The test suite runs background applications - some in background threads,
37-
# others in background processes. This multiprocessing queue allows us to collect
38-
# up spans from all sources.
39-
import multiprocessing
40-
41-
self.span_queue = multiprocessing.Queue()
42-
else:
43-
self.span_queue = queue.Queue()
30+
self.span_queue = queue.Queue()
4431

4532
# The Queue where we store finished profiles before they are sent
4633
self.profile_queue = queue.Queue()
@@ -163,8 +150,6 @@ def prepare_and_report_data(self):
163150
Prepare and report the data payload.
164151
@return: Boolean
165152
"""
166-
if env_is_test:
167-
return True
168153
with self.background_report_lock:
169154
payload = self.prepare_payload()
170155
self.agent.report_data_payload(payload)

src/instana/fsm.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ def __init__(self, agent):
6767
self.timer = threading.Timer(1, self.fsm.lookup)
6868
self.timer.daemon = True
6969
self.timer.name = self.THREAD_NAME
70-
71-
# Only start the announce process when not in Test
72-
if not "INSTANA_TEST" in os.environ:
73-
self.timer.start()
70+
self.timer.start()
7471

7572
@staticmethod
7673
def print_state_change(e):

src/instana/recorder.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ def queued_spans(self) -> List[ReadableSpan]:
4141
span = None
4242
spans = []
4343

44-
import time
45-
46-
from .singletons import env_is_test
47-
48-
if env_is_test is True:
49-
time.sleep(1)
50-
5144
if self.agent.collector.span_queue.empty() is True:
5245
return spans
5346

src/instana/singletons.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
# Detect the environment where we are running ahead of time
1717
aws_env = os.environ.get("AWS_EXECUTION_ENV", "")
18-
env_is_test = "INSTANA_TEST" in os.environ
1918
env_is_aws_fargate = aws_env == "AWS_ECS_FARGATE"
2019
env_is_aws_eks_fargate = (
2120
os.environ.get("INSTANA_TRACER_ENVIRONMENT") == "AWS_EKS_FARGATE"
@@ -29,15 +28,7 @@
2928
(k_service, k_configuration, k_revision, instana_endpoint_url)
3029
)
3130

32-
if env_is_test:
33-
from .agent.test import TestAgent
34-
from .recorder import StanRecorder
35-
36-
agent = TestAgent()
37-
span_recorder = StanRecorder(agent)
38-
profiler = Profiler(agent)
39-
40-
elif env_is_aws_lambda:
31+
if env_is_aws_lambda:
4132
from .agent.aws_lambda import AWSLambdaAgent
4233
from .recorder import StanRecorder
4334

tests/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import os
55

6-
os.environ["INSTANA_TEST"] = "true"
7-
86
if os.environ.get('GEVENT_STARLETTE_TEST'):
97
from gevent import monkey
108
monkey.patch_all()

0 commit comments

Comments
 (0)