Skip to content

[bug] Selenium tests contain JS errors due to failed websocket connection #904

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

Open
nemesifier opened this issue Aug 2, 2024 · 4 comments
Labels

Comments

@nemesifier
Copy link
Member

Selenium tests contain JS errors due to failed websocket connection.

We need to switch from django's StaticLiveServerTestCase to ChannelsLiveServerTestCase.
I also recommend making the base selenium class in openwisp-utils automatically inherit ChannelsLiveServerTestCase and enforce this across OpenWISP.

We also have to figure out:

@dee077
Copy link
Contributor

dee077 commented Apr 15, 2025

I have updated the selenium test in utils to inherit from ChannelsLiveServerTestCase instead of StaticLiveServerTestCase and found it is failing on Django 5.2 and passing on others.

This open issue in the channels repo as 5.2 is added recently.

  1. Should all the selenium tests across all modules inherit from ChannelsLiveServerTestCase?
  2. We can't run the test case in parallel after this, we have to separate the unit test and selenium test.

So, how should we proceed then?

@pandafy
Copy link
Member

pandafy commented Apr 28, 2025

  • Should all the selenium tests across all modules inherit from ChannelsLiveServerTestCase?

Yes

  • We can't run the test case in parallel after this, we have to separate the unit test and selenium test.

Can you please explain why?

@dee077
Copy link
Contributor

dee077 commented Apr 28, 2025

Can you please explain why?

When running tests using StaticLiveServerTestCase in parallel, Django creates a new process for each test worker. Inside each of these processes, a thread is started to run a WSGI server for serving the application, along with additional threads for executing the individual tests.

However, when running tests with ChannelsLiveServerTestCase in parallel, a similar initial process is created for each test worker. But instead of spawning a thread for the server, ChannelsLiveServerTestCase starts a new Daphne (ASGI) server as a separate process not as a thread. Along with this, threads are also spawned to execute the individual tests.

This causes a problem:
Python does not allow a daemonic process (the worker running for tests) to create child processes (the Daphne server process). As a result, an error occurs:

======================================================================
ERROR: test_menu_on_wide_screen (test_project.tests.test_selenium.TestMenu.test_menu_on_wide_screen)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/deepanshu/Documents/GSOC/OpenWisp/.utils/lib/python3.12/site-packages/django/test/testcases.py", line 284, in _setup_and_call
    self._pre_setup()
  File "/home/deepanshu/Documents/GSOC/OpenWisp/.utils/lib/python3.12/site-packages/channels/testing/live.py", line 61, in _pre_setup
    self._server_process.start()
    ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/multiprocessing/process.py", line 118, in start
    assert not _current_process._config.get('daemon'), \
    ^^^^^^^^^^^^^^^^^
AssertionError: daemonic processes are not allowed to have children

Solutions:

  1. Don't use --parallel
  2. Start the Dapine server manually in a different terminal. (work locally but can cause issues in ci).

Let me know if there are any other solutions!

@pandafy
Copy link
Member

pandafy commented Apr 28, 2025

@dee077 can you open a draft PR in openwisp-utils? I would like to do some debugging before finalizing on a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: To do (general)
Development

No branches or pull requests

3 participants