alphagov/whitehall — pull request #1701 by tekin (2014-09-04 17:04:51+00:00)
Title: Rake task for generating realistic benchmarks

Adds a `test:alt_benchmarks` rake task to more accurately measure the performance of some poorly performing pages.

This leans on the existing performance testing facilities in Rails, but instead of running against the "test" environment, it defines a new one called "benchmark" that is set up to behave more like production. The
main differences between "test" and "benchmark" are:

* caching will be performed in "benchmark"
* the database will not be dropped/rebuilt on every run

The main aim here is to more accurately model the behaviour in production, right down to the volume of data in the database. By preloading a dump of production data into the benchmark database, these performance tests will give us a more accurate measure of page load times for those pages that contain lots of form elements referencing data from the database (e.g. select lists for organisations, related policies, etc).

A set of reference tests have been added as an example. Note that these tests depend on a fully-loaded database being present by design.

The results are saved to the `tmp/performance` folder and the output looks something like this:

```
$ b rake test:alt_benchmarks
Run options:

# Running tests:

[1/8] AdminEditionPagesTest#test_edit_detailed_guide_pageAdminEditionPagesTest#test_edit_detailed_guide_page (8.31 sec warmup)
wall_time: 5.55 sec
[2/8] AdminEditionPagesTest#test_edit_news_pageAdminEditionPagesTest#test_edit_news_page (3.95 sec warmup)
wall_time: 3.78 sec
[3/8] AdminEditionPagesTest#test_edit_publication_pageAdminEditionPagesTest#test_edit_publication_page (4.66 sec warmup)
wall_time: 3.83 sec
[4/8] AdminEditionPagesTest#test_edit_speech_pageAdminEditionPagesTest#test_edit_speech_page (6.12 sec warmup)
wall_time: 4.82 sec
[5/8] AdminEditionPagesTest#test_new_detailed_guide_pageAdminEditionPagesTest#test_new_detailed_guide_page (4.38 sec warmup)
wall_time: 4.45 sec
[6/8] AdminEditionPagesTest#test_new_news_pageAdminEditionPagesTest#test_new_news_page (3.15 sec warmup)
wall_time: 3.05 sec
[7/8] AdminEditionPagesTest#test_new_publication_pageAdminEditionPagesTest#test_new_publication_page (3.08 sec warmup)
wall_time: 3.08 sec
[8/8] AdminEditionPagesTest#test_new_speech_pageAdminEditionPagesTest#test_new_speech_page (4.73 sec warmup)
wall_time: 4.49 sec
= 28.62 sFinished tests in 215.089793s, 0.0372 tests/s, 0.0000 assertions/s.
```