Skip to content

Instantly share code, notes, and snippets.

@raggi
Created December 2, 2009 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raggi/247405 to your computer and use it in GitHub Desktop.
Save raggi/247405 to your computer and use it in GitHub Desktop.
ruby sync io bug on fbsd + osx, 1.8
# This bug seems to occur on 1.8.6..1.9 on OSX and FreeBSD. It's known not to occur on Linux.
require 'rubygems'
require 'minitest/unit'
include MiniTest::Assertions
require 'tempfile'
path = nil
begin
Tempfile.open('testing.sync.pos') do |f| # Has been tested without tempfile.
path = f.path
end
open(path, 'a+') do |f| # Has been tested with w+, etc.
assert_equal 0, f.pos
f.write('a')
assert_equal 1, f.pos
f.write('b')
assert_equal 2, f.pos
f.sync = true
assert_equal 2, f.pos
f.write('c')
assert_equal 3, f.pos # Bug returns 2 here
end
ensure
File.delete(path) if File.exists?(path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment