[katello-devel] Faster unit tests

Dmitri Dolguikh dmitri at redhat.com
Thu Aug 11 14:32:41 UTC 2011


On 11-08-11 11:23 AM, Ivan Nečas wrote:
> On 08/11/2011 02:55 AM, Mike McCune wrote:
>> On 08/04/2011 03:53 AM, Lukas Zapletal wrote:
>>> Hello,
>>>
>>> saw this today
>>>
>>> http://bit.ly/rb0UWM
>>>
>>> and here are some points to make our unit tests faster:
>>>
>>> 1) "rspec spec" instead of "rails spec"
>>>
>>> On my laptop this improves it from 0m51.863s to 0m32.116s.
>>>
>>> 2) sqlite in memory mode
>>>
>>> This is actually slower on my laptop (about 2 seconds).
>>>
>>> 3) Since we dont have developer/integration tests (no real logins - we
>>> just mock User object) there is no room for improvement regarding to 
>>> the
>>> authentication process.
>>>
>>> 4) Did not test Spork server.
>>>
>>> Outcome: run "rspec test" instead of "rails spec" and you will be
>>> faster. Please note:
>>>
>>> Top 10 slowest examples (please fix):
>>> Â Â Â  SystemsController viewing systems and requesting individual data
>>> should show packages
>>> Â Â Â Â Â  1 seconds ./spec/controllers/systems_controller_spec.rb:84
>>> Â Â Â  SystemsController viewing systems should throw an exception 
>>> when the
>>> search parameters are invalid
>>> Â Â Â Â Â  1 seconds ./spec/controllers/systems_controller_spec.rb:60
>>> Â Â Â  SystemsController viewing systems and requesting individual data
>>> should show systems by env
>>> Â Â Â Â Â  0.86844 seconds 
>>> ./spec/controllers/systems_controller_spec.rb:90
>>> Â Â Â  SystemsController viewing systems should show the system 2 
>>> pane list
>>> Â Â Â Â Â  0.83007 seconds 
>>> ./spec/controllers/systems_controller_spec.rb:44
>>> Â Â Â  SystemsController viewing systems should return a portion of 
>>> systems
>>> Â Â Â Â Â  0.82123 seconds 
>>> ./spec/controllers/systems_controller_spec.rb:52
>>> Â Â Â  SystemsController viewing systems and requesting individual data
>>> should show subscriptions
>>> Â Â Â Â Â  0.81525 seconds 
>>> ./spec/controllers/systems_controller_spec.rb:78
>>> Â Â Â  SystemsController viewing systems and requesting individual 
>>> data it
>>> should show facts
>>> Â Â Â Â Â  0.79887 seconds 
>>> ./spec/controllers/systems_controller_spec.rb:72
>>> Â Â Â  RolesController viewing roles should return a portion of roles
>>> Â Â Â Â Â  0.79685 seconds 
>>> ./spec/controllers/roles_controller_spec.rb:119
>>> Â Â Â  RolesController viewing roles should show the role 2 pane list
>>> Â Â Â Â Â  0.78308 seconds 
>>> ./spec/controllers/roles_controller_spec.rb:110
>>> Â Â Â  NoticesController viewing notices should show all unread 
>>> notices for
>>> a user
>>> Â Â Â Â Â  0.50836 seconds 
>>> ./spec/controllers/notices_controller_spec.rb:46
>>>
>>
>> The startup time is a dog:
>>
>> ## One test:
>>
>> $ time rake spec SPEC=spec/models/changeset_spec.rb
>> /usr/bin/ruby -S bundle exec rspec spec/models/changeset_spec.rb
>> ................
>>
>> Finished in 1.81 seconds
>> 16 examples, 0 failures
>>
>> real    0m35.603s
>> user    0m20.948s
>> sys    0m5.392s
>>
>> ## All tests:
>>
>> $ time rake spec
>> [....]
>> Finished in 37.27 seconds
>> 594 examples, 0 failures, 20 pending
>>
>> real    1m11.193s
>> user    0m54.833s
>> sys    0m8.033s
>>
>> So almost ~30 seconds of wall time is just getting the env up and 
>> going ..
>>
> Hi,
>
> Using sport should cut the time off.
>
> Without spork:
>
> time rspec spec/models/changeset_spec.rb
>
> Finished in 0.90513 seconds
> 16 examples, 0 failures
>
> real  0m5.784s
> user  0m4.983s
> sys  0m0.753s
>
>
> With spork:
>
> time rspec spec/models/changeset_spec.rb  --drb
>
> Finished in 1.04 seconds
> 16 examples, 0 failures
>
> real  0m1.526s
> user  0m0.098s
> sys  0m0.017s
>
> To be really useful, it needs to change set config.cache_classes = 
> false in config/environments/test.rb. Unfortunately because of this, 
> some tests fail, because this option causes lazy loading.
>
> It makes faster the start-up time, so it has no so huge impact on the 
> whole test suite, but when you run one test frequently, it is a 
> significant change.
>
> Ivan
>
another option is to try using autotest - it will automatically run 
tests after it detects changes. I haven't tried it yet however.
-d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/katello-devel/attachments/20110811/67fa5341/attachment.htm>


More information about the katello-devel mailing list