Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job 312 #459

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,38 @@ jobs:
- store-pytest-results
- store-coverage-report

python312:
docker:
- image: python:3.12
- image: cimg/postgres:9.6.24
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: ''
POSTGRES_DB: circle_test
- image: cimg/mariadb:10.11.2
- image: cimg/redis:5.0.14
- image: rabbitmq:3.9.13
- image: mongo:4.2.3
- image: egymgmbh/pubsub-emulator
command:
- test-project
- test-topic
- test-subscription
working_directory: ~/repo
steps:
- run:
name: Install extra Python Dependencies for 3.12
command: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source ~/.cargo/env

- checkout
- pip-install-deps:
requirements: "tests/requirements-312.txt"
- run-tests-with-coverage-report
- store-pytest-results
- store-coverage-report

py38couchbase:
docker:
- image: cimg/python:3.8.17
Expand Down Expand Up @@ -259,6 +291,7 @@ workflows:
- python39
- python310
- python311
- python312
- py37cassandra
- py38couchbase
- py38gevent
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ htmlcov/
.coverage
.coverage.*
.cache
nosetests.xml
nosetests.json
coverage.xml
*,cover
.hypothesis/
Expand Down
85 changes: 41 additions & 44 deletions tests/clients/test_pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import logging
import pytest

from nose.tools import (assert_is_none, assert_is_not_none,
assert_false, assert_true, assert_list_equal)

from ..helpers import testenv
from instana.singletons import tracer

Expand All @@ -26,21 +23,21 @@

class TestPyMongoTracer(unittest.TestCase):
def setUp(self):
self.conn = pymongo.MongoClient(host=testenv['mongodb_host'], port=int(testenv['mongodb_port']),
username=testenv['mongodb_user'], password=testenv['mongodb_pw'])
self.conn.test.records.delete_many(filter={})
self.client = pymongo.MongoClient(host=testenv['mongodb_host'], port=int(testenv['mongodb_port']),
username=testenv['mongodb_user'], password=testenv['mongodb_pw'])
self.client.test.records.delete_many(filter={})

self.recorder = tracer.recorder
self.recorder.clear_spans()

def tearDown(self):
return None
self.client.close()

def test_successful_find_query(self):
with tracer.start_active_span("test"):
self.conn.test.records.find_one({"type": "string"})
self.client.test.records.find_one({"type": "string"})

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 2)
Expand All @@ -51,21 +48,21 @@ def test_successful_find_query(self):
self.assertEqual(test_span.t, db_span.t)
self.assertEqual(db_span.p, test_span.s)

assert_is_none(db_span.ec)
self.assertIsNone(db_span.ec)

self.assertEqual(db_span.n, "mongo")
self.assertEqual(db_span.data["mongo"]["service"], "%s:%s" % (testenv['mongodb_host'], testenv['mongodb_port']))
self.assertEqual(db_span.data["mongo"]["namespace"], "test.records")
self.assertEqual(db_span.data["mongo"]["command"], "find")

self.assertEqual(db_span.data["mongo"]["filter"], '{"type": "string"}')
assert_is_none(db_span.data["mongo"]["json"])
self.assertIsNone(db_span.data["mongo"]["json"])

def test_successful_insert_query(self):
with tracer.start_active_span("test"):
self.conn.test.records.insert_one({"type": "string"})
self.client.test.records.insert_one({"type": "string"})

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 2)
Expand All @@ -76,20 +73,20 @@ def test_successful_insert_query(self):
self.assertEqual(test_span.t, db_span.t)
self.assertEqual(db_span.p, test_span.s)

assert_is_none(db_span.ec)
self.assertIsNone(db_span.ec)

self.assertEqual(db_span.n, "mongo")
self.assertEqual(db_span.data["mongo"]["service"], "%s:%s" % (testenv['mongodb_host'], testenv['mongodb_port']))
self.assertEqual(db_span.data["mongo"]["namespace"], "test.records")
self.assertEqual(db_span.data["mongo"]["command"], "insert")

assert_is_none(db_span.data["mongo"]["filter"])
self.assertIsNone(db_span.data["mongo"]["filter"])

