Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix stupid taskset bug where nuls weren't preseved in returned data b…

…ecause

i wasn't limiting the number of splits that i was doing on the response
packet; add test for this


git-svn-id: http://code.sixapart.com/svn/gearman/trunk/api/ruby@283 011c6a6d-750f-0410-a5f6-93fdcd050bc4
  • Loading branch information...
commit f993321cbaea0c63eab985ae5dd9ea1d05e007c9 1 parent 7a49565
derat authored
View
5 examples/scale_image.rb
@@ -1,7 +1,6 @@
#!/usr/bin/ruby
$: << '../lib'
-require 'base64'
require 'gearman'
require 'optparse'
@@ -26,8 +25,8 @@
client = Gearman::Client.new(servers.split(','), 'example')
taskset = Gearman::TaskSet.new(client)
-arg = [width, height, format, Base64.encode64(File.read(ARGV[0]))].join("\0")
+arg = [width, height, format, File.read(ARGV[0])].join("\0")
task = Gearman::Task.new('scale_image', arg)
-task.on_complete {|d| File.new(ARGV[1],'w').write(Base64.decode64(d)) }
+task.on_complete {|d| File.new(ARGV[1],'w').write(d) }
taskset.add_task(task)
taskset.wait(10)
View
9 examples/scale_image_worker.rb
@@ -1,7 +1,6 @@
#!/usr/bin/ruby
$: << '../lib'
-require 'base64'
require 'gearman'
require 'optparse'
require 'RMagick'
@@ -11,8 +10,8 @@
opts = OptionParser.new
opts.banner = "Usage: #{$0} [options]"
-opts.on('-s SERVERS', '--servers', 'Job servers,
- comma-separated host:port') { servers }
+opts.on('-s SERVERS', '--servers',
+ 'Job servers, comma-separated host:port') { servers }
opts.parse!
worker = Gearman::Worker.new(servers.split(','), 'example')
@@ -21,7 +20,7 @@
width, height, format, data = data.split("\0", 4)
width = width.to_f
height = height.to_f
- image = Magick::Image.from_blob(Base64.decode64(data))[0]
+ image = Magick::Image.from_blob(data)[0]
orig_ratio = image.columns.to_f / image.rows
new_ratio = width / height
w = new_ratio < orig_ratio ? width : orig_ratio / new_ratio * width
@@ -29,7 +28,7 @@
puts "Got #{image.inspect}; resizing to #{w}x#{h} #{format}"
image.resize!(w, h)
image.format = format
- Base64.encode64(image.to_blob)
+ image.to_blob
end
loop { worker.work }
View
4 lib/gearman/taskset.rb
@@ -67,7 +67,7 @@ def handle_job_created(hostport, data)
# @param hostport "host:port" of job server
# @param data data returned in packet from server
def handle_work_complete(hostport, data)
- handle, data = data.split("\0")
+ handle, data = data.split("\0", 2)
Util.log "Got work_complete with handle #{handle} and " +
"#{data ? data.size : '0'} byte(s) of data from #{hostport}"
js_handle = Util.handle_to_str(hostport, handle)
@@ -113,7 +113,7 @@ def handle_work_fail(hostport, data)
# @param hostport "host:port" of job server
# @param data data returned in packet from server
def handle_work_status(hostport, data)
- handle, num, den = data.split("\0")
+ handle, num, den = data.split("\0", 3)
Util.log "Got work_status with handle #{handle} from #{hostport}: " +
"#{num}/#{den}"
js_handle = Util.handle_to_str(hostport, handle)
View
27 test/mock_client.rb
@@ -353,4 +353,31 @@ def test_uniq_dash
assert_equal(1, res2)
assert_equal(2, res3)
end
+
+ ##
+ # Test that NUL bytes in returned data are preserved.
+ def test_nuls_in_data
+ server = FakeJobServer.new(self)
+ client, sock, res = nil
+
+ s = TestScript.new
+ c = TestScript.new
+
+ server_thread = Thread.new { s.loop_forever }.run
+ client_thread = Thread.new { c.loop_forever }.run
+
+ c.exec { client = Gearman::Client.new("localhost:#{server.port}") }
+
+ c.exec { res = client.do_task('foo', nil) }
+ s.exec { sock = server.expect_connection }
+ s.wait
+
+ s.exec { server.expect_request(sock, :submit_job, "foo\000\000") }
+ s.exec { server.send_response(sock, :job_created, 'a') }
+ s.exec { server.send_response(sock, :work_complete, "a\0001\0002\0003") }
+ c.wait
+ s.wait
+
+ assert_equal("1\0002\0003", res)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.