Commit 9773ccc4519c4c35f969248c4e0f13689b631760
1 parent
71bd9568
Exists in
master
and in
4 other branches
sidekiq with green tests
Showing
15 changed files
with
70 additions
and
90 deletions
Show diff stats
Procfile
config/initializers/4_resque.rb
| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | -# Custom Redis configuration | |
| 2 | -config_file = Rails.root.join('config', 'resque.yml') | |
| 3 | - | |
| 4 | -resque_url = if File.exists?(config_file) | |
| 5 | - YAML.load_file(config_file)[Rails.env] | |
| 6 | - else | |
| 7 | - "localhost:6379" | |
| 8 | - end | |
| 9 | - | |
| 10 | -Sidekiq.configure_server do |config| | |
| 11 | - config.redis = { | |
| 12 | - url: "redis://#{resque_url}", | |
| 13 | - namespace: 'resque:gitlab' | |
| 14 | - } | |
| 15 | -end | |
| 16 | - | |
| 17 | -Sidekiq.configure_client do |config| | |
| 18 | - config.redis = { | |
| 19 | - url: "redis://#{resque_url}", | |
| 20 | - namespace: 'resque:gitlab' | |
| 21 | - } | |
| 22 | -end |
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +# Custom Redis configuration | |
| 2 | +config_file = Rails.root.join('config', 'resque.yml') | |
| 3 | + | |
| 4 | +resque_url = if File.exists?(config_file) | |
| 5 | + YAML.load_file(config_file)[Rails.env] | |
| 6 | + else | |
| 7 | + "localhost:6379" | |
| 8 | + end | |
| 9 | + | |
| 10 | +Sidekiq.configure_server do |config| | |
| 11 | + config.redis = { | |
| 12 | + url: "redis://#{resque_url}", | |
| 13 | + namespace: 'resque:gitlab' | |
| 14 | + } | |
| 15 | +end | |
| 16 | + | |
| 17 | +Sidekiq.configure_client do |config| | |
| 18 | + config.redis = { | |
| 19 | + url: "redis://#{resque_url}", | |
| 20 | + namespace: 'resque:gitlab' | |
| 21 | + } | |
| 22 | +end | ... | ... |
features/steps/admin/admin_active_tab.rb
features/support/env.rb
| ... | ... | @@ -6,6 +6,8 @@ require './config/environment' |
| 6 | 6 | require 'rspec' |
| 7 | 7 | require 'database_cleaner' |
| 8 | 8 | require 'spinach/capybara' |
| 9 | +require 'sidekiq/testing/inline' | |
| 10 | + | |
| 9 | 11 | |
| 10 | 12 | %w(gitolite_stub stubbed_repository valid_commit).each do |f| |
| 11 | 13 | require Rails.root.join('spec', 'support', f) | ... | ... |
lib/hooks/post-receive
lib/tasks/gitlab/check.rake
| ... | ... | @@ -871,7 +871,7 @@ namespace :gitlab do |
| 871 | 871 | |
| 872 | 872 | |
| 873 | 873 | namespace :resque do |
| 874 | - desc "GITLAB | Check the configuration of Resque" | |
| 874 | + desc "GITLAB | Check the configuration of Sidekiq" | |
| 875 | 875 | task check: :environment do |
| 876 | 876 | warn_user_is_not_gitlab |
| 877 | 877 | start_checking "Resque" |
| ... | ... | @@ -888,7 +888,7 @@ namespace :gitlab do |
| 888 | 888 | def check_resque_running |
| 889 | 889 | print "Running? ... " |
| 890 | 890 | |
| 891 | - if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/) | |
| 891 | + if run_and_match("ps aux | grep -i sidekiq", /sidekiq-[\d\.]+:.+$/) | |
| 892 | 892 | puts "yes".green |
| 893 | 893 | else |
| 894 | 894 | puts "no".red |
| ... | ... | @@ -899,7 +899,7 @@ namespace :gitlab do |
| 899 | 899 | ) |
| 900 | 900 | for_more_information( |
| 901 | 901 | see_installation_guide_section("Install Init Script"), |
| 902 | - "see log/resque.log for possible errors" | |
| 902 | + "see log/sidekiq.log for possible errors" | |
| 903 | 903 | ) |
| 904 | 904 | fix_and_rerun |
| 905 | 905 | end | ... | ... |
spec/models/system_hook_spec.rb
| ... | ... | @@ -23,41 +23,31 @@ describe SystemHook do |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | 25 | it "project_create hook" do |
| 26 | - with_resque do | |
| 27 | - project = create(:project) | |
| 28 | - end | |
| 26 | + project = create(:project) | |
| 29 | 27 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once |
| 30 | 28 | end |
| 31 | 29 | |
| 32 | 30 | it "project_destroy hook" do |
| 33 | 31 | project = create(:project) |
| 34 | - with_resque do | |
| 35 | - project.destroy | |
| 36 | - end | |
| 32 | + project.destroy | |
| 37 | 33 | WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once |
| 38 | 34 | end |
| 39 | 35 | |
| 40 | 36 | it "user_create hook" do |
| 41 | - with_resque do | |
| 42 | - create(:user) | |
| 43 | - end | |
| 37 | + create(:user) | |
| 44 | 38 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once |
| 45 | 39 | end |
| 46 | 40 | |
| 47 | 41 | it "user_destroy hook" do |
| 48 | 42 | user = create(:user) |
| 49 | - with_resque do | |
| 50 | - user.destroy | |
| 51 | - end | |
| 43 | + user.destroy | |
| 52 | 44 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once |
| 53 | 45 | end |
| 54 | 46 | |
| 55 | 47 | it "project_create hook" do |
| 56 | 48 | user = create(:user) |
| 57 | 49 | project = create(:project) |
| 58 | - with_resque do | |
| 59 | - project.team << [user, :master] | |
| 60 | - end | |
| 50 | + project.team << [user, :master] | |
| 61 | 51 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once |
| 62 | 52 | end |
| 63 | 53 | |
| ... | ... | @@ -65,11 +55,8 @@ describe SystemHook do |
| 65 | 55 | user = create(:user) |
| 66 | 56 | project = create(:project) |
| 67 | 57 | project.team << [user, :master] |
| 68 | - with_resque do | |
| 69 | - project.users_projects.clear | |
| 70 | - end | |
| 58 | + project.users_projects.clear | |
| 71 | 59 | WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once |
| 72 | 60 | end |
| 73 | 61 | end |
| 74 | - | |
| 75 | 62 | end | ... | ... |
spec/observers/issue_observer_spec.rb
| ... | ... | @@ -21,8 +21,7 @@ describe IssueObserver do |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | it 'sends an email to the assignee' do |
| 24 | - Notify.should_receive(:new_issue_email).with(issue.id). | |
| 25 | - and_return(double(deliver: true)) | |
| 24 | + Notify.should_receive(:new_issue_email).with(issue.id) | |
| 26 | 25 | |
| 27 | 26 | subject.after_create(issue) |
| 28 | 27 | end |
| ... | ... | @@ -71,6 +70,7 @@ describe IssueObserver do |
| 71 | 70 | context 'a status "closed"' do |
| 72 | 71 | it 'note is created if the issue is being closed' do |
| 73 | 72 | issue.should_receive(:is_being_closed?).and_return(true) |
| 73 | + Notify.should_receive(:issue_status_changed_email).twice | |
| 74 | 74 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
| 75 | 75 | |
| 76 | 76 | subject.after_update(issue) |
| ... | ... | @@ -85,7 +85,7 @@ describe IssueObserver do |
| 85 | 85 | |
| 86 | 86 | it 'notification is delivered if the issue being closed' do |
| 87 | 87 | issue.stub(:is_being_closed?).and_return(true) |
| 88 | - Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true)) | |
| 88 | + Notify.should_receive(:issue_status_changed_email).twice | |
| 89 | 89 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
| 90 | 90 | |
| 91 | 91 | subject.after_update(issue) |
| ... | ... | @@ -104,7 +104,7 @@ describe IssueObserver do |
| 104 | 104 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
| 105 | 105 | issue_without_assignee.stub(:is_being_closed?).and_return(true) |
| 106 | 106 | issue_without_assignee.stub(:is_being_reopened?).and_return(false) |
| 107 | - Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true)) | |
| 107 | + Notify.should_receive(:issue_status_changed_email).once | |
| 108 | 108 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed') |
| 109 | 109 | |
| 110 | 110 | subject.after_update(issue_without_assignee) |
| ... | ... | @@ -113,6 +113,7 @@ describe IssueObserver do |
| 113 | 113 | |
| 114 | 114 | context 'a status "reopened"' do |
| 115 | 115 | it 'note is created if the issue is being reopened' do |
| 116 | + Notify.should_receive(:issue_status_changed_email).twice | |
| 116 | 117 | issue.should_receive(:is_being_reopened?).and_return(true) |
| 117 | 118 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
| 118 | 119 | |
| ... | ... | @@ -128,7 +129,7 @@ describe IssueObserver do |
| 128 | 129 | |
| 129 | 130 | it 'notification is delivered if the issue being reopened' do |
| 130 | 131 | issue.stub(:is_being_reopened?).and_return(true) |
| 131 | - Notify.should_receive(:issue_status_changed_email).twice.and_return(stub(deliver: true)) | |
| 132 | + Notify.should_receive(:issue_status_changed_email).twice | |
| 132 | 133 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
| 133 | 134 | |
| 134 | 135 | subject.after_update(issue) |
| ... | ... | @@ -147,7 +148,7 @@ describe IssueObserver do |
| 147 | 148 | issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
| 148 | 149 | issue_without_assignee.stub(:is_being_closed?).and_return(false) |
| 149 | 150 | issue_without_assignee.stub(:is_being_reopened?).and_return(true) |
| 150 | - Notify.should_receive(:issue_status_changed_email).once.and_return(stub(deliver: true)) | |
| 151 | + Notify.should_receive(:issue_status_changed_email).once | |
| 151 | 152 | Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened') |
| 152 | 153 | |
| 153 | 154 | subject.after_update(issue_without_assignee) |
| ... | ... | @@ -164,8 +165,7 @@ describe IssueObserver do |
| 164 | 165 | end |
| 165 | 166 | |
| 166 | 167 | def it_sends_a_reassigned_email_to(recipient) |
| 167 | - Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id). | |
| 168 | - and_return(double(deliver: true)) | |
| 168 | + Notify.should_receive(:reassigned_issue_email).with(recipient, issue.id, previous_assignee.id) | |
| 169 | 169 | end |
| 170 | 170 | |
| 171 | 171 | def it_does_not_send_a_reassigned_email_to(recipient) | ... | ... |
spec/observers/merge_request_observer_spec.rb
| ... | ... | @@ -21,9 +21,7 @@ describe MergeRequestObserver do |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | it 'sends an email to the assignee' do |
| 24 | - Notify.should_receive(:new_merge_request_email).with(mr.id). | |
| 25 | - and_return(double(deliver: true)) | |
| 26 | - | |
| 24 | + Notify.should_receive(:new_merge_request_email).with(mr.id) | |
| 27 | 25 | subject.after_create(mr) |
| 28 | 26 | end |
| 29 | 27 | |
| ... | ... | @@ -158,8 +156,7 @@ describe MergeRequestObserver do |
| 158 | 156 | end |
| 159 | 157 | |
| 160 | 158 | def it_sends_a_reassigned_email_to(recipient) |
| 161 | - Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id). | |
| 162 | - and_return(double(deliver: true)) | |
| 159 | + Notify.should_receive(:reassigned_merge_request_email).with(recipient, mr.id, previous_assignee.id) | |
| 163 | 160 | end |
| 164 | 161 | |
| 165 | 162 | def it_does_not_send_a_reassigned_email_to(recipient) | ... | ... |
spec/observers/note_observer_spec.rb
| ... | ... | @@ -4,7 +4,6 @@ describe NoteObserver do |
| 4 | 4 | subject { NoteObserver.instance } |
| 5 | 5 | |
| 6 | 6 | let(:team_without_author) { (1..2).map { |n| double :user, id: n } } |
| 7 | - let(:delivery_success) { double deliver: true } | |
| 8 | 7 | |
| 9 | 8 | describe '#after_create' do |
| 10 | 9 | let(:note) { double :note } |
| ... | ... | @@ -45,13 +44,13 @@ describe NoteObserver do |
| 45 | 44 | note.stub(:id).and_return(42) |
| 46 | 45 | author = double :user, id: 1 |
| 47 | 46 | note.stub(:commit_author).and_return(author) |
| 48 | - Notify.should_receive(:note_commit_email).and_return(delivery_success) | |
| 47 | + Notify.should_receive(:note_commit_email) | |
| 49 | 48 | |
| 50 | 49 | subject.after_create(note) |
| 51 | 50 | end |
| 52 | 51 | |
| 53 | 52 | it 'does not notify the author of a commit when not flagged to notify the author' do |
| 54 | - Notify.should_not_receive(:note_commit_email) | |
| 53 | + notify.should_not_receive(:note_commit_email) | |
| 55 | 54 | |
| 56 | 55 | subject.after_create(note) |
| 57 | 56 | end |
| ... | ... | @@ -71,28 +70,28 @@ describe NoteObserver do |
| 71 | 70 | context 'notifies team of a new note on' do |
| 72 | 71 | it 'a commit' do |
| 73 | 72 | note.stub(:noteable_type).and_return('Commit') |
| 74 | - Notify.should_receive(:note_commit_email).twice.and_return(delivery_success) | |
| 73 | + notify.should_receive(:note_commit_email).twice | |
| 75 | 74 | |
| 76 | 75 | subject.send(:notify_team, note) |
| 77 | 76 | end |
| 78 | 77 | |
| 79 | 78 | it 'an issue' do |
| 80 | 79 | note.stub(:noteable_type).and_return('Issue') |
| 81 | - Notify.should_receive(:note_issue_email).twice.and_return(delivery_success) | |
| 80 | + notify.should_receive(:note_issue_email).twice | |
| 82 | 81 | |
| 83 | 82 | subject.send(:notify_team, note) |
| 84 | 83 | end |
| 85 | 84 | |
| 86 | 85 | it 'a wiki page' do |
| 87 | 86 | note.stub(:noteable_type).and_return('Wiki') |
| 88 | - Notify.should_receive(:note_wiki_email).twice.and_return(delivery_success) | |
| 87 | + notify.should_receive(:note_wiki_email).twice | |
| 89 | 88 | |
| 90 | 89 | subject.send(:notify_team, note) |
| 91 | 90 | end |
| 92 | 91 | |
| 93 | 92 | it 'a merge request' do |
| 94 | 93 | note.stub(:noteable_type).and_return('MergeRequest') |
| 95 | - Notify.should_receive(:note_merge_request_email).twice.and_return(delivery_success) | |
| 94 | + notify.should_receive(:note_merge_request_email).twice | |
| 96 | 95 | |
| 97 | 96 | subject.send(:notify_team, note) |
| 98 | 97 | end |
| ... | ... | @@ -100,16 +99,16 @@ describe NoteObserver do |
| 100 | 99 | it 'a wall' do |
| 101 | 100 | # Note: wall posts have #noteable_type of nil |
| 102 | 101 | note.stub(:noteable_type).and_return(nil) |
| 103 | - Notify.should_receive(:note_wall_email).twice.and_return(delivery_success) | |
| 102 | + notify.should_receive(:note_wall_email).twice | |
| 104 | 103 | |
| 105 | 104 | subject.send(:notify_team, note) |
| 106 | 105 | end |
| 107 | 106 | end |
| 108 | 107 | |
| 109 | 108 | it 'does nothing for a new note on a snippet' do |
| 110 | - note.stub(:noteable_type).and_return('Snippet') | |
| 109 | + note.stub(:noteable_type).and_return('Snippet') | |
| 111 | 110 | |
| 112 | - subject.send(:notify_team, note).should be_nil | |
| 111 | + subject.send(:notify_team, note).should be_nil | |
| 113 | 112 | end |
| 114 | 113 | end |
| 115 | 114 | |
| ... | ... | @@ -125,4 +124,8 @@ describe NoteObserver do |
| 125 | 124 | subject.send(:team_without_note_author, note).should == team_without_author |
| 126 | 125 | end |
| 127 | 126 | end |
| 127 | + | |
| 128 | + def notify | |
| 129 | + Notify | |
| 130 | + end | |
| 128 | 131 | end | ... | ... |
spec/observers/user_observer_spec.rb
| ... | ... | @@ -10,24 +10,14 @@ describe UserObserver do |
| 10 | 10 | end |
| 11 | 11 | |
| 12 | 12 | context 'when a new user is created' do |
| 13 | - let(:user) { double(:user, id: 42, | |
| 14 | - password: 'P@ssword!', | |
| 15 | - name: 'John', | |
| 16 | - email: 'u@mail.local', | |
| 17 | - username: 'root', | |
| 18 | - create_namespace: true) } | |
| 19 | - let(:notification) { double :notification } | |
| 20 | - | |
| 21 | 13 | it 'sends an email' do |
| 22 | - notification.should_receive(:deliver) | |
| 23 | - Notify.should_receive(:new_user_email).with(user.id, user.password).and_return(notification) | |
| 24 | - | |
| 25 | - subject.after_create(user) | |
| 14 | + Notify.should_receive(:new_user_email) | |
| 15 | + create(:user) | |
| 26 | 16 | end |
| 27 | 17 | |
| 28 | 18 | it 'trigger logger' do |
| 29 | 19 | Gitlab::AppLogger.should_receive(:info) |
| 30 | - subject.after_create(user) | |
| 20 | + create(:user) | |
| 31 | 21 | end |
| 32 | 22 | end |
| 33 | 23 | end | ... | ... |
spec/requests/admin/admin_users_spec.rb
| ... | ... | @@ -41,7 +41,7 @@ describe "Admin::Users" do |
| 41 | 41 | end |
| 42 | 42 | |
| 43 | 43 | it "should call send mail" do |
| 44 | - Notify.should_receive(:new_user_email).and_return(stub(deliver: true)) | |
| 44 | + Notify.should_receive(:new_user_email) | |
| 45 | 45 | |
| 46 | 46 | User.observers.enable :user_observer do |
| 47 | 47 | click_button "Save" |
| ... | ... | @@ -50,9 +50,7 @@ describe "Admin::Users" do |
| 50 | 50 | |
| 51 | 51 | it "should send valid email to user with email & password" do |
| 52 | 52 | User.observers.enable :user_observer do |
| 53 | - with_resque do | |
| 54 | - click_button "Save" | |
| 55 | - end | |
| 53 | + click_button "Save" | |
| 56 | 54 | user = User.last |
| 57 | 55 | email = ActionMailer::Base.deliveries.last |
| 58 | 56 | email.subject.should have_content("Account was created") | ... | ... |
spec/spec_helper.rb
| 1 | 1 | require 'simplecov' unless ENV['CI'] |
| 2 | 2 | |
| 3 | + | |
| 3 | 4 | # This file is copied to spec/ when you run 'rails generate rspec:install' |
| 4 | 5 | ENV["RAILS_ENV"] ||= 'test' |
| 5 | 6 | require File.expand_path("../../config/environment", __FILE__) |
| ... | ... | @@ -8,6 +9,7 @@ require 'capybara/rails' |
| 8 | 9 | require 'capybara/rspec' |
| 9 | 10 | require 'webmock/rspec' |
| 10 | 11 | require 'email_spec' |
| 12 | +require 'sidekiq/testing/inline' | |
| 11 | 13 | |
| 12 | 14 | # Requires supporting ruby files with custom matchers and macros, etc, |
| 13 | 15 | # in spec/support/ and its subdirectories. | ... | ... |
spec/workers/post_receive_spec.rb
| ... | ... | @@ -4,7 +4,7 @@ describe PostReceive do |
| 4 | 4 | |
| 5 | 5 | context "as a resque worker" do |
| 6 | 6 | it "reponds to #perform" do |
| 7 | - PostReceive.should respond_to(:perform) | |
| 7 | + PostReceive.new.should respond_to(:perform) | |
| 8 | 8 | end |
| 9 | 9 | end |
| 10 | 10 | |
| ... | ... | @@ -15,7 +15,7 @@ describe PostReceive do |
| 15 | 15 | |
| 16 | 16 | it "fetches the correct project" do |
| 17 | 17 | Project.should_receive(:find_with_namespace).with(project.path_with_namespace).and_return(project) |
| 18 | - PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 18 | + PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | 21 | it "does not run if the author is not in the project" do |
| ... | ... | @@ -24,7 +24,7 @@ describe PostReceive do |
| 24 | 24 | project.should_not_receive(:observe_push) |
| 25 | 25 | project.should_not_receive(:execute_hooks) |
| 26 | 26 | |
| 27 | - PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false | |
| 27 | + PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false | |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | it "asks the project to trigger all hooks" do |
| ... | ... | @@ -34,7 +34,7 @@ describe PostReceive do |
| 34 | 34 | project.should_receive(:update_merge_requests) |
| 35 | 35 | project.should_receive(:observe_push) |
| 36 | 36 | |
| 37 | - PostReceive.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 37 | + PostReceive.new.perform(pwd(project), 'sha-old', 'sha-new', 'refs/heads/master', key_id) | |
| 38 | 38 | end |
| 39 | 39 | end |
| 40 | 40 | ... | ... |