def test_successful_update_query(self):
with tracer.start_active_span("test"):
self.conn.test.records.update_one({"type": "string"}, {"$set": {"type": "int"}})
self.client.test.records.update_one({"type": "string"}, {"$set": {"type": "int"}})

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 2)
Expand All @@ -100,29 +97,29 @@ def test_successful_update_query(self):
self.assertEqual(test_span.t, db_span.t)
self.assertEqual(db_span.p, test_span.s)

assert_is_none(db_span.ec)
self.assertIsNone(db_span.ec)

self.assertEqual(db_span.n, "mongo")
self.assertEqual(db_span.data["mongo"]["service"], "%s:%s" % (testenv['mongodb_host'], testenv['mongodb_port']))
self.assertEqual(db_span.data["mongo"]["namespace"], "test.records")
self.assertEqual(db_span.data["mongo"]["command"], "update")

assert_is_none(db_span.data["mongo"]["filter"])
assert_is_not_none(db_span.data["mongo"]["json"])
self.assertIsNone(db_span.data["mongo"]["filter"])
self.assertIsNotNone(db_span.data["mongo"]["json"])

payload = json.loads(db_span.data["mongo"]["json"])
assert_true({
self.assertIn({
"q": {"type": "string"},
"u": {"$set": {"type": "int"}},
"multi": False,
"upsert": False
} in payload, db_span.data["mongo"]["json"])
}, payload)

def test_successful_delete_query(self):
with tracer.start_active_span("test"):
self.conn.test.records.delete_one(filter={"type": "string"})
self.client.test.records.delete_one(filter={"type": "string"})

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 2)
Expand All @@ -133,24 +130,24 @@ def test_successful_delete_query(self):
self.assertEqual(test_span.t, db_span.t)
self.assertEqual(db_span.p, test_span.s)

assert_is_none(db_span.ec)
self.assertIsNone(db_span.ec)

self.assertEqual(db_span.n, "mongo")
self.assertEqual(db_span.data["mongo"]["service"], "%s:%s" % (testenv['mongodb_host'], testenv['mongodb_port']))
self.assertEqual(db_span.data["mongo"]["namespace"], "test.records")
self.assertEqual(db_span.data["mongo"]["command"], "delete")

assert_is_none(db_span.data["mongo"]["filter"])
assert_is_not_none(db_span.data["mongo"]["json"])
self.assertIsNone(db_span.data["mongo"]["filter"])
self.assertIsNotNone(db_span.data["mongo"]["json"])

payload = json.loads(db_span.data["mongo"]["json"])
assert_true({"q": {"type": "string"}, "limit": 1} in payload, db_span.data["mongo"]["json"])
self.assertIn({"q": {"type": "string"}, "limit": 1}, payload)

def test_successful_aggregate_query(self):
with tracer.start_active_span("test"):
self.conn.test.records.count_documents({"type": "string"})
self.client.test.records.count_documents({"type": "string"})

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 2)
Expand All @@ -161,29 +158,29 @@ def test_successful_aggregate_query(self):
self.assertEqual(test_span.t, db_span.t)
self.assertEqual(db_span.p, test_span.s)

assert_is_none(db_span.ec)
self.assertIsNone(db_span.ec)

self.assertEqual(db_span.n, "mongo")
self.assertEqual(db_span.data["mongo"]["service"], "%s:%s" % (testenv['mongodb_host'], testenv['mongodb_port']))
self.assertEqual(db_span.data["mongo"]["namespace"], "test.records")
self.assertEqual(db_span.data["mongo"]["command"], "aggregate")

assert_is_none(db_span.data["mongo"]["filter"])
assert_is_not_none(db_span.data["mongo"]["json"])
self.assertIsNone(db_span.data["mongo"]["filter"])
self.assertIsNotNone(db_span.data["mongo"]["json"])

payload = json.loads(db_span.data["mongo"]["json"])
assert_true({"$match": {"type": "string"}} in payload, db_span.data["mongo"]["json"])
self.assertIn({"$match": {"type": "string"}}, payload)

@pymongoversion
def test_successful_map_reduce_query(self):
mapper = "function () { this.tags.forEach(function(z) { emit(z, 1); }); }"
reducer = "function (key, values) { return len(values); }"

