LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Rails V5 and Ruby 2.3.1 - tests completing slowly (https://www.linuxquestions.org/questions/programming-9/rails-v5-and-ruby-2-3-1-tests-completing-slowly-4175589742/)

grail 09-19-2016 02:29 PM

Rails V5 and Ruby 2.3.1 - tests completing slowly
 
I have been going over some old courses on rails which have updated to the new version (5).
I am up to the first section on testing and have come across a strange timing that I cannot explain :(

So here is my super simple test code:
Code:

require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest

  test "should get root" do
    get root_url
    assert_response :success
  end
end

As you can see it is a simple test to see if the root_url is returning successfully.
Now when I time the output of this I get:
Code:

$ time rails t
Started with run options --seed 38470

  1/1: [======================================================================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.49690s
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips


real        0m54.209s
user        0m3.450s
sys        0m0.397s

Here we see that the actual test took less than half a second (see 'Finished in' time), but that the whole command took a whopping 54+ seconds to complete :(

I have tried searching for a reason but I am only able to find optimization options instead of a reason why there is an additional 53 seconds (rounded) to complete the command after the tests have finished.

If anyone can point me in the direction of an answer it would be much appreciated :)

Please also let me know if there is any other detail to be provided to help with a solution?

sundialsvcs 09-19-2016 02:54 PM

Although I am entirely(!) unfamiliar with "the present situation," I have definitely encountered this sort of [esoteric ...] problem before.

I suspect that your test ... condition encompasses an expectation that is not "entirely fulfilled" by "the entire block." Instead, it is fulfilled by just the first part of it ... which therefore is never actually seen(!). And so, the test block eventually times out.

Your test block should encompass only "the thing that actually is to be tested," not any subsequent response to its success.

The action assert_response :success should only occur if the test outcome is favorable. Therefore, it should follow that block, not be a part of it.

grail 09-20-2016 02:14 AM

I see where you are coming from, however, no test that I can create has any different results. Also, this test is directly from the course and when I previously used the course on version 4+ of rails I had no issues.

It is as though there is something else running after the test that I am unable to locate :(

grail 09-20-2016 10:50 AM

As a little extra, I have removed all tests and still have to wait 53+ seconds for the process to complete :( Obviously something else is running but I am buggered if I can see what :(

grail 09-25-2016 01:20 PM

Okee dokee then ... I have found the cause and a work-around which gets me back to practicing :)

The problem stems from the addition of the following to my Gemfile:
Code:

group :test do
        gem 'rails-controller-testing', '0.1.1'
        gem 'minitest-reporters',      '1.1.9'
        gem 'guard',                    '2.13.0'
#        gem 'guard-minitest',          '2.4.4'
end

The commented out line for guard-minitest has all my tests returning immediately after they are completed :D I have noted that on the github site
related to the gem that there is mention of some issues and although I tried the suggested solution, I was not able to overcome the extra time issue.

As I do not intend to use guard this is a non-issue for me at the moment but I will continue to follow the solutions to see if I can update this question when a solution exists :)


All times are GMT -5. The time now is 08:00 PM.