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

[tests] Fixed flaky test_topology_graph #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

youhaveme9
Copy link
Contributor

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #347

Please open a new issue if there isn't an existing issue yet.

Comment on lines +165 to +167
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, path))
)
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 assume that the TimeoutError is raised by this code. I would update the logic here

Suggested change
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, path))
)
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, path))
)
except Exception:
import ipdb
ipdb.set_trace()

The test execution will halt when the code in except block is executed. Now, inspect the webpage. open the JS console on browser (created by selenium) and look for any errors.

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.

From the development chat by @youhaveme9

Running the test manually always passes
But running the test continuously in a loop using a script sometimes throws a timeout error
Is it due to the WebDriverWait function or something else?

@youhaveme9 you're correct. The TimeoutError appears because WebDriverWait cannot find the element in the defined time period.

For debugging, I suggest the following:

  1. Don't run the test suite with SELENIUM_HEADLESS. Change the headless key to false, so you will observe what selenium is doing with the web browser.

"headless": true,

  1. When running the test suite in loop, pause the execution with ipdb so you can inspect the problematic webpage. (You will need to install ipdb with pip install ipdb in your venv)

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.

I ran the tests a few times and it finally failed at the 4th attempt:
https://github.com/openwisp/docker-openwisp/actions/runs/12749591277/job/35931588981?pr=430

@youhaveme9
Copy link
Contributor Author

Hey @pandafy
I tried changing headless to false in config but its throwing this error?

Traceback (most recent call last):
  File "/workspaces/docker-openwisp/tests/runtests.py", line 136, in setUpClass
    cls.base_driver = webdriver.Chrome(options=options)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/codespace/.python/current/lib/python3.12/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/home/codespace/.python/current/lib/python3.12/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/home/codespace/.python/current/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in __init__
    self.start_session(capabilities)
  File "/home/codespace/.python/current/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/codespace/.python/current/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
    self.error_handler.check_response(response)
  File "/home/codespace/.python/current/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir```

@nemesifier
Copy link
Member

I provided some instructions on running only the flaky test continuously:
#347 (comment)

@nemesifier
Copy link
Member

The error message of the failed build is different though:

======================================================================
FAIL: test_topology_graph (__main__.TestServices)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/openwisp/docker-openwisp/tests/runtests.py", line 215, in test_topology_graph
    self.assertEqual(len(self.console_error_check()), 0)
AssertionError: 1 != 0

Which means there's been some progress!

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.

[bug] Flaky test: test_topology_graph
3 participants