fork_break 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.travis.yml +23 -0
- data/README.md +8 -0
- data/fork_break.gemspec +8 -7
- data/lib/fork_break.rb +1 -0
- data/lib/fork_break/null_breakpoint_setter.rb +7 -0
- data/lib/fork_break/process.rb +9 -1
- data/lib/fork_break/version.rb +1 -1
- data/spec/fork_break_spec.rb +30 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a045eeead39fd72e60950ac324dd97e1886f1adc
|
4
|
+
data.tar.gz: 2c8be1f3dd8803350b83aaa87967cbbcde7ef27b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76cf51cf876d68c1d97ef8099889b1bc1e829b3d7f4ad121c2bb87f523dcb7afcce3386cda2266bf97d952e288285bef87e0aa4d29a38a8add251565d9afcc34
|
7
|
+
data.tar.gz: c6404a9230a6c0d8022d06290db9bd00ed886d5e0dc689159e1055b957ff70ec6b858bfa1d30f390f465161ecd81af93e1df4125457c4560e005438bcbe1281b
|
data/.rubocop.yml
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.1.7
|
5
|
+
- 2.2.3
|
6
|
+
- jruby-19mode
|
7
|
+
- jruby-head
|
8
|
+
- rbx-2
|
9
|
+
- ruby-head
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: jruby-19mode
|
14
|
+
- rvm: jruby-head
|
15
|
+
|
16
|
+
before_install:
|
17
|
+
- gem update --system
|
18
|
+
- gem install bundler -v 1.10.6
|
19
|
+
install: 'bundle'
|
20
|
+
script: 'bundle exec rspec && bundle exec rubocop'
|
21
|
+
notifications:
|
22
|
+
email:
|
23
|
+
- pedro.carrico@gmail.com
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ForkBreak
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/forkbreak/fork_break.png)](http://travis-ci.org/forkbreak/fork_break) [![Dependency Status](https://gemnasium.com/forkbreak/fork_break.png)](https://gemnasium.com/forkbreak/fork_break) [![Gem Version](https://badge.fury.io/rb/fork_break.svg)](http://badge.fury.io/rb/fork_break) [![Code Climate](https://codeclimate.com/github/forkbreak/fork_break/badges/gpa.svg)](https://codeclimate.com/github/forkbreak/fork_break)
|
4
|
+
|
3
5
|
Testing multiprocess behaviour is difficult and requires a way to synchronize processes at
|
4
6
|
specific execution points. This gem allows the parent process to control the behaviour of child processes using
|
5
7
|
breakpoints. It was originally built for testing the behaviour of database transactions and locking mechanisms.
|
@@ -98,6 +100,9 @@ puts counter_after_synced_execution("counter_with_lock", true) # => 2
|
|
98
100
|
puts counter_after_synced_execution("counter_without_lock", false) # => 1
|
99
101
|
```
|
100
102
|
|
103
|
+
When running outside a ForkBreak process the breakpoints will be ignored so that you can use the same classes with
|
104
|
+
breakpoints in production code.
|
105
|
+
|
101
106
|
There's also the possibility of adding a predefined timeout to the wait function and having it raise an exception.
|
102
107
|
|
103
108
|
```ruby
|
@@ -115,3 +120,6 @@ process.finish.wait(timeout: 1) # will raise ForkBreak::WaitTimeout after 1 seco
|
|
115
120
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
116
121
|
4. Push to the branch (`git push origin my-new-feature`)
|
117
122
|
5. Create new Pull Request
|
123
|
+
|
124
|
+
## License
|
125
|
+
ForkBreak is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/fork_break.gemspec
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'fork_break/version'
|
2
5
|
|
3
6
|
Gem::Specification.new do |gem|
|
4
|
-
gem.authors = ['Petter Remen']
|
5
|
-
gem.email = ['petter.remen@gmail.com']
|
7
|
+
gem.authors = ['Petter Remen', 'Pedro Carriço']
|
6
8
|
gem.summary =
|
7
9
|
'Testing multiprocess behaviour is difficult and requires a way to synchronize processes at specific execution ' \
|
8
10
|
'points. This gem allows the parent process to control the behaviour of child processes using breakpoints. It was' \
|
9
11
|
'originally built for testing the behaviour of database transactions and locking mechanisms.'
|
10
12
|
gem.description = 'Fork with breakpoints for syncing child process execution'
|
11
|
-
gem.homepage = 'http://github.com/
|
13
|
+
gem.homepage = 'http://github.com/forkbreak/fork_break'
|
12
14
|
gem.licenses = ['MIT']
|
13
|
-
|
14
15
|
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
15
|
-
gem.executables = gem.files.grep(
|
16
|
-
gem.test_files = gem.files.grep(
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
18
|
gem.name = 'fork_break'
|
18
19
|
gem.require_paths = ['lib']
|
19
20
|
gem.version = ForkBreak::VERSION
|
data/lib/fork_break.rb
CHANGED
data/lib/fork_break/process.rb
CHANGED
@@ -4,16 +4,21 @@ module ForkBreak
|
|
4
4
|
attr_accessor :breakpoint_setter
|
5
5
|
end
|
6
6
|
|
7
|
+
attr_reader :return_value
|
8
|
+
|
9
|
+
@breakpoint_setter = NullBreakpointSetter.new
|
10
|
+
|
7
11
|
def initialize(debug = false, &block)
|
8
12
|
@debug = debug
|
9
13
|
@fork = Fork.new(:return, :to_fork, :from_fork) do |child_fork|
|
10
14
|
self.class.breakpoint_setter = breakpoints = BreakpointSetter.new(child_fork, debug)
|
11
15
|
|
12
16
|
breakpoints << :forkbreak_start
|
13
|
-
block.call(breakpoints)
|
17
|
+
returned_value = block.call(breakpoints)
|
14
18
|
breakpoints << :forkbreak_end
|
15
19
|
|
16
20
|
self.class.breakpoint_setter = nil
|
21
|
+
returned_value
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
@@ -31,6 +36,9 @@ module ForkBreak
|
|
31
36
|
loop do
|
32
37
|
brk = @fork.receive_object
|
33
38
|
puts "Parent is receiving object #{brk} from #{@fork.pid}" if @debug
|
39
|
+
|
40
|
+
@return_value = @fork.return_value if brk == :forkbreak_end
|
41
|
+
|
34
42
|
if brk == @next_breakpoint
|
35
43
|
return self
|
36
44
|
elsif brk == :forkbreak_end
|
data/lib/fork_break/version.rb
CHANGED
data/spec/fork_break_spec.rb
CHANGED
@@ -59,7 +59,7 @@ describe ForkBreak::Process do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def counter_after_synced_execution(counter_path, with_lock)
|
62
|
+
def counter_after_synced_execution(counter_path, with_lock)
|
63
63
|
process1, process2 = 2.times.map do
|
64
64
|
ForkBreak::Process.new { FileCounter.open(counter_path, with_lock).increase }
|
65
65
|
end
|
@@ -86,6 +86,21 @@ describe ForkBreak::Process do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
it 'ignores breakpoints when running outside a ForkBreak process' do
|
90
|
+
class Foo
|
91
|
+
include ForkBreak::Breakpoints
|
92
|
+
|
93
|
+
def bar
|
94
|
+
breakpoints << :test
|
95
|
+
'baz'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
expect(Foo.new.breakpoints).to be_kind_of(ForkBreak::NullBreakpointSetter)
|
100
|
+
expect { Foo.new.bar }.to_not raise_error
|
101
|
+
expect(Foo.new.bar).to eq('baz')
|
102
|
+
end
|
103
|
+
|
89
104
|
it 'raises the process exception' do
|
90
105
|
class MyException < StandardError; end
|
91
106
|
|
@@ -103,4 +118,18 @@ describe ForkBreak::Process do
|
|
103
118
|
|
104
119
|
expect { process.finish.wait(timeout: 0.01) }.to raise_error(ForkBreak::WaitTimeout)
|
105
120
|
end
|
121
|
+
|
122
|
+
it 'keeps the return value of the process' do
|
123
|
+
class Foo
|
124
|
+
include ForkBreak::Breakpoints
|
125
|
+
|
126
|
+
def bar
|
127
|
+
'baz'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
process = ForkBreak::Process.new { Foo.new.bar }.finish.wait
|
132
|
+
|
133
|
+
expect(process.return_value).to eq('baz')
|
134
|
+
end
|
106
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fork_break
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petter Remen
|
8
|
+
- Pedro Carriço
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-06
|
12
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: fork
|
@@ -65,8 +66,7 @@ dependencies:
|
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: 0.27.1
|
67
68
|
description: Fork with breakpoints for syncing child process execution
|
68
|
-
email:
|
69
|
-
- petter.remen@gmail.com
|
69
|
+
email:
|
70
70
|
executables: []
|
71
71
|
extensions: []
|
72
72
|
extra_rdoc_files: []
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- ".gitignore"
|
75
75
|
- ".rspec"
|
76
76
|
- ".rubocop.yml"
|
77
|
+
- ".travis.yml"
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE
|
79
80
|
- README.md
|
@@ -82,11 +83,12 @@ files:
|
|
82
83
|
- lib/fork_break.rb
|
83
84
|
- lib/fork_break/breakpoint_setter.rb
|
84
85
|
- lib/fork_break/breakpoints.rb
|
86
|
+
- lib/fork_break/null_breakpoint_setter.rb
|
85
87
|
- lib/fork_break/process.rb
|
86
88
|
- lib/fork_break/version.rb
|
87
89
|
- spec/fork_break_spec.rb
|
88
90
|
- spec/spec_helper.rb
|
89
|
-
homepage: http://github.com/
|
91
|
+
homepage: http://github.com/forkbreak/fork_break
|
90
92
|
licenses:
|
91
93
|
- MIT
|
92
94
|
metadata: {}
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
requirements: []
|
108
110
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.5.1
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Testing multiprocess behaviour is difficult and requires a way to synchronize
|