dynflow 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/dynflow.gemspec +1 -0
- data/lib/dynflow/persistence_adapters/sequel_migrations/001_initial.rb +2 -1
- data/lib/dynflow/version.rb +1 -1
- data/test/redis_locking_test.rb +92 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfb6db078bac6d7bb006fa9cdc7ccb30a5eaa507d5c5fde11723c5295fe7990c
|
4
|
+
data.tar.gz: 7959053035ed970863493c066622e51ca16733d17be8869458ef79c6ccfe4244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219901624a304846e8d8b3e70e274e2b291923db9f43ae482816b02caa3b967985fc75f936283e5647f98415d788235e7521ac26f28b59dde625084ed9599bf5
|
7
|
+
data.tar.gz: d1a32c183a574de8e3a0aeeb875bafa6082f2a2971a0f8755f441ab5d350cba2de19e2df22c93109335244f8e84ac65b5dc100abd3517c098bc37e7231751ce2
|
data/.travis.yml
CHANGED
@@ -2,6 +2,7 @@ language: ruby
|
|
2
2
|
|
3
3
|
services:
|
4
4
|
- postgresql
|
5
|
+
- redis
|
5
6
|
|
6
7
|
rvm:
|
7
8
|
- "2.3.1"
|
@@ -18,6 +19,7 @@ matrix:
|
|
18
19
|
env: "DB=mysql DB_CONN_STRING=mysql2://root@localhost/travis_ci_test"
|
19
20
|
services:
|
20
21
|
- mysql
|
22
|
+
- redis
|
21
23
|
- rvm: "2.4.0"
|
22
24
|
env: "DB=sqlite3 DB_CONN_STRING=sqlite:/"
|
23
25
|
- rvm: "2.4.0"
|
data/dynflow.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_development_dependency "rack-test"
|
31
31
|
s.add_development_dependency "minitest"
|
32
32
|
s.add_development_dependency "minitest-reporters"
|
33
|
+
s.add_development_dependency "minitest-stub-const"
|
33
34
|
s.add_development_dependency "activerecord"
|
34
35
|
s.add_development_dependency 'activejob'
|
35
36
|
s.add_development_dependency "sqlite3"
|
@@ -32,7 +32,8 @@ Sequel.migration do
|
|
32
32
|
primary_key [:execution_plan_uuid, :id]
|
33
33
|
index [:execution_plan_uuid, :id], :unique => true
|
34
34
|
column :action_id, Integer
|
35
|
-
foreign_key [:execution_plan_uuid, :action_id], :dynflow_actions
|
35
|
+
foreign_key [:execution_plan_uuid, :action_id], :dynflow_actions,
|
36
|
+
name: :dynflow_steps_execution_plan_uuid_fkey1
|
36
37
|
index [:execution_plan_uuid, :action_id]
|
37
38
|
|
38
39
|
column :data, String, text: true
|
data/lib/dynflow/version.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'test_helper'
|
3
|
+
require 'mocha/minitest'
|
4
|
+
require 'minitest/stub_const'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'sidekiq'
|
7
|
+
require 'dynflow/executors/sidekiq/core'
|
8
|
+
|
9
|
+
module Dynflow
|
10
|
+
module RedisLockingTest
|
11
|
+
describe Executors::Sidekiq::RedisLocking do
|
12
|
+
class Orchestrator
|
13
|
+
include Executors::Sidekiq::RedisLocking
|
14
|
+
|
15
|
+
attr_accessor :logger
|
16
|
+
|
17
|
+
def initialize(world, logger)
|
18
|
+
@world = world
|
19
|
+
@logger = logger
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Logger
|
24
|
+
attr_reader :logs
|
25
|
+
def initialize
|
26
|
+
@logs = []
|
27
|
+
end
|
28
|
+
|
29
|
+
[:info, :error, :fatal].each do |key|
|
30
|
+
define_method key do |message|
|
31
|
+
@logs << [key, message]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
::Sidekiq.redis do |conn|
|
38
|
+
conn.del Executors::Sidekiq::RedisLocking::REDIS_LOCK_KEY
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def redis_orchestrator_id
|
43
|
+
::Sidekiq.redis do |conn|
|
44
|
+
conn.get Executors::Sidekiq::RedisLocking::REDIS_LOCK_KEY
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:world) { OpenStruct.new(:id => '12345') }
|
49
|
+
let(:world2) { OpenStruct.new(:id => '67890') }
|
50
|
+
let(:orchestrator) { Orchestrator.new(world, Logger.new) }
|
51
|
+
let(:orchestrator2) { Orchestrator.new(world2, Logger.new) }
|
52
|
+
|
53
|
+
it 'acquires the lock when it is not taken' do
|
54
|
+
orchestrator.wait_for_orchestrator_lock
|
55
|
+
logs = orchestrator.logger.logs
|
56
|
+
_(redis_orchestrator_id).must_equal world.id
|
57
|
+
_(logs).must_equal [[:info, 'Acquired orchestrator lock, entering active mode.']]
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'reacquires the lock if it was lost' do
|
61
|
+
orchestrator.reacquire_orchestrator_lock
|
62
|
+
logs = orchestrator.logger.logs
|
63
|
+
_(redis_orchestrator_id).must_equal world.id
|
64
|
+
_(logs).must_equal [[:error, 'The orchestrator lock was lost, reacquired']]
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'terminates the process if lock was stolen' do
|
68
|
+
orchestrator.wait_for_orchestrator_lock
|
69
|
+
Process.expects(:kill)
|
70
|
+
orchestrator2.reacquire_orchestrator_lock
|
71
|
+
logs = orchestrator2.logger.logs
|
72
|
+
_(redis_orchestrator_id).must_equal world.id
|
73
|
+
_(logs).must_equal [[:fatal, 'The orchestrator lock was stolen by 12345, aborting.']]
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'polls for the lock availability' do
|
77
|
+
Executors::Sidekiq::RedisLocking.stub_const(:REDIS_LOCK_TTL, 1) do
|
78
|
+
Executors::Sidekiq::RedisLocking.stub_const(:REDIS_LOCK_POLL_INTERVAL, 0.5) do
|
79
|
+
orchestrator.wait_for_orchestrator_lock
|
80
|
+
_(redis_orchestrator_id).must_equal world.id
|
81
|
+
orchestrator2.wait_for_orchestrator_lock
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
_(redis_orchestrator_id).must_equal world2.id
|
86
|
+
passive, active = orchestrator2.logger.logs
|
87
|
+
_(passive).must_equal [:info, 'Orchestrator lock already taken, entering passive mode.']
|
88
|
+
_(active).must_equal [:info, 'Acquired orchestrator lock, entering active mode.']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Necas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -151,6 +151,20 @@ dependencies:
|
|
151
151
|
- - ">="
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: minitest-stub-const
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
154
168
|
- !ruby/object:Gem::Dependency
|
155
169
|
name: activerecord
|
156
170
|
requirement: !ruby/object:Gem::Requirement
|
@@ -566,6 +580,7 @@ files:
|
|
566
580
|
- test/middleware_test.rb
|
567
581
|
- test/persistence_test.rb
|
568
582
|
- test/prepare_travis_env.sh
|
583
|
+
- test/redis_locking_test.rb
|
569
584
|
- test/rescue_test.rb
|
570
585
|
- test/round_robin_test.rb
|
571
586
|
- test/semaphores_test.rb
|
@@ -648,6 +663,7 @@ test_files:
|
|
648
663
|
- test/middleware_test.rb
|
649
664
|
- test/persistence_test.rb
|
650
665
|
- test/prepare_travis_env.sh
|
666
|
+
- test/redis_locking_test.rb
|
651
667
|
- test/rescue_test.rb
|
652
668
|
- test/round_robin_test.rb
|
653
669
|
- test/semaphores_test.rb
|