ruby_process 0.0.9 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/README.md +98 -0
- data/Rakefile +2 -2
- data/RubyProcess.gemspec +88 -0
- data/VERSION +1 -1
- data/cmds/blocks.rb +18 -18
- data/cmds/marshal.rb +2 -2
- data/cmds/new.rb +13 -13
- data/cmds/numeric.rb +4 -4
- data/cmds/static.rb +10 -10
- data/cmds/str_eval.rb +4 -4
- data/cmds/system.rb +11 -11
- data/examples/example_csv.rb +13 -0
- data/examples/example_file_write.rb +2 -2
- data/examples/example_knj_db_dump.rb +7 -7
- data/examples/example_strscan.rb +3 -3
- data/include/args_handeling.rb +21 -21
- data/lib/ruby_process.rb +111 -105
- data/lib/{ruby_process_cproxy.rb → ruby_process/class_proxy.rb} +35 -35
- data/lib/{ruby_process_proxyobj.rb → ruby_process/proxy_object.rb} +18 -18
- data/ruby_process.gemspec +17 -10
- data/scripts/ruby_process_script.rb +7 -7
- data/shippable.yml +7 -0
- data/spec/class_proxy_spec.rb +95 -0
- data/spec/hard_load_spec.rb +13 -17
- data/spec/leaks_spec.rb +7 -7
- data/spec/ruby_process_spec.rb +75 -77
- data/spec/spec_helper.rb +3 -1
- metadata +60 -60
- data/README.rdoc +0 -19
- data/spec/cproxy_spec.rb +0 -101
data/spec/leaks_spec.rb
CHANGED
@@ -3,22 +3,22 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "RubyProcess" do
|
4
4
|
it "should be able to clean up after itself when timeout" do
|
5
5
|
require "timeout"
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
RubyProcess::ClassProxy.run do |data|
|
8
8
|
sp = data[:subproc]
|
9
|
-
|
9
|
+
|
10
10
|
begin
|
11
11
|
Timeout.timeout(1) do
|
12
12
|
sp.static(:Object, :sleep, 2)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
raise "Expected timeout to be raised."
|
16
16
|
rescue Timeout::Error
|
17
17
|
#ignore.
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
answers = sp.instance_variable_get(:@answers)
|
21
|
-
|
21
|
+
answers.should be_empty
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
data/spec/ruby_process_spec.rb
CHANGED
@@ -1,73 +1,70 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "RubyProcess" do
|
4
|
+
let(:rp) { RubyProcess.new(debug: false).spawn_process }
|
5
|
+
|
6
|
+
after do
|
7
|
+
rp.destroy unless rp.destroyed?
|
8
|
+
end
|
9
|
+
|
4
10
|
it "should be able to do basic stuff" do
|
5
|
-
|
6
|
-
$rp.spawn_process
|
7
|
-
|
8
|
-
proxyarr = $rp.new(:Array)
|
11
|
+
proxyarr = rp.new(:Array)
|
9
12
|
proxyarr << 1
|
10
13
|
proxyarr << 3
|
11
14
|
proxyarr << 5
|
12
|
-
|
13
|
-
|
14
|
-
raise "Not an array." if !arr.is_a?(Array)
|
15
|
-
raise "Expected three elements." if arr.length != 3
|
16
|
-
raise "Expected 1" if arr[0] != 1
|
17
|
-
raise "Expected 3" if arr[1] != 3
|
18
|
-
raise "Expected 5" if arr[2] != 5
|
15
|
+
|
16
|
+
proxyarr.__rp_marshal.should eq [1, 3, 5]
|
19
17
|
end
|
20
|
-
|
18
|
+
|
21
19
|
it "should be able to pass proxy-objects as arguments." do
|
22
|
-
str =
|
20
|
+
str = rp.new(:String, "/tmp/somefile")
|
23
21
|
thread_id = Thread.current.__id__
|
24
22
|
write_called = false
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
|
24
|
+
rp.static(:File, :open, str, "w") do |fp|
|
25
|
+
thread_id.should eq Thread.current.__id__
|
28
26
|
fp.write("Test!")
|
29
27
|
write_called = true
|
30
28
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
raise "Unexpected content of file: '#{read}'." if read != "Test!"
|
29
|
+
|
30
|
+
write_called.should eq true
|
31
|
+
File.read(str.__rp_marshal).should eq "Test!"
|
35
32
|
end
|
36
|
-
|
33
|
+
|
37
34
|
it "should be able to write files" do
|
38
35
|
fpath = "/tmp/ruby_process_file_write_test"
|
39
|
-
fp =
|
36
|
+
fp = rp.static(:File, :open, fpath, "w")
|
40
37
|
fp.write("Test!")
|
41
38
|
fp.close
|
42
|
-
|
43
|
-
|
39
|
+
|
40
|
+
File.read(fpath).should eq "Test!"
|
44
41
|
end
|
45
|
-
|
42
|
+
|
46
43
|
it "should do garbage collection" do
|
47
44
|
GC.start
|
48
45
|
end
|
49
|
-
|
46
|
+
|
50
47
|
it "should be able to do static calls" do
|
51
|
-
pid =
|
52
|
-
|
53
|
-
raise "
|
48
|
+
pid = rp.static(:Process, :pid).__rp_marshal
|
49
|
+
rp.finalize_count.should be <= 0 unless RUBY_ENGINE == "jruby"
|
50
|
+
raise "Not a number" if !pid.is_a?(Fixnum) && !pid.is_a?(Integer)
|
54
51
|
end
|
55
|
-
|
52
|
+
|
56
53
|
it "should be able to handle blocking blocks" do
|
57
54
|
run_count = 0
|
58
55
|
fpath = "/tmp/ruby_process_file_write_test"
|
59
|
-
|
56
|
+
rp.static(:File, :open, fpath, "w") do |fp|
|
60
57
|
sleep 0.1
|
61
58
|
run_count += 1
|
62
59
|
fp.write("Test!!!")
|
63
60
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
|
62
|
+
run_count.should > 0
|
63
|
+
File.read(fpath).should eq "Test!!!"
|
67
64
|
end
|
68
|
-
|
65
|
+
|
69
66
|
it "should be able to do slow block-results in JRuby." do
|
70
|
-
|
67
|
+
rp.str_eval("
|
71
68
|
class ::Kaspertest
|
72
69
|
def self.kaspertest
|
73
70
|
8.upto(12) do |i|
|
@@ -76,51 +73,51 @@ describe "RubyProcess" do
|
|
76
73
|
end
|
77
74
|
end
|
78
75
|
end
|
79
|
-
|
76
|
+
|
80
77
|
nil
|
81
78
|
")
|
82
|
-
|
79
|
+
|
83
80
|
require "timeout"
|
84
81
|
Timeout.timeout(10) do
|
85
82
|
expect = 8
|
86
|
-
|
87
|
-
|
83
|
+
rp.static("Kaspertest", "kaspertest") do |count|
|
84
|
+
expect.should eq count.__rp_marshal
|
88
85
|
expect += 1
|
89
86
|
end
|
90
|
-
|
91
|
-
|
87
|
+
|
88
|
+
expect.should eq 13
|
92
89
|
end
|
93
90
|
end
|
94
|
-
|
91
|
+
|
95
92
|
it "should be able to handle large block-runs" do
|
96
93
|
#Try to define an integer and run upto with a block.
|
97
|
-
proxy_int =
|
98
|
-
|
94
|
+
proxy_int = rp.numeric(5)
|
95
|
+
|
99
96
|
expect = 5
|
100
97
|
proxy_int.upto(250) do |i|
|
101
|
-
|
98
|
+
i.__rp_marshal.should eq expect
|
102
99
|
expect += 1
|
103
100
|
end
|
104
|
-
|
101
|
+
|
105
102
|
#Ensure the expected has actually been increased by running the block.
|
106
|
-
|
103
|
+
expect.should eq 251
|
107
104
|
end
|
108
|
-
|
105
|
+
|
109
106
|
it "should handle stressed operations" do
|
110
107
|
#Spawn a test-object - a string - with a variable-name.
|
111
|
-
proxy_obj =
|
112
|
-
|
113
|
-
|
108
|
+
proxy_obj = rp.new(:String, "Kasper")
|
109
|
+
proxy_obj.__rp_marshal.should eq "Kasper"
|
110
|
+
|
114
111
|
#Stress it a little by doing 500 calls.
|
115
112
|
0.upto(500) do
|
116
113
|
res = proxy_obj.slice(0, 3).__rp_marshal
|
117
|
-
|
114
|
+
res.should eq "Kas"
|
118
115
|
end
|
119
116
|
end
|
120
|
-
|
117
|
+
|
121
118
|
it "should be thread-safe" do
|
122
119
|
#Do a lot of calls at the same time to test thread-safety.
|
123
|
-
proxy_obj =
|
120
|
+
proxy_obj = rp.new(:String, "Kasper")
|
124
121
|
threads = []
|
125
122
|
0.upto(5) do |thread_i|
|
126
123
|
should_return = "Kasper".slice(0, thread_i)
|
@@ -128,49 +125,50 @@ describe "RubyProcess" do
|
|
128
125
|
begin
|
129
126
|
0.upto(250) do |num_i|
|
130
127
|
res = proxy_obj.slice(0, thread_i).__rp_marshal
|
131
|
-
|
128
|
+
res.should eq should_return
|
132
129
|
end
|
133
130
|
rescue => e
|
134
131
|
Thread.current[:error] = e
|
135
132
|
end
|
136
133
|
end
|
137
|
-
|
134
|
+
|
138
135
|
threads << thread
|
139
136
|
end
|
140
|
-
|
137
|
+
|
141
138
|
threads.each do |thread|
|
142
139
|
thread.join
|
143
140
|
raise thread[:error] if thread[:error]
|
144
141
|
end
|
145
142
|
end
|
146
|
-
|
143
|
+
|
147
144
|
it "should be able to do evals" do
|
148
|
-
res =
|
149
|
-
|
145
|
+
res = rp.str_eval("return 10").__rp_marshal
|
146
|
+
res.should eq 10
|
150
147
|
end
|
151
|
-
|
148
|
+
|
152
149
|
it "should clean itself" do
|
153
|
-
|
150
|
+
rp.garbage_collect
|
154
151
|
GC.start
|
155
|
-
|
152
|
+
rp.flush_finalized
|
156
153
|
GC.start
|
157
|
-
|
154
|
+
rp.flush_finalized
|
158
155
|
end
|
159
|
-
|
156
|
+
|
160
157
|
it "should be clean and not leaking" do
|
161
158
|
GC.start
|
162
|
-
|
159
|
+
rp.flush_finalized
|
163
160
|
GC.start
|
164
|
-
|
165
|
-
|
166
|
-
answers =
|
167
|
-
|
168
|
-
|
169
|
-
objects =
|
170
|
-
|
161
|
+
rp.flush_finalized
|
162
|
+
|
163
|
+
answers = rp.instance_variable_get(:@answers)
|
164
|
+
answers.should be_empty
|
165
|
+
|
166
|
+
objects = rp.instance_variable_get(:@objects)
|
167
|
+
objects.should be_empty
|
171
168
|
end
|
172
|
-
|
169
|
+
|
173
170
|
it "should be able to destroy itself" do
|
174
|
-
|
171
|
+
rp.destroy
|
172
|
+
rp.destroyed?.should eq true
|
175
173
|
end
|
176
174
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
1
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
6
|
require 'rspec'
|
@@ -8,5 +11,4 @@ require 'ruby_process'
|
|
8
11
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
12
|
|
10
13
|
RSpec.configure do |config|
|
11
|
-
|
12
14
|
end
|
metadata
CHANGED
@@ -1,110 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.9
|
4
|
+
version: 0.0.13
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kasper Johansen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
|
14
|
+
name: wref
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '0'
|
21
|
-
name: wref
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
25
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
32
|
-
|
28
|
+
name: tsafe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
33
30
|
requirements:
|
34
|
-
- -
|
31
|
+
- - ">="
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '0'
|
37
|
-
name: tsafe
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
none: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
42
|
+
name: string-cases
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
47
50
|
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
51
|
requirements:
|
50
|
-
- -
|
52
|
+
- - ">="
|
51
53
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
53
56
|
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
|
-
|
57
|
-
none: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
65
|
requirements:
|
59
|
-
- - ~>
|
66
|
+
- - "~>"
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: 2.8.0
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
|
-
|
64
|
-
|
70
|
+
name: rdoc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
65
72
|
requirements:
|
66
|
-
- - ~>
|
73
|
+
- - "~>"
|
67
74
|
- !ruby/object:Gem::Version
|
68
75
|
version: '3.12'
|
69
|
-
name: rdoc
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
|
-
|
73
|
-
none: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
79
|
requirements:
|
75
|
-
- - ~>
|
80
|
+
- - "~>"
|
76
81
|
- !ruby/object:Gem::Version
|
77
82
|
version: '3.12'
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
|
-
|
80
|
-
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
81
86
|
requirements:
|
82
|
-
- -
|
87
|
+
- - ">="
|
83
88
|
- !ruby/object:Gem::Version
|
84
89
|
version: 1.0.0
|
85
|
-
name: bundler
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
|
-
|
89
|
-
none: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
93
|
requirements:
|
91
|
-
- -
|
94
|
+
- - ">="
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: 1.0.0
|
94
97
|
- !ruby/object:Gem::Dependency
|
95
|
-
|
96
|
-
|
98
|
+
name: jeweler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
97
100
|
requirements:
|
98
|
-
- - ~>
|
101
|
+
- - "~>"
|
99
102
|
- !ruby/object:Gem::Version
|
100
103
|
version: 1.8.3
|
101
|
-
name: jeweler
|
102
104
|
type: :development
|
103
105
|
prerelease: false
|
104
|
-
|
105
|
-
none: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
107
|
requirements:
|
107
|
-
- - ~>
|
108
|
+
- - "~>"
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: 1.8.3
|
110
111
|
description: A framework for spawning and communicating with other Ruby-processes
|
@@ -113,14 +114,15 @@ executables: []
|
|
113
114
|
extensions: []
|
114
115
|
extra_rdoc_files:
|
115
116
|
- LICENSE.txt
|
116
|
-
- README.
|
117
|
+
- README.md
|
117
118
|
files:
|
118
|
-
- .document
|
119
|
-
- .rspec
|
119
|
+
- ".document"
|
120
|
+
- ".rspec"
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE.txt
|
122
|
-
- README.
|
123
|
+
- README.md
|
123
124
|
- Rakefile
|
125
|
+
- RubyProcess.gemspec
|
124
126
|
- VERSION
|
125
127
|
- cmds/blocks.rb
|
126
128
|
- cmds/marshal.rb
|
@@ -129,16 +131,18 @@ files:
|
|
129
131
|
- cmds/static.rb
|
130
132
|
- cmds/str_eval.rb
|
131
133
|
- cmds/system.rb
|
134
|
+
- examples/example_csv.rb
|
132
135
|
- examples/example_file_write.rb
|
133
136
|
- examples/example_knj_db_dump.rb
|
134
137
|
- examples/example_strscan.rb
|
135
138
|
- include/args_handeling.rb
|
136
139
|
- lib/ruby_process.rb
|
137
|
-
- lib/
|
138
|
-
- lib/
|
140
|
+
- lib/ruby_process/class_proxy.rb
|
141
|
+
- lib/ruby_process/proxy_object.rb
|
139
142
|
- ruby_process.gemspec
|
140
143
|
- scripts/ruby_process_script.rb
|
141
|
-
-
|
144
|
+
- shippable.yml
|
145
|
+
- spec/class_proxy_spec.rb
|
142
146
|
- spec/hard_load_spec.rb
|
143
147
|
- spec/leaks_spec.rb
|
144
148
|
- spec/ruby_process_spec.rb
|
@@ -146,29 +150,25 @@ files:
|
|
146
150
|
homepage: http://github.com/kaspernj/ruby_process
|
147
151
|
licenses:
|
148
152
|
- MIT
|
153
|
+
metadata: {}
|
149
154
|
post_install_message:
|
150
155
|
rdoc_options: []
|
151
156
|
require_paths:
|
152
157
|
- lib
|
153
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
159
|
requirements:
|
156
|
-
- -
|
160
|
+
- - ">="
|
157
161
|
- !ruby/object:Gem::Version
|
158
|
-
segments:
|
159
|
-
- 0
|
160
|
-
hash: -790821121563732357
|
161
162
|
version: '0'
|
162
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
164
|
requirements:
|
165
|
-
- -
|
165
|
+
- - ">="
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project:
|
170
|
-
rubygems_version:
|
170
|
+
rubygems_version: 2.4.0
|
171
171
|
signing_key:
|
172
|
-
specification_version:
|
172
|
+
specification_version: 4
|
173
173
|
summary: A framework for spawning and communicating with other Ruby-processes
|
174
174
|
test_files: []
|