Commit 216d5e2c1adb8470421a99943f09c45e4e515d5b
1 parent
5d56da6b
Exists in
master
and in
4 other branches
Fix intermittently failing notification_service test
Change-Id: Ic23cb46901f8adc77943bf3cc79566587364e22a
Showing
3 changed files
with
63 additions
and
56 deletions
Show diff stats
spec/requests/api/repositories_spec.rb
spec/services/notification_service_spec.rb
spec/support/test_env.rb
| ... | ... | @@ -34,43 +34,19 @@ module TestEnv |
| 34 | 34 | setup_test_repos(opts) if opts[:repos] == true |
| 35 | 35 | end |
| 36 | 36 | |
| 37 | - def testing_path | |
| 38 | - Rails.root.join('tmp', 'test-git-base-path') | |
| 39 | - end | |
| 40 | - | |
| 41 | - def seed_repo_path | |
| 42 | - Rails.root.join('tmp', 'repositories', 'gitlabhq') | |
| 43 | - end | |
| 44 | - | |
| 45 | - def seed_satellite_path | |
| 46 | - Rails.root.join('tmp', 'satellite', 'gitlabhq') | |
| 47 | - end | |
| 48 | - | |
| 49 | - def satellite_path | |
| 50 | - "#{testing_path()}/satellite" | |
| 37 | + def enable_observers | |
| 38 | + ActiveRecord::Base.observers.enable(:all) | |
| 51 | 39 | end |
| 52 | 40 | |
| 53 | - def repo(namespace, name) | |
| 54 | - unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) | |
| 55 | - repo = File.join(testing_path(), "#{namespace.path}/#{name}.git") | |
| 56 | - else | |
| 57 | - repo = File.join(testing_path(), "#{name}.git") | |
| 58 | - end | |
| 41 | + def disable_observers | |
| 42 | + ActiveRecord::Base.observers.disable(:all) | |
| 59 | 43 | end |
| 60 | 44 | |
| 61 | - def satellite(namespace, name) | |
| 62 | - unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) | |
| 63 | - satellite_repo = File.join(satellite_path, namespace.path, name) | |
| 64 | - else | |
| 65 | - satellite_repo = File.join(satellite_path, name) | |
| 66 | - end | |
| 45 | + def disable_mailer | |
| 46 | + NotificationService.any_instance.stub(mailer: double.as_null_object) | |
| 67 | 47 | end |
| 68 | - | |
| 69 | - | |
| 70 | - def setup_test_repos(opts ={}) | |
| 71 | - create_repo(nil, 'gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('') | |
| 72 | - create_repo(nil, 'source_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('source_') | |
| 73 | - create_repo(nil, 'target_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('target_') | |
| 48 | + def enable_mailer | |
| 49 | + NotificationService.any_instance.unstub(:mailer) | |
| 74 | 50 | end |
| 75 | 51 | |
| 76 | 52 | def setup_stubs() |
| ... | ... | @@ -110,19 +86,6 @@ module TestEnv |
| 110 | 86 | ) |
| 111 | 87 | end |
| 112 | 88 | |
| 113 | - def clear_test_repo_dir | |
| 114 | - setup_stubs | |
| 115 | - # Use tmp dir for FS manipulations | |
| 116 | - repos_path = testing_path() | |
| 117 | - # Remove tmp/test-git-base-path | |
| 118 | - FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path | |
| 119 | - | |
| 120 | - # Recreate tmp/test-git-base-path | |
| 121 | - FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path | |
| 122 | - #Since much more is happening in satellites | |
| 123 | - FileUtils.mkdir_p Gitlab.config.satellites.path | |
| 124 | - end | |
| 125 | - | |
| 126 | 89 | def clear_repo_dir(namespace, name) |
| 127 | 90 | setup_stubs |
| 128 | 91 | #Clean any .wiki.git that may have been created |
| ... | ... | @@ -139,6 +102,60 @@ module TestEnv |
| 139 | 102 | create_satellite(repo, namespace, name) |
| 140 | 103 | end |
| 141 | 104 | |
| 105 | + private | |
| 106 | + | |
| 107 | + def testing_path | |
| 108 | + Rails.root.join('tmp', 'test-git-base-path') | |
| 109 | + end | |
| 110 | + | |
| 111 | + def seed_repo_path | |
| 112 | + Rails.root.join('tmp', 'repositories', 'gitlabhq') | |
| 113 | + end | |
| 114 | + | |
| 115 | + def seed_satellite_path | |
| 116 | + Rails.root.join('tmp', 'satellite', 'gitlabhq') | |
| 117 | + end | |
| 118 | + | |
| 119 | + def satellite_path | |
| 120 | + "#{testing_path()}/satellite" | |
| 121 | + end | |
| 122 | + | |
| 123 | + def repo(namespace, name) | |
| 124 | + unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) | |
| 125 | + repo = File.join(testing_path(), "#{namespace.path}/#{name}.git") | |
| 126 | + else | |
| 127 | + repo = File.join(testing_path(), "#{name}.git") | |
| 128 | + end | |
| 129 | + end | |
| 130 | + | |
| 131 | + def satellite(namespace, name) | |
| 132 | + unless (namespace.nil? || namespace.path.nil? || namespace.path.strip.empty?) | |
| 133 | + satellite_repo = File.join(satellite_path, namespace.path, name) | |
| 134 | + else | |
| 135 | + satellite_repo = File.join(satellite_path, name) | |
| 136 | + end | |
| 137 | + end | |
| 138 | + | |
| 139 | + def setup_test_repos(opts ={}) | |
| 140 | + create_repo(nil, 'gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('') | |
| 141 | + create_repo(nil, 'source_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('source_') | |
| 142 | + create_repo(nil, 'target_gitlabhq') #unless opts[:repo].nil? || !opts[:repo].include?('target_') | |
| 143 | + end | |
| 144 | + | |
| 145 | + def clear_test_repo_dir | |
| 146 | + setup_stubs | |
| 147 | + # Use tmp dir for FS manipulations | |
| 148 | + repos_path = testing_path() | |
| 149 | + # Remove tmp/test-git-base-path | |
| 150 | + FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path | |
| 151 | + | |
| 152 | + # Recreate tmp/test-git-base-path | |
| 153 | + FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path | |
| 154 | + | |
| 155 | + #Since much more is happening in satellites | |
| 156 | + FileUtils.mkdir_p Gitlab.config.satellites.path | |
| 157 | + end | |
| 158 | + | |
| 142 | 159 | # Create a testing satellite, and clone the source repo into it |
| 143 | 160 | def create_satellite(source_repo, namespace, satellite_name) |
| 144 | 161 | satellite_repo = satellite(namespace, satellite_name) |
| ... | ... | @@ -152,15 +169,5 @@ module TestEnv |
| 152 | 169 | system(command) |
| 153 | 170 | end |
| 154 | 171 | |
| 155 | - def enable_observers | |
| 156 | - ActiveRecord::Base.observers.enable(:all) | |
| 157 | - end | |
| 158 | - | |
| 159 | - def disable_observers | |
| 160 | - ActiveRecord::Base.observers.disable(:all) | |
| 161 | - end | |
| 162 | 172 | |
| 163 | - def disable_mailer | |
| 164 | - NotificationService.any_instance.stub(mailer: double.as_null_object) | |
| 165 | - end | |
| 166 | 173 | end | ... | ... |