Adding functional tests for psycopg2 integration#528
Adding functional tests for psycopg2 integration#528toumorokoshi merged 10 commits intoopen-telemetry:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #528 +/- ##
==========================================
+ Coverage 88.97% 89.38% +0.41%
==========================================
Files 43 43
Lines 2213 2195 -18
Branches 248 250 +2
==========================================
- Hits 1969 1962 -7
+ Misses 173 161 -12
- Partials 71 72 +1
Continue to review full report at Codecov.
|
| cls._connection.close() | ||
|
|
||
| @fixture(autouse=True) | ||
| def connect_to_db(self): |
There was a problem hiding this comment.
it feels a little weird to me to have a mix of pytest fixtures, and of the standard setup/teardown unittest pattern.
Can we normalize to one or the other? I think given the current precedent on unittest-style, that would be preferable.
since it's autouse, I figure it can be added to the setup/teardown method.
Or, I'm ok with just moving the class level fixtures like cursor to pytest fixtures as well. @c24t for his thoughts, since he's been arguing against pytest fixtures in our codebase.
| def connect_to_db(self): | ||
| if self._connection is None: | ||
| # Try to connect to DB | ||
| for i in range(5): |
There was a problem hiding this comment.
why do we need this retry logic? seems like even if we need it, 5 retries is a lot of times.
There was a problem hiding this comment.
DB will take sometime to startup in docker, maybe having less retries and more wait time?, it could take like 15 or 20 seconds to be ready to receive connections
There was a problem hiding this comment.
Another option is to fail immediately in the tests and replace docker-compose -up with a script that does the same and blocks until the container can accept connections. If possible I think it's a good idea to avoid sleeping at all in tests, and between this and #526 we're looking at adding up to a minute of idle time to an already-slow test suite.
There was a problem hiding this comment.
Added a python script to check DB connections, so tests will not have any sleep but there will be initial script check for all tests, this will improve waiting if something goes wrong with docker setup and test will fail quickly
ext/opentelemetry-ext-docker-tests/tests/postgres/test_psycopg_functional.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-docker-tests/tests/postgres/test_psycopg_functional.py
Outdated
Show resolved
Hide resolved
| with self._tracer.start_as_current_span("rootSpan"): | ||
| try: | ||
| self._cursor.callproc("test", ()) | ||
| except Exception as err: |
There was a problem hiding this comment.
does this exception need to be caught? seems like it's fine to let it raise up.
Even if it's unrelated to our code, exceptions are a separate code path that we should exercise explicitly.
There was a problem hiding this comment.
Stored procedure doesn't exist so callproc will fail but Span will be created, I want to avoid as much pre setup as possible for this tests
There was a problem hiding this comment.
You might want an assertRaises here instead then, the tests generally shouldn't print anything.
| with self._tracer.start_as_current_span("rootSpan"): | ||
| try: | ||
| self._cursor.callproc("test", ()) | ||
| except Exception as err: |
There was a problem hiding this comment.
You might want an assertRaises here instead then, the tests generally shouldn't print anything.
| def connect_to_db(self): | ||
| if self._connection is None: | ||
| # Try to connect to DB | ||
| for i in range(5): |
There was a problem hiding this comment.
Another option is to fail immediately in the tests and replace docker-compose -up with a script that does the same and blocks until the container can accept connections. If possible I think it's a good idea to avoid sleeping at all in tests, and between this and #526 we're looking at adding up to a minute of idle time to an already-slow test suite.
toumorokoshi
left a comment
There was a problem hiding this comment.
Thanks for refactoring out the pytest! (Although I personally would love full pytest).
I still think there's some improvement in the connectivity checks that should be addressed, or else it'll provide incomplete information to others if it fails. Once that's fixed up I'll switch to approved.
Thanks for focusing on this!
| def check_docker_services_availability(): | ||
| try: | ||
| print("Checking Postgres availability") | ||
| check_postgres_connection() |
There was a problem hiding this comment.
should mongo availability also be checked?
There was a problem hiding this comment.
MongoDB have been super fast to be available, will add the logic just to be safe in case this changes.
c24t
left a comment
There was a problem hiding this comment.
Thanks for addressing all the feedback @hectorhdzg, no more blocking comments from me.
toumorokoshi
left a comment
There was a problem hiding this comment.
LGTM, thanks for addressing that!
E2E verification for span creation using psycopg2 and dbapi integrations