Merge branch '20-fix-encoding-failures' into 'master'
Use a BINARY encoded string when doing read/write comparisons. This is a bit of a cheat really, but `#read` returns an ASCII encoded string, where as our ruby generates UTF-8 encoded strings, causing assertion failures. Closes #20 See merge request !8
This commit is contained in:
@@ -3,6 +3,10 @@ require 'flexnbd/fake_source'
|
||||
require 'flexnbd/fake_dest'
|
||||
|
||||
module ProxyTests
|
||||
def b
|
||||
String.new("\xFF", encoding: "BINARY")
|
||||
end
|
||||
|
||||
def with_proxied_client( override_size = nil )
|
||||
@env.serve1 unless @server_up
|
||||
@env.proxy2 unless @proxy_up
|
||||
@@ -51,7 +55,7 @@ module ProxyTests
|
||||
with_proxied_client do |client|
|
||||
(0..3).each do |n|
|
||||
offset = n * 4096
|
||||
client.write(offset, "\xFF" * 4096)
|
||||
client.write(offset, b * 4096)
|
||||
rsp = client.read_response
|
||||
|
||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||
@@ -60,7 +64,7 @@ module ProxyTests
|
||||
|
||||
data = @env.file1.read(offset, 4096)
|
||||
|
||||
assert_equal( ( "\xFF" * 4096 ), data, "Data not written correctly (offset is #{n})" )
|
||||
assert_equal( ( b * 4096 ), data, "Data not written correctly (offset is #{n})" )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -107,7 +111,7 @@ module ProxyTests
|
||||
|
||||
# The reply should be proxied back to the client.
|
||||
sc2.write_reply( req2[:handle] )
|
||||
sc2.write_data( "\xFF" * 4096 )
|
||||
sc2.write_data( b * 4096 )
|
||||
|
||||
# Check it to make sure it's correct
|
||||
rsp = timeout(15) { client.read_response }
|
||||
@@ -116,7 +120,7 @@ module ProxyTests
|
||||
assert_equal req1[:handle], rsp[:handle]
|
||||
|
||||
data = client.read_raw( 4096 )
|
||||
assert_equal( ("\xFF" * 4096), data, "Wrong data returned" )
|
||||
assert_equal( (b * 4096), data, "Wrong data returned" )
|
||||
|
||||
sc2.close
|
||||
server.close
|
||||
@@ -131,7 +135,7 @@ module ProxyTests
|
||||
server, sc1 = maker.value
|
||||
|
||||
# Send the read request to the proxy
|
||||
client.write( 0, ( "\xFF" * 4096 ) )
|
||||
client.write( 0, ( b * 4096 ) )
|
||||
|
||||
# ensure we're given the read request
|
||||
req1 = sc1.read_request
|
||||
@@ -140,7 +144,7 @@ module ProxyTests
|
||||
assert_equal 0, req1[:from]
|
||||
assert_equal 4096, req1[:len]
|
||||
data1 = sc1.read_data( 4096 )
|
||||
assert_equal( ( "\xFF" * 4096 ), data1, "Data not proxied successfully" )
|
||||
assert_equal( ( b * 4096 ), data1, "Data not proxied successfully" )
|
||||
|
||||
# Kill the server again, now we're sure the read request has been sent once
|
||||
sc1.close
|
||||
|
@@ -6,6 +6,7 @@ class TestServeMode < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
@b = String.new("\xFF", encoding: "BINARY")
|
||||
@env = Environment.new
|
||||
@env.writefile1( "0" )
|
||||
@env.serve1
|
||||
@@ -53,18 +54,18 @@ class TestServeMode < Test::Unit::TestCase
|
||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||
assert_equal 0, rsp[:error]
|
||||
|
||||
client.write( 0, "\xFF" )
|
||||
client.write( 0, @b )
|
||||
rsp = client.read_response
|
||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||
assert_equal 0, rsp[:error]
|
||||
|
||||
client.write( 0, "\xFF\xFF" )
|
||||
client.write( 0, @b * 2 )
|
||||
rsp = client.read_response
|
||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||
assert_equal 0, rsp[:error]
|
||||
end
|
||||
|
||||
assert_equal "\xFF\xFF", @env.file1.read( 0, 2 )
|
||||
assert_equal @b * 2, @env.file1.read( 0, 2 )
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user