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

Use before_all block to setup requests/cache_spec data #29437

Merged
merged 1 commit into from
Mar 13, 2024

Commits on Mar 12, 2024

  1. Use before_all block to setup requests/cache_spec data

    This spec is looping through various collections of endpoints and
    asserting different caching properties.
    
    Previously, the `before` block here was running before every example,
    and thus creating/dropping the full set of factories in every
    example-wrapping transaction.
    
    The change here is to use `before_all` which wraps the example group in
    a big transaction and creates the factories (which, in this entire spec,
    are very much like fixture data). The individual transactions around
    each example from rspec are still in place, so for the few examples
    which do modify any of the records, that will not pollute other specs.
    
    Some before/after summary to show factory creation reduction:
    
    BEFORE:
    ```
    Finished in 23.1 seconds (files took 2.78 seconds to load)
    253 examples, 0 failures
    
    [TEST PROF INFO] Factories usage
    
     Total: 1611
     Total top-level: 1611
     Total time: 00:12.677 (out of 00:23.892)
     Total uniq factories: 6
    
       total   top-level     total time      time per call      top-level time               name
    
         506         506        2.6162s            0.0052s             2.6162s             status
         264         264        3.4650s            0.0131s             3.4650s            account
         253         253        3.5710s            0.0141s             3.5710s             invite
         253         253        0.4301s            0.0017s             0.4301s               poll
         253         253        2.4347s            0.0096s             2.4347s               user
          82          82        0.1603s            0.0020s             0.1603s accessible_access_token
    ```
    
    AFTER:
    ```
    Finished in 9.54 seconds (files took 2.72 seconds to load)
    253 examples, 0 failures
    
    [TEST PROF INFO] Factories usage
    
     Total: 18
     Total top-level: 18
     Total time: 00:00.860 (out of 00:10.325)
     Total uniq factories: 6
    
       total   top-level     total time      time per call      top-level time               name
    
          12          12        0.6972s            0.0581s             0.6972s            account
           2           2        0.0997s            0.0499s             0.0997s             status
           1           1        0.0093s            0.0093s             0.0093s               user
           1           1        0.0232s            0.0232s             0.0232s             invite
           1           1        0.0134s            0.0134s             0.0134s               poll
           1           1        0.0175s            0.0175s             0.0175s accessible_access_token
    ```
    
    So, we are able to reduce:
    
    - Total factory creation from ~1600 DB records to just under 20
    - Percentage of time spent on factories from ~50% to under 10%
    - Overall spec file run time by more than 50%
    mjankowski committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    4c90de6 View commit details
    Browse the repository at this point in the history