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

requests/api/project_spec.rb speed up #8445

Merged
merged 1 commit into from Feb 12, 2015

Conversation

jvanbaarsen
Copy link
Contributor

What does this MR do?
It improves the speed of the request/api/project_spec.rb tests by ~3 minutes. It also removes some test duplication, and moves some assertions into the same tests so another API call is not needed.

Before: ~3.51 min
After: ~ 50 sec.

@TeatroIO
Copy link

I've prepared a stage. Click to open.

it { json_response['permissions']["project_access"]["access_level"].should == Gitlab::Access::MASTER }
it { json_response['permissions']["group_access"].should be_nil }
expect(response.status).to eq(200)
expect(json_response['permissions']["project_access"]["access_level"]).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]
Prefer single-quoted strings when you don't need string interpolation or special symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to ignore the Line is too long notice, since i have to perform some super weird tricks to get that one char win.

@jvanbaarsen jvanbaarsen force-pushed the project-spec-speed-up branch 2 times, most recently from 3d1c9be to c8e732a Compare December 13, 2014 19:00
@jvanbaarsen jvanbaarsen changed the title [wip] requests/api/project_spec.rb speed up requests/api/project_spec.rb speed up Dec 13, 2014
@jvanbaarsen
Copy link
Contributor Author

@dblessing Can you review?

end

context 'group project' do
before do
it 'should set the owner and return 200' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the style that was present before is preferred. If you want to only evaluate the before once to speed things up and check a bunch of things, use before(:all) instead of the before(:each) that's implied. As much as possible I think we should only assert one thing per it block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having one assertion per test is good when you're writing your code. after you're done writing, the tests are just there to validate behaviour. I think its best to move assertion that can be handled in one test to a single test, this speeds up significantly on the long term. Since the current test run takes over 19 minutes, every speed up is welcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can or should change the style of a test based on pre/post code writing. The best practice stands, IMHO. I think if we use 'before(:all)' here we will achieve good test style and get the speed up because the before block will only be evaluated once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purely a style preference. I'm not nearly as concerned about this one. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@randx Curious about your opinion on this :)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping me when you push up changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblessing Just tried the before(:all) approach, but this will be deprecated as of rspec 3, since @NARKOZ is working on upgrading rspec, I think it would be best to keep the change as I have proposed initially. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I will take one last look at merge this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like before(:all) is not deprecated AFAICT. I will still move forward with this PR, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i should have been more precise :) It is deprecated in combination with using a let.

@jvanbaarsen
Copy link
Contributor Author

@dblessing Can this be marked as ready for merge? Or you want opinion of @randx ?

@dzaporozhets
Copy link
Member

If you dont mind I leave decision to @dblessing. Feel free to merge it if you think this is ready.

@jvanbaarsen
Copy link
Contributor Author

@randx Ok thanks! Will fix the last items later tonight.

@jvanbaarsen
Copy link
Contributor Author

@dblessing After this gets rebased, would you be confortible with it being merged?

@dblessing
Copy link
Member

yes, looks good.

@jvanbaarsen jvanbaarsen force-pushed the project-spec-speed-up branch 2 times, most recently from 446dd4c to 22d1265 Compare February 1, 2015 15:36
(1..user2.projects_limit-1).each { |p| post api('/projects', user2), name: "foo#{p}" }
post api('/projects', user2), name: 'foo'
it 'should create new project without path and return 201' do
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [89/80]
Space missing inside {.
Space missing inside }.
Prefer single-quoted strings when you don't need string interpolation or special symbols.

@jvanbaarsen
Copy link
Contributor Author

@dblessing Somehow two commits from master got in this PR, and im not really sure how to get them out (already tried rebasing). You have any ideas? If not I'll cherry-pick my commit into a clean branch and recreate a PR.

@dblessing
Copy link
Member

I see that. Odd. Rebasing should have taken care of it. I don't know another way unfortunately.

@jvanbaarsen
Copy link
Contributor Author

@dblessing Hm ok, I'll cherry pick into another branch then :)

Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
@jvanbaarsen
Copy link
Contributor Author

@dblessing I think that GitHub just had a hickup or something, I rebased again and now all is well :) When this is green I'll merge.

@rspeicher
Copy link
Contributor

👍 for merging this. I also noticed this test case was unnecessarily slow.

@jvanbaarsen
Copy link
Contributor Author

Thanks for the reminder. Totally forgot about this one

On Wed, Feb 11, 2015 at 8:28 PM, Robert Speicher notifications@github.com
wrote:

👍 for merging this. I also noticed this test case was unnecessarily slow.

Reply to this email directly or view it on GitHub:
#8445 (comment)

jvanbaarsen added a commit that referenced this pull request Feb 12, 2015
requests/api/project_spec.rb speed up
@jvanbaarsen jvanbaarsen merged commit d9f84f6 into gitlabhq:master Feb 12, 2015
@jvanbaarsen jvanbaarsen deleted the project-spec-speed-up branch February 12, 2015 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants