synchronised_migration 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c1431ba1cc8bb0ad840ba1020723cbefe53e2b88f3e40e80e24a203b7ab8163
4
- data.tar.gz: 0faa2082f8cbceefcaa72b566d9ec16b02be2e19b27016ddf47e7a8f5d882659
3
+ metadata.gz: cc7b4ada6d890ac183de30b375e6ead7de8dde32827aa870808552420637a006
4
+ data.tar.gz: 1826cd77772547266f1dcf309a52574960aa0fdd6efb96a148264ad995979b08
5
5
  SHA512:
6
- metadata.gz: 842a04dca6b33503bf50d9563d688ea10c2ac624523b893a6f6314367dbff97c98cfecaf0dd9c82c32d0084323e1231aa81409a5616a6806b2b025b8fee9ffc2
7
- data.tar.gz: d0be7428022db07f04c00d6017f29c2988035365c5ce76430cbae5177cd672d77aed79ff850e1a5a93987f25042a141cee384df6fe9ebdfabe7f117c0691fa1c
6
+ metadata.gz: 5748c0d00c031d6bea8400d598c39f97a6bde99eebfe9273e018fd346ca79186a809ef6f16d9ce6a4213a583e88b7f1fce3e713fd2a9dc40a7adb70340016a0c
7
+ data.tar.gz: 18442e4f7ddcbdb497af3a05852b59677840871c24844945ddf4da3fca9a5edf2857f6090c5c01067d69c88ee7098a7e5e0ca5f8632e273399c614b537c36de2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Synchronised Migration
2
2
 
3
+ ## 2.1.1
4
+
5
+ * [TT-5896] Early exit from migration inside lock if already completed
6
+
3
7
  ## 2.1.0
4
8
 
5
9
  * [TT-5827] Add "success key" when REDLOCK_VERSION_SUFFIX is set, preventing repeat runs
@@ -32,10 +32,11 @@ class SynchronisedMigration::Main
32
32
  end
33
33
 
34
34
  def execute
35
+ return Result.ok if migration_already_completed?
35
36
  return Result.fail 'Halting the script because the previous migration failed.' if previous_failed?
36
37
  mark_failed
37
- migrate
38
- return Result.fail 'Migration failed.' if migration_failed?
38
+ migration_success = migrate
39
+ return Result.fail 'Migration failed.' unless migration_success
39
40
  mark_successful
40
41
  remove_fail_marker
41
42
  return Result.ok
@@ -67,20 +68,20 @@ class SynchronisedMigration::Main
67
68
  end
68
69
 
69
70
  def migrate
70
- return Kernel.system target_command unless with_clean_env?
71
- Bundler.with_original_env do
72
- Kernel.system target_command
71
+ if with_clean_env?
72
+ Bundler.with_original_env do
73
+ Kernel.system target_command
74
+ end
75
+ else
76
+ Kernel.system target_command
73
77
  end
78
+ $?.success?
74
79
  end
75
80
 
76
81
  def with_clean_env?
77
82
  not ENV.fetch('WITH_CLEAN_BUNDLER_ENV', '').empty?
78
83
  end
79
84
 
80
- def migration_failed?
81
- not $?.success?
82
- end
83
-
84
85
  def target_command
85
86
  ENV.fetch 'SYNCHRONISED_COMMAND', 'bin/launch/migrate'
86
87
  end
@@ -1,3 +1,3 @@
1
1
  module SynchronisedMigration
2
- VERSION = '2.1.0'
2
+ VERSION = '2.1.1'
3
3
  end
@@ -10,7 +10,8 @@ describe SynchronisedMigration::Main do
10
10
  let(:redlock) { double }
11
11
  let(:fail_marker_value) { nil }
12
12
  let(:success_marker_value) { nil }
13
- let(:set_version_suffix) { ENV['REDLOCK_VERSION_SUFFIX'] = 'bork' }
13
+ let(:version_suffix) { 'bork' }
14
+ let(:set_version_suffix) { ENV['REDLOCK_VERSION_SUFFIX'] = version_suffix }
14
15
  let(:time_value) { double(to_i: 123456789) }
15
16
 
16
17
  before do
@@ -19,8 +20,24 @@ describe SynchronisedMigration::Main do
19
20
  subject.instance.instance_variable_set :@redis, nil
20
21
  subject.instance.instance_variable_set :@redlock, nil
21
22
 
23
+ allow(subject.instance).to receive(:execute).and_call_original
24
+ allow(subject.instance).to receive(:migrate).and_call_original
25
+
22
26
  allow(Redis).to receive(:new).and_return(redis)
23
- allow(redis).to receive(:get).and_return(success_marker_value, fail_marker_value)
27
+ allow(redis).to receive(:get) { |key|
28
+ case key
29
+ when "migration-failed-#{version_suffix}"
30
+ fail_marker_value
31
+ when "migration-failed"
32
+ fail_marker_value
33
+ when "migration-success-#{version_suffix}"
34
+ success_marker_value
35
+ when "migration-success"
36
+ success_marker_value
37
+ else
38
+ raise "invalid key for redis get: #{key}"
39
+ end
40
+ }
24
41
  allow(redis).to receive(:set)
25
42
  allow(redis).to receive(:del)
26
43
 
@@ -62,6 +79,24 @@ describe SynchronisedMigration::Main do
62
79
  expect(redlock).not_to have_received(:lock!)
63
80
  end
64
81
  end
82
+
83
+ context 'executing in lock waiter' do
84
+ let(:result2) { subject.call }
85
+
86
+ before do
87
+ # Note: bypasses the first success flag check so it can enter lock.
88
+ expect(result).to be_success
89
+ allow(redis).to receive(:get).and_return(nil, '1')
90
+ end
91
+
92
+ it 'early exits and does not execute again', :aggregate_failures do
93
+ expect(result2).to be_success
94
+ expect(redlock).to have_received(:lock!).exactly(2).times
95
+ expect(Kernel).to have_received(:system).exactly(1).times
96
+ expect(subject.instance).to have_received(:execute).exactly(2).times
97
+ expect(subject.instance).to have_received(:migrate).exactly(1).times
98
+ end
99
+ end
65
100
  end
66
101
 
67
102
  context 'when require a clean Bundler environment' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchronised_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alvin Yim
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-06 00:00:00.000000000 Z
12
+ date: 2019-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redlock