Browse Source

Port travis_retry for CI (#7379)

* Port travis_retry for CI

* Add license
Yamagishi Kazutoshi 9 months ago
parent
commit
8c35d163a5
5 changed files with 48 additions and 14 deletions
  1. 2
    2
      .circleci/config.yml
  2. 0
    1
      Gemfile
  3. 0
    3
      Gemfile.lock
  4. 46
    0
      bin/retry
  5. 0
    8
      spec/spec_helper.rb

+ 2
- 2
.circleci/config.yml View File

@@ -90,7 +90,7 @@ aliases:
90 90
             command: ./bin/rails parallel:create parallel:load_schema parallel:prepare
91 91
         - run:
92 92
             name: Run Tests
93
-            command: bundle exec parallel_test ./spec/ --group-by filesize --type rspec
93
+            command: ./bin/retry bundle exec parallel_test ./spec/ --group-by filesize --type rspec
94 94
 
95 95
 jobs:
96 96
   install:
@@ -150,7 +150,7 @@ jobs:
150 150
       - image: circleci/node:8.11.1-stretch
151 151
     steps:
152 152
       - *attach_workspace
153
-      - run: yarn test:jest
153
+      - run: ./bin/retry yarn test:jest
154 154
 
155 155
   check-i18n:
156 156
     <<: *defaults

+ 0
- 1
Gemfile View File

@@ -112,7 +112,6 @@ group :test do
112 112
   gem 'microformats', '~> 4.0'
113 113
   gem 'rails-controller-testing', '~> 1.0'
114 114
   gem 'rspec-sidekiq', '~> 3.0'
115
-  gem 'rspec-retry', '~> 0.5', require: false
116 115
   gem 'simplecov', '~> 0.16', require: false
117 116
   gem 'webmock', '~> 3.3'
118 117
   gem 'parallel_tests', '~> 2.21'

+ 0
- 3
Gemfile.lock View File

@@ -501,8 +501,6 @@ GEM
501 501
       rspec-expectations (~> 3.7.0)
502 502
       rspec-mocks (~> 3.7.0)
503 503
       rspec-support (~> 3.7.0)
504
-    rspec-retry (0.5.7)
505
-      rspec-core (> 3.3)
506 504
     rspec-sidekiq (3.0.3)
507 505
       rspec-core (~> 3.0, >= 3.0.0)
508 506
       sidekiq (>= 2.4.0)
@@ -726,7 +724,6 @@ DEPENDENCIES
726 724
   redis-rails (~> 5.0)
727 725
   rqrcode (~> 0.10)
728 726
   rspec-rails (~> 3.7)
729
-  rspec-retry (~> 0.5)
730 727
   rspec-sidekiq (~> 3.0)
731 728
   rubocop (~> 0.55)
732 729
   ruby-progressbar (~> 1.4)

+ 46
- 0
bin/retry View File

@@ -0,0 +1,46 @@
1
+#!/bin/bash
2
+# https://github.com/travis-ci/travis-build/blob/cbe49ea239ab37b9b38b5b44d287b7ec7a108c16/lib/travis/build/templates/header.sh#L243-L260
3
+#
4
+# MIT LICENSE
5
+#
6
+# Copyright (c) 2016 Travis CI GmbH <contact@travis-ci.org>
7
+#
8
+# Permission is hereby granted, free of charge, to any person obtaining a copy
9
+# of this software and associated documentation files (the "Software"), to deal
10
+# in the Software without restriction, including without limitation the rights
11
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+# copies of the Software, and to permit persons to whom the Software is
13
+# furnished to do so, subject to the following conditions:
14
+#
15
+# The above copyright notice and this permission notice shall be included in
16
+# all copies or substantial portions of the Software.
17
+#
18
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+# THE SOFTWARE.
25
+retry() {
26
+  local result=0
27
+  local count=1
28
+
29
+  while [ $count -le 3 ]; do
30
+    if [ $result -ne 0 ]; then
31
+      echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
32
+    fi
33
+
34
+    "$@" && { result=0 && break; } || result=$?
35
+    count=$(($count + 1))
36
+    sleep 1
37
+  done
38
+
39
+  if [ $count -gt 3 ]; then
40
+    echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
41
+  fi
42
+
43
+  return $result
44
+}
45
+
46
+retry $@

+ 0
- 8
spec/spec_helper.rb View File

@@ -1,4 +1,3 @@
1
-#require 'rspec/retry'
2 1
 require 'simplecov'
3 2
 
4 3
 GC.disable
@@ -12,9 +11,6 @@ end
12 11
 gc_counter = -1
13 12
 
14 13
 RSpec.configure do |config|
15
-  #config.verbose_retry = true
16
-  #config.display_try_failure_messages = true
17
-
18 14
   config.expect_with :rspec do |expectations|
19 15
     expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20 16
   end
@@ -29,10 +25,6 @@ RSpec.configure do |config|
29 25
     end
30 26
   end
31 27
 
32
-  #config.around :each do |ex|
33
-  #  ex.run_with_retry retry: 3
34
-  #end
35
-
36 28
   config.before :suite do
37 29
     Chewy.strategy(:bypass)
38 30
   end

Loading…
Cancel
Save