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

Port of redis code improvements from prior revision #1132

Merged
merged 4 commits into from
Mar 3, 2021

Conversation

matteius
Copy link
Contributor

This brings back the naming convention refactor and the test cases to make use of the fakeredis testing module which allowed me to introduce some new tests and cleanup how imports were handled in the test file. This was lost when my prior "redis fix" was reverted: https://github.com/celery/kombu/pull/1106/files

The changes here are more minimal and change not how the redis module functions, but changes it to be more readable and to update the test class to be more complete.

@auvipy auvipy added this to the 4.7 milestone Dec 18, 2019
@auvipy auvipy self-requested a review December 18, 2019 21:49
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check that this won't break celery master?

@matteius
Copy link
Contributor Author

@auvipy It should not break master -- there are no merge conflicts and the travis-ci passes. It is not functional changes but rather refactoring.

@auvipy
Copy link
Member

auvipy commented Dec 18, 2019

I am talking about celery master, not kombu

@matteius
Copy link
Contributor Author

@auvipy Does not break celery master, that code base does not reference _q_for_pri which is a private kombu method. Otherwise the changes were isolated to code kombu code readability and redis unit testing enhancements

kombu/transport/redis.py Outdated Show resolved Hide resolved
kombu/transport/redis.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Dec 29, 2019

Codecov Report

Merging #1132 into master will decrease coverage by 0.22%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1132      +/-   ##
==========================================
- Coverage   88.83%   88.61%   -0.23%     
==========================================
  Files          65       65              
  Lines        6788     6796       +8     
  Branches      815      816       +1     
==========================================
- Hits         6030     6022       -8     
- Misses        665      678      +13     
- Partials       93       96       +3
Impacted Files Coverage Δ
kombu/transport/redis.py 88.69% <100%> (-2.48%) ⬇️
kombu/transport/virtual/base.py 98.23% <0%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe5adb5...9b8bf9a. Read the comment docs.

@matteius
Copy link
Contributor Author

@auvipy This one has been updated for review again.

@matteius
Copy link
Contributor Author

matteius commented Jan 3, 2020

I spent days on this before this summer and when the original PR was reverted I was heart broken so I thought to make the best of it I would capture the testing bits and other variable naming improvements that is not functional code changes, and so to see it sit here and linger and be not considered important is again heart breaking. Especially when on the other half of my PRs that have no testing the common ask is for testing, but we need to enhance the Redis tests and that is exactly what this PR does!

@thedrow
Copy link
Member

thedrow commented Jan 6, 2020

LGTM.

Copy link
Contributor

@shaib shaib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments. Must admit that I am not a good evaluator here -- I am not familiar with Kombu and what needs to be tested about it, so the comments are mostly general.

else:
queue_args = (queue, '', '')
priority_queue_name = '%s%s%s' % queue_args
return priority_queue_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a question of taste, I guess, but IMO this rewrite of the function is not an improvement. The 2-line version was clear enough, and easier to read.

class FakeRedisKombuTransport(FakeRedisKombuTransportLite):
Channel = FakeRedisKombuChannel


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, without getting into too much detail -- the above is nearly 500 lines of adaptations and setting up clients on top of FakeRedis.

  1. If you're already refactoring, I'd take these out to their own file. Maybe more than one.
  2. Why is all this necessary? there seem to be no comments explaining it, and coming in knowing nothing, I'd basically expect a FakeRedis-based test-suite to just set up FakeRedis as the Redis server, and then run everything, as is, against that -- 10-20 lines of setup before the actual tests begin, not 500.

I note that about half of these lines are pre-existing, but IIUC that was before FakeRedis -- so the test basically included "a small FakeRedis" inside it. Now that an actual FakeRedis is used, I'd expect these to go away. Or, otherwise, explain the need for them.

Comment on lines +520 to +523
global _fake_redis_client
_fake_redis_client = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is tearDown() tearing down something setUp() did not set up?

Comment on lines 1055 to 1056
except Exception:
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have a try-block, then?

Comment on lines 1124 to 1127
conn_kwargs = dict(
transport=FakeRedisKombuTransport,
transport_options={'sep': ':'})
with Connection(**conn_kwargs) as conn:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

        with Connection(
            transport=FakeRedisKombuTransport,
            transport_options={'sep': ':'},
        ) as conn:

Comment on lines +23 to +29
_fake_redis_client = None


def _get_fake_redis_client():
global _fake_redis_client
if _fake_redis_client is None:
_fake_redis_client = FakeRedisClient()
return _fake_redis_client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this implies you'd want to use the fake redis client as a singleton -- set up once and then used forever -- in actual use in the test suite, you take care to destroy the global in tearDown() functions, to force it to be set up anew later. This seems wrong -- it looks like you should be using normal objects, perhaps setting the client as an attribute of the TestCase instance, rather than try to make it a singleton fetched through a function and then "reach behind the function's back" to manipulate the global.

@matusvalo matusvalo merged commit 753f4ec into celery:master Mar 3, 2021
@matusvalo
Copy link
Member

Thank you @matteius. I am sorry for long delay :-).

@auvipy
Copy link
Member

auvipy commented Mar 4, 2021

Thank you @matteius. I am sorry for long delay :-).

thanks both of you for bringing & drawing the finishing line.

@matusvalo
Copy link
Member

I had to revert this PR due failing integration tests. I prefer reopen this PR (not sure how can be done) and fix the problems with failing integration tests.

@thedrow
Copy link
Member

thedrow commented Mar 7, 2021

Revert the revert and edit the title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants