Skip to content

Fixes build for PyPy3#6635

Merged
thedrow merged 11 commits into
celery:masterfrom
mjhoffman65:fix_pypy_check
Jun 27, 2021
Merged

Fixes build for PyPy3#6635
thedrow merged 11 commits into
celery:masterfrom
mjhoffman65:fix_pypy_check

Conversation

@mjhoffman65

@mjhoffman65 mjhoffman65 commented Feb 18, 2021

Copy link
Copy Markdown
Contributor

@auvipy, I took at stab at fixing the PyPy failures. My first step is to try to install all the requirements and recreate the unit test failure in the docker environment. I ran into issues installing the python requirements and am wondering if more work needs to be done before we can expect celery to run with PyPy. Looks like at least a couple of the dependencies do not work with PyPy since they rely on a C backend.

couchbase: https://docs.couchbase.com/python-sdk/current/hello-world/start-using-sdk.html#pypy-support
ephem: celery/django-celery-beat#69 (comment) (Note we may be able to replace this with skyfield. See here for more.)

This PR illustrates the same error I'm getting in the docker environment: https://github.com/celery/celery/runs/1930241932?check_suite_focus=true

How should I move forward?

@mjhoffman65 mjhoffman65 changed the title installs packages the same way docker does PyPy Compatibility Feb 18, 2021
@mjhoffman65 mjhoffman65 changed the title PyPy Compatibility PyPy Compatibility? Feb 18, 2021
@auvipy

auvipy commented Feb 19, 2021

Copy link
Copy Markdown
Member

I think we should stop couchbase testing and eventually remove it from the build. I am not sure how much popular it is.

@thedrow

thedrow commented Feb 20, 2021

Copy link
Copy Markdown
Contributor

I think we should stop couchbase testing and eventually remove it from the build. I am not sure how much popular it is.

Since we're getting PRs for it, it is in use.

@thedrow

thedrow commented Feb 20, 2021

Copy link
Copy Markdown
Contributor

What we can do is specify that couchebase cannot be installed in pypy using markers.

@thedrow

thedrow commented Feb 21, 2021

Copy link
Copy Markdown
Contributor

We now see actual errors.
Are you working on fixing those?

@mjhoffman65

mjhoffman65 commented Feb 22, 2021

Copy link
Copy Markdown
Contributor Author

We now see actual errors.
Are you working on fixing those?

Yep! Working now to fix them.

@mjhoffman65 mjhoffman65 changed the title PyPy Compatibility? Fixes build for PyPy3 Feb 22, 2021
@mjhoffman65

mjhoffman65 commented Feb 22, 2021

Copy link
Copy Markdown
Contributor Author

@auvipy @thedrow This is ready for review. I have some in-progress Dockerfile changes making it easy to run the unit tests with pypy3 via docker as well, but that can go separately.

@mjhoffman65
mjhoffman65 marked this pull request as ready for review February 22, 2021 18:41
@lgtm-com

lgtm-com Bot commented Feb 22, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert and fixes 2 when merging c0ca554 into 3384937 - view on LGTM.com

new alerts:

  • 1 for Unused import

fixed alerts:

  • 1 for Non-exception in 'except' clause
  • 1 for Module is imported with 'import' and 'import from'

self.patching('celery.backends.mongodb.MongoBackend.encode')
self.patching('celery.backends.mongodb.MongoBackend.decode')
self.patching('celery.backends.mongodb.Binary')
self.patching('datetime.datetime')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing that line fixes this error when running the MongoDB backend tests.
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does it pass on CPython?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tox.ini appears to need a change to run these tests.

diff --git a/tox.ini b/tox.ini
index f62ea3cdf..51cf5d020 100644
--- a/tox.ini
+++ b/tox.ini
@@ -31,7 +31,7 @@ deps=
     3.6,3.7,3.8,3.9: -r{toxinidir}/requirements/test-ci-default.txt
     3.5,3.6,3.7,3.8,3.9: -r{toxinidir}/requirements/docs.txt
     3.6,3.7,3.8,3.9: -r{toxinidir}/requirements/docs.txt
-    pypy3: -r{toxinidir}/requirements/test-ci-base.txt
+    pypy3: -r{toxinidir}/requirements/test-ci-default.txt
 
     integration: -r{toxinidir}/requirements/test-integration.txt
 

@maybe-sybr maybe-sybr May 7, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This patch was originally added back in the depths of time: 3ea8824 It seems to be a vestigial thing, so I think it'll be fine to remove it.

The breakage is because pypy3 appears to be a little less duck-type-y with its datetime subtraction implementation. We're giving it a Mock that looks like a datetime object, but isn't probably isn't using a spec= to pass isinstance() checks.

Actually, this is super interesting. It seems to be mocking confusion because we do a bunch of from datetime import datetime imports which means that by only mocking datetime.datetime in this suite, we're causing datetime to be different in various places and when pypy3 does an isinstance() check for in its __sub__() implementation, it's actually checking if the arguments are subclasses of the mock class!.

tl;dr easiest fix is to avoid the issue entirely by using the change @mjhoffman65 put up. Correct fix is to not use from imports so that we're always accessing via the defining module and mocks will work without weird contortions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leaving this for @thedrow to resolve

@thedrow

thedrow commented Feb 22, 2021

Copy link
Copy Markdown
Contributor

What about that event is a boolean failure that pops up every now and then?
@auvipy You know what I'm talking about right? Can you find a build log where that happens?
@mjhoffman65 If you repeatedly run the test suite multiple times, does it always pass?

@mjhoffman65

mjhoffman65 commented Feb 22, 2021

Copy link
Copy Markdown
Contributor Author

What about that event is a boolean failure that pops up every now and then?
@auvipy You know what I'm talking about right? Can you find a build log where that happens?
@mjhoffman65 If you repeatedly run the test suite multiple times, does it always pass?

@thedrow I've ran it 4 times in docker and so far it has always passed. I'm not sure how to trigger reruns with the github actions, but I haven't seen that error pop up yet. I'm assuming it's this one: #6489

@thedrow

thedrow commented Feb 23, 2021

Copy link
Copy Markdown
Contributor

Yes, exactly.

@mjhoffman65

Copy link
Copy Markdown
Contributor Author

Was able to recreate #6489. Will reopen after I fix it.

@auvipy auvipy reopened this Feb 24, 2021
@auvipy auvipy added this to the 5.1.0 milestone Feb 24, 2021
@thedrow

thedrow commented Feb 24, 2021

Copy link
Copy Markdown
Contributor

Was able to recreate #6489. Will reopen after I fix it.

There's no need to close this PR. Just mark it as a draft if it's not ready for merge.

@thedrow
thedrow marked this pull request as draft February 24, 2021 10:15
@lgtm-com

lgtm-com Bot commented Mar 2, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert and fixes 2 when merging 3712de6 into cfa1b41 - view on LGTM.com

new alerts:

  • 1 for Unused import

fixed alerts:

  • 1 for Non-exception in 'except' clause
  • 1 for Module is imported with 'import' and 'import from'

Comment thread celery/utils/timer2.py Outdated
@thedrow

thedrow commented Mar 4, 2021

Copy link
Copy Markdown
Contributor

It seems like the failing test is not related to your change.
Would you mind investigating or should I open an issue?

@thedrow

thedrow commented Apr 7, 2021

Copy link
Copy Markdown
Contributor

I've rebased this PR but I'm still waiting for your response @mjhoffman65.

@maybe-sybr

maybe-sybr commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

Freshened on master and also with a few extra fixes for the same kind of Thread._is_stopped shadowing in the bgThread class which is probably broken in a race-y way similar to Timer but only touched in two tests so we probably never noticed that it was different to the timer failure.

I'm hoping this will go green now, with the fix from #6806 pulled in via the rebase as well.

@codecov

codecov Bot commented Jun 9, 2021

Copy link
Copy Markdown

Codecov Report

Merging #6635 (1ce3b20) into master (d9d8250) will increase coverage by 5.12%.
The diff coverage is 100.00%.

❗ Current head 1ce3b20 differs from pull request most recent head f486c0d. Consider uploading reports for the commit f486c0d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6635      +/-   ##
==========================================
+ Coverage   70.70%   75.82%   +5.12%     
==========================================
  Files         138      138              
  Lines       16603    16603              
  Branches     2092     2092              
==========================================
+ Hits        11739    12590     +851     
+ Misses       4668     3797     -871     
- Partials      196      216      +20     
Flag Coverage Δ
unittests 75.82% <100.00%> (+5.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
celery/backends/redis.py 92.17% <ø> (+8.93%) ⬆️
celery/bin/base.py 0.00% <ø> (ø)
celery/concurrency/__init__.py 100.00% <ø> (ø)
celery/exceptions.py 32.60% <ø> (ø)
celery/worker/consumer/consumer.py 93.57% <ø> (ø)
celery/canvas.py 94.82% <100.00%> (ø)
celery/utils/threads.py 65.43% <100.00%> (ø)
celery/utils/timer2.py 98.95% <100.00%> (ø)
celery/app/trace.py 98.60% <0.00%> (+0.27%) ⬆️
celery/result.py 58.01% <0.00%> (+0.40%) ⬆️
... and 22 more

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 d9d8250...f486c0d. Read the comment docs.

@maybe-sybr

maybe-sybr commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

Huh, weird, it's trying to run flake8 under action environments without python 3.9 installed :/

Edit: Oh 0295d7a did that. Probably no point in linting in each of the build jobs though, that's kind of weird

@lgtm-com

lgtm-com Bot commented Jun 9, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert and fixes 1 when merging a3b2af7 into d9d8250 - view on LGTM.com

new alerts:

  • 1 for Non-exception in 'except' clause

fixed alerts:

  • 1 for Module is imported with 'import' and 'import from'

@maybe-sybr
maybe-sybr force-pushed the fix_pypy_check branch 2 times, most recently from 60a8122 to 1ce3b20 Compare June 9, 2021 07:41
Also fix some flakes which may have been added by some other
autoformatter in celery#6804. The 4 space non-visual-indentation should keep
most formatters fairly happy.
@lgtm-com

lgtm-com Bot commented Jun 9, 2021

Copy link
Copy Markdown

This pull request fixes 1 alert when merging f486c0d into d9d8250 - view on LGTM.com

fixed alerts:

  • 1 for Module is imported with 'import' and 'import from'

@maybe-sybr
maybe-sybr marked this pull request as ready for review June 9, 2021 10:14
@maybe-sybr
maybe-sybr requested a review from thedrow June 9, 2021 10:14
@thedrow
thedrow merged commit 117cd9c into celery:master Jun 27, 2021
@thedrow

thedrow commented Jun 27, 2021

Copy link
Copy Markdown
Contributor

Thanks to everyone who helped us stablize the build :)

thedrow pushed a commit that referenced this pull request Jun 27, 2021
* installs packages the same way docker does

* removes couchbase dependency for PyPy

* removes ephem dependency for PyPy

* fixes mongo unit tests for PyPy3

Mocking `datetime.datetime` was causing an issue with
`datetime.utcnow()`.  This mock doesn't appear to be needed.
See https://github.com/celery/celery/pull/6635/checks?check_run_id=1944166896.

* fix: Avoid shadowing `Thread` attributes

Fixes #6489

* ci: Install default deps for pypy3 toxenvs

* ci: Run unit tests with `tox`

* ci: Lint source in separate action using `tox`

* ci: Redent codecov action

* test: Rework some mocking in `test_platforms.py`

Also fix some flakes which may have been added by some other
autoformatter in #6804. The 4 space non-visual-indentation should keep
most formatters fairly happy.

* style: Fix some flakes

Co-authored-by: maybe-sybr <[email protected]>
jeyrce pushed a commit to jeyrce/celery that referenced this pull request Aug 25, 2021
* installs packages the same way docker does

* removes couchbase dependency for PyPy

* removes ephem dependency for PyPy

* fixes mongo unit tests for PyPy3

Mocking `datetime.datetime` was causing an issue with
`datetime.utcnow()`.  This mock doesn't appear to be needed.
See https://github.com/celery/celery/pull/6635/checks?check_run_id=1944166896.

* fix: Avoid shadowing `Thread` attributes

Fixes celery#6489

* ci: Install default deps for pypy3 toxenvs

* ci: Run unit tests with `tox`

* ci: Lint source in separate action using `tox`

* ci: Redent codecov action

* test: Rework some mocking in `test_platforms.py`

Also fix some flakes which may have been added by some other
autoformatter in celery#6804. The 4 space non-visual-indentation should keep
most formatters fairly happy.

* style: Fix some flakes

Co-authored-by: maybe-sybr <[email protected]>
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.

pypy3 unit tests sometimes fail due to an attribute we expect to be an Event being a bool instead

4 participants