with tracer.start_active_span("test"):
self.conn.test.records.map_reduce(bson.code.Code(mapper), bson.code.Code(reducer), "results",
self.client.test.records.map_reduce(bson.code.Code(mapper), bson.code.Code(reducer), "results",
query={"x": {"$lt": 2}})

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 2)
Expand All @@ -194,7 +191,7 @@ def test_successful_map_reduce_query(self):
self.assertEqual(test_span.t, db_span.t)
self.assertEqual(db_span.p, test_span.s)

assert_is_none(db_span.ec)
self.assertIsNone(db_span.ec)

self.assertEqual(db_span.n, "mongo")
self.assertEqual(db_span.data["mongo"]["service"], "%s:%s" % (testenv['mongodb_host'], testenv['mongodb_port']))
Expand All @@ -203,19 +200,19 @@ def test_successful_map_reduce_query(self):
"mapreduce") # mapreduce command was renamed to mapReduce in pymongo 3.9.0

self.assertEqual(db_span.data["mongo"]["filter"], '{"x": {"$lt": 2}}')
assert_is_not_none(db_span.data["mongo"]["json"])
self.assertIsNotNone(db_span.data["mongo"]["json"])

payload = json.loads(db_span.data["mongo"]["json"])
self.assertEqual(payload["map"], {"$code": mapper}, db_span.data["mongo"]["json"])
self.assertEqual(payload["reduce"], {"$code": reducer}, db_span.data["mongo"]["json"])

def test_successful_mutiple_queries(self):
with tracer.start_active_span("test"):
self.conn.test.records.bulk_write([pymongo.InsertOne({"type": "string"}),
pymongo.UpdateOne({"type": "string"}, {"$set": {"type": "int"}}),
pymongo.DeleteOne({"type": "string"})])
self.client.test.records.bulk_write([pymongo.InsertOne({"type": "string"}),
pymongo.UpdateOne({"type": "string"}, {"$set": {"type": "int"}}),
pymongo.DeleteOne({"type": "string"})])

assert_is_none(tracer.active_span)
self.assertIsNone(tracer.active_span)

spans = self.recorder.queued_spans()
self.assertEqual(len(spans), 4)
Expand All @@ -229,11 +226,11 @@ def test_successful_mutiple_queries(self):
self.assertEqual(span.p, test_span.s)

# check if all spans got a unique id
assert_false(span.s in seen_span_ids)
self.assertNotIn(span.s, seen_span_ids)

seen_span_ids.add(span.s)
commands.append(span.data["mongo"]["command"])

# ensure spans are ordered the same way as commands
assert_list_equal(commands, ["insert", "update", "delete"])
self.assertListEqual(commands, ["insert", "update", "delete"])

21 changes: 14 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import sys
import pytest

# Set our testing flags
os.environ["INSTANA_TEST"] = "true"
# os.environ["INSTANA_DEBUG"] = "true"

# Make sure the instana package is fully loaded
import instana

collect_ignore_glob = []

# Cassandra and gevent tests are run in dedicated jobs on CircleCI and will
Expand All @@ -28,13 +35,13 @@
# tests/opentracing/test_ot_span.py::TestOTSpan::test_stacks
# TODO: Remove that once we find a workaround or DROP opentracing!

# Set our testing flags
os.environ["INSTANA_TEST"] = "true"
# os.environ["INSTANA_DEBUG"] = "true"

# Make sure the instana package is fully loaded
import instana

if sys.version_info.minor >= 12:
# Currently the dependencies of sanic and aiohttp are not installable on 3.12
# PyLongObject’ {aka ‘struct _longobject’} has no member named ‘ob_digit’
collect_ignore_glob.append("*test_sanic*")
collect_ignore_glob.append("*test_aiohttp*")
# The asyncio also depends on aiohttp
collect_ignore_glob.append("*test_asyncio*")

@pytest.fixture(scope='session')
def celery_config():
Expand Down
3 changes: 1 addition & 2 deletions tests/frameworks/test_tornado_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import tests.apps.tornado_server
from ..helpers import testenv

from nose.plugins.skip import SkipTest
raise SkipTest("Non deterministic tests TBR")
raise unittest.SkipTest("Non deterministic tests TBR")

class TestTornadoClient(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/opentracing/test_opentracing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2020

from nose.plugins.skip import SkipTest
from unittest import SkipTest
from opentracing.harness.api_check import APICompatibilityCheckMixin

from instana.tracer import InstanaTracer
Expand Down
Loading
Loading