Skip to content

Conversation

@gersh
Copy link

@gersh gersh commented Aug 2, 2023

Add "task-*" events so we can monitor the queue with Flower.

@gersh gersh requested a review from clokep as a code owner August 2, 2023 18:11
@clokep
Copy link
Owner

clokep commented Aug 2, 2023

Any chance that tests could be added for this?

@gersh
Copy link
Author

gersh commented Aug 2, 2023

Is there a good way to test if a signal has been sent with pytest? I tried:

    class TaskMonitor:
        def __init__(self):
            self.tasks_received = 0
            self.tasks_started = 0
            self.tasks_suceeded = 0

        def on_task_received(self, event):
            self.tasks_received += 1
        def on_task_started(self, event):
            self.tasks_started += 1
        def on_task_suceeded(self, event):
            self.tasks_suceeded += 1

    tm = TaskMonitor()

    recv = celery_app.events.Receiver(connection, handlers={
            'task-received': tm.on_task_received,
            'task-started': tm.on_task_started,
            'task-suceeded': tm.on_task_suceeded,
            '*': tm.on_other
            })

but I can't seem to get it to work. If you can help me figure out how to get it to listen for events in a pytest, I can implement it. I tested it in Flower, and it seems to work, but I'm not sure how to get the internals to work for a unit test.

@clokep
Copy link
Owner

clokep commented Aug 3, 2023

Some of the tests use the SignalCounter class to do this (it is a bit hacky, but I haven't managed to figure out a better way to do it).

@clokep
Copy link
Owner

clokep commented Aug 3, 2023

See also #70.

@clokep
Copy link
Owner

clokep commented Aug 5, 2024

@gersh Shout when you think this is ready for review again!

You should be able to run the lints locally manually by running the same commands as CI:

- name: "Install dependencies"
run: python -m pip install -r requirements/pkgutils.txt
- name: "Run pyupgrade"
run: pyupgrade --py37-plus **/*.py
- name: "Run flake8"
run: flake8
- name: "Run isort"
run: isort --check .
- name: "Run black"
run: black --check .
- name: "Run mypy"
run: mypy

@gersh
Copy link
Author

gersh commented Aug 5, 2024

@clokep I think I fixed the lint issues.

@gersh
Copy link
Author

gersh commented Aug 6, 2024

@clokep I fixed all the lint issues.

@Jochem22
Copy link

Is this still in progress? Anything that needs to be done?

@@ -0,0 +1,85 @@
import asyncio
Copy link
Owner

Choose a reason for hiding this comment

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

Why all the use of asyncio in these tests instead of being more similar to the existing tests?

signals.task_revoked.disconnect(dummy_receiver)


def test_task_prerun_signal(
Copy link
Owner

Choose a reason for hiding this comment

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

These don't seem to actually hook up signals and make sure they run.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants