Skip to content

Conversation

@dee077
Copy link
Member

@dee077 dee077 commented Apr 28, 2025

Replaced StaticLiveServerTestCase with ChannelsLiveServerTestCase to resolve JS errors caused by failed websocket connections.

Fixes #466

Checklist

Reference to Existing Issue

Closes #466.

Description of Changes

  • Changed StaticLiveServerTestCase to ChannelsLiveServerTestCase.
  • Updated to Django 5.2.0 in ci.
  • Removed --parallel for running test in ci.

Issues

  • ChannelsLiveServerTestCase does not support Django 5.2 yet.
  • For running test --parallel does not work.

@dee077 dee077 changed the title [change:tests] Switch to ChannelsLiveServerTestCase #904 [change:tests] Switch to ChannelsLiveServerTestCase #466 Apr 29, 2025
@dee077 dee077 force-pushed the issues/904-change-to-ChannelsLiveServerTestCase branch from ee2d9f8 to 3d223e8 Compare April 29, 2025 05:26
@nemesifier nemesifier added enhancement testing Issue related to testing or CI labels May 8, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

Looks on the right track to me.

Question: how can we be sure it's working as expected and there's no JS errors?
Wouldn't it make sense to add at least one test for this?

CI is not passing on Django 5.2, why is that?

'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'openwisp_utils.db',
'TEST': {
'NAME': 'openwisp_utils_test.db',
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is this needed?

Without this, it was causing this error

raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: ChannelLiveServerTestCase can not be used with in memory databases

As the ASGI server requires a physical database



class TestMenu(SeleniumTestMixin, StaticLiveServerTestCase):
class TestMenu(SeleniumTestMixin, ChannelsLiveServerTestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Let's tag all these tests (as we're doing in other modules for the selenium tests) so we can exclude them from the parallel run.

if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
run: |
coverage run runtests.py --parallel
coverage run runtests.py
Copy link
Member

Choose a reason for hiding this comment

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

Once we have tagged the tests, we can modify the runtests.py script to handle which tests must not be run in parallel.

Since this can get complex in each module, I insisted with @pandafy that we hide this complexity from contributors in the runtests.py script, which thanks to a few lines of comments is also useful to us maintainers to remember why it's done that way.

See the runtests.py script in the controller module:
https://github.com/openwisp/openwisp-controller/blob/master/runtests.py#L46-L47

Copy link
Member

Choose a reason for hiding this comment

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

We need to handle this.

@dee077
Copy link
Member Author

dee077 commented May 9, 2025

CI is not passing on Django 5.2, why is that?

There is an open issue in django channels for ChannelsLiveServerTestCase is broken in django 5.2
django/channels#2148

@dee077 dee077 force-pushed the issues/904-change-to-ChannelsLiveServerTestCase branch 2 times, most recently from a6a7f2b to 6a8a34a Compare June 4, 2025 11:48
@coveralls
Copy link

coveralls commented Jun 4, 2025

Coverage Status

coverage: 96.029%. remained the same
when pulling da9866c on dee077:issues/904-change-to-ChannelsLiveServerTestCase
into dd1b06f on openwisp:master.

setup.py Outdated
"channels[daphne]~=4.2.0",
"channels[daphne]@"
"git+https://github.com/openwisp/channels.git@"
"issues/2148-ChannelsLiveServerTestCase-Django52-compatible#egg=channels[daphne]",
Copy link
Member

Choose a reason for hiding this comment

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

We can update this now as the PR has been merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated!

if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
run: |
coverage run runtests.py --parallel
coverage run runtests.py
Copy link
Member

Choose a reason for hiding this comment

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

We need to handle this.

pip install ${{ matrix.django-version }}
sudo npm install -g prettier
pip uninstall channels channels-redis daphne -y
pip install -e ".[channels]"
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't be needed anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated!

dee077 added 3 commits August 27, 2025 01:48
Replaced StaticLiveServerTestCase with ChannelsLiveServerTestCase to resolve JS errors caused by failed websocket connections.

Fixes openwisp#466
@dee077 dee077 force-pushed the issues/904-change-to-ChannelsLiveServerTestCase branch from 6a8a34a to 18861b1 Compare August 26, 2025 21:07
@dee077 dee077 marked this pull request as ready for review August 26, 2025 21:16
@dee077
Copy link
Member Author

dee077 commented Aug 26, 2025

Updates:

  • Changed ChannelsLiveServerTestCase from StaticLiveServerTestCase
  • Added tag selenium tests to all selenium tests to exclude them from running in parallel.
  • Updated CI to run unit and selenium tests separately.

nemesifier
nemesifier previously approved these changes Aug 27, 2025
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

LGTM! @pandafy what do you think?

@github-project-automation github-project-automation bot moved this from To do (general) to In progress in OpenWISP Contributor's Board Aug 27, 2025
pandafy
pandafy previously approved these changes Aug 27, 2025
Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

LGTM! I have one question, the rest looks good!


from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "openwisp2.settings")
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this here? I don't see it in openwisp-controller and openwisp-notifications.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't remember exactly why, but removing it does nothing. So removed it.

@dee077 dee077 dismissed stale reviews from pandafy and nemesifier via da9866c August 27, 2025 11:41
@dee077
Copy link
Member Author

dee077 commented Aug 27, 2025

Updates

  • Added --noinput flag in running test in ci to auto destroy the previous db as ChannelsLiveServerTestCase requires a physical db and rerunning jobs can ask prompts to destroy db yes or no.
  • Removed from asgi.py
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "openwisp2.settings")

@nemesifier nemesifier changed the title [change:tests] Switch to ChannelsLiveServerTestCase #466 [fix:tests] Switch to ChannelsLiveServerTestCase #466 Aug 29, 2025
@nemesifier nemesifier changed the title [fix:tests] Switch to ChannelsLiveServerTestCase #466 [tests:fix] Switched to ChannelsLiveServerTestCase #466 Aug 29, 2025
@nemesifier nemesifier merged commit bf8ac7b into openwisp:master Aug 29, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in OpenWISP Contributor's Board Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement testing Issue related to testing or CI

Projects

Development

Successfully merging this pull request may close these issues.

[bug:tests] Switch to ChannelsLiveServerTestCase for all Selenium tests

4 participants