RubyProcess 0.0.12

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