On Circle Ci - selenium test case timeout issue with celery


I have a django project, where I have written a unit-test, using the StaticLiveServerTestCase as shown in the example code below. I am using Selenium to execute the tests, and this works successfully on my local machine. However, when circle-ci executes my test, I am presented with a time out error.

2019-03-28 15:34:44,872 DEBUG selenium.webdriver.remote.remote_connection POST {"url": "http://localhost:37402/ja/accounts/login/", "sessionId": "sessid"}

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout
  (Session info: chrome=67.0.3396.99)
  (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-141-generic x86_64)

At first I thought the error was due to selenium and circle-ci, so I changed my webdriver.get() command to call google . com instead of my own site, and the circle-ci container successfully calls to google.

self.web_driver.get('%s%s' % (self.live_server_url, reverse('login')))

So I was able to rule out a circle-ci / selenium issue.

Next, I considered the issue could be caused by celery. On the login page, celery is being polled, to check whether or not a particular task is being processed. In production, the celery server is called and returns its response as normal. In the circle-ci / unit test scenario, this call times out.

One diagnostic test I tried, was to simply return True, early from my celery task processing check - and if I do this, circle-ci does not time out and the tests are executed properly.

Does anyone have any ideas, how to make circle-ci and celery play nicely, via a unit-test scenario - implying that I do not want the unit-test to check the live celery server.

Below, is the example test-case code that I am using from the django-selenium documentation. Thanks for your help.

Celery - django documentation

Django - Selenium Documentation

Selenium - Django Unit Test code

    def setUpClass(cls):
        cls.selenium = WebDriver()

    def test_login(self):

        self.selenium.get('%s%s' % (self.live_server_url, '/login/'))

        username_input = self.selenium.find_element_by_name("username")
        password_input = self.selenium.find_element_by_name("password")
        self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()

I’m not familiar with Django, but this does not sound like a unit test. Browser tests would usually be considered to be functional or integration tests, because of the number of pieces involved. It sounds like your test is making an HTTP call to the Celery server?

My response isn’t intended to be mere pedantry - I wonder if my observation may expose some misunderstanding, either on your side or mine.

(My broad advice when debugging browser tests is to use Selenium screenshots, and to use SSH to set up a fast try-debug loop. There isn’t much difference between CircleCI and a standard Linux VPS; in other words, if this problem presented itself to you on your local machine, how would you debug it?)

1 Like