Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Windows fixes #237

Merged
merged 12 commits into from

2 participants

@arthurschreiber
Collaborator

This is a collection of issues that I found while runnning the rugged testsuite on windows.

I really don't like having to trigger GC.start, and I'd propose that we move to a resource management model more inline with how File and other IO work, but I'll open a separate PR for that.

@brianmario
Owner

:+1: just had to start doing this in mysql2 to make sure idle connections weren't sitting around any longer than they needed to.

@arthurschreiber
Collaborator

@brianmario care to elaborate?

@brianmario
Owner

So as of 0.3.12 and 0.2.19 we started doing our own ref-counting on Mysql2::Client instances to make sure it wouldn't be freed until all of the Mysql2::Result objects generated from it had been freed. This was due to a limitation in libmysql.

As a result, the Client objects were hanging around a lot longer in the tests and we're creating all kinds of connections to test various connection options and stuff. So I had to go back through the test suite and make sure we closed every connection we opened as soon as it wasn't needed.

@arthurschreiber arthurschreiber referenced this pull request
Merged

Add Rugged cross compilation support #241

2 of 2 tasks complete
@arthurschreiber
Collaborator
C:\rugged>rake
git submodule update --init
install -c tmp/i386-mingw32/rugged/2.0.0/rugged.so lib/rugged/rugged.so
Run options: --seed 36787

# Running tests:

................................................................................
................................................................................
................................................................................
.........................................

Finished tests in 19.428343s, 14.4634 tests/s, 44.7799 assertions/s.

281 tests, 870 assertions, 0 failures, 0 errors, 0 skips

Depends on libgit2/libgit2#1748 to be merged, then I'll pull this in, I think.

@arthurschreiber arthurschreiber merged commit 098ddbc into from
@arthurschreiber arthurschreiber deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  .gitattributes
@@ -0,0 +1,2 @@
+test/fixtures/*.git/packed-refs text eol=lf
+test/fixtures/*.git/logs/**/* text eol=lf
View
2  Rakefile
@@ -43,7 +43,7 @@ task :cover do
end
Rake::TestTask.new do |t|
- t.libs << 'lib:test'
+ t.libs << 'lib' << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
t.warning = true
View
48 test/blob_test.rb
@@ -78,7 +78,7 @@ def test_blob_text_with_negative_lines
def test_blob_text_default_encoding
oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
blob = @repo.lookup(oid)
- assert_equal Encoding::UTF_8, blob.text.encoding
+ assert_equal Encoding.default_external, blob.text.encoding
end
def test_blob_text_set_encoding
@@ -137,14 +137,22 @@ def test_blob_is_binary
end
class BlobDiffTest < Rugged::SandboxedTestCase
- def test_diff_blob
- repo = sandbox_init("diff")
+ def setup
+ super
+ @repo = sandbox_init("diff")
+ end
+
+ def teardown
+ @repo.close
+ super
+ end
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
+ def test_diff_blob
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
+ b = @repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
- blob = repo.lookup(a.tree["readme.txt"][:oid])
- other = repo.lookup(b.tree["readme.txt"][:oid])
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
+ other = @repo.lookup(b.tree["readme.txt"][:oid])
patch = blob.diff(other)
@@ -184,13 +192,11 @@ def test_diff_blob
end
def test_diff_string
- repo = sandbox_init("diff")
-
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
+ b = @repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
- blob = repo.lookup(a.tree["readme.txt"][:oid])
- other = repo.lookup(b.tree["readme.txt"][:oid]).content
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
+ other = @repo.lookup(b.tree["readme.txt"][:oid]).content
patch = blob.diff(other)
@@ -230,11 +236,9 @@ def test_diff_string
end
def test_diff_nil
- repo = sandbox_init("diff")
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
-
- blob = repo.lookup(a.tree["readme.txt"][:oid])
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
patch = blob.diff(nil)
@@ -261,13 +265,11 @@ def test_diff_nil
end
def test_diff_with_paths
- repo = sandbox_init("diff")
-
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
+ b = @repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
- blob = repo.lookup(a.tree["readme.txt"][:oid])
- other = repo.lookup(b.tree["readme.txt"][:oid])
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
+ other = @repo.lookup(b.tree["readme.txt"][:oid])
patch = blob.diff(other, :old_path => "old_readme.txt", :new_path => "new_readme.txt")
assert_equal "old_readme.txt", patch.delta.old_file[:path]
View
28 test/index_test.rb
@@ -118,13 +118,16 @@ def test_add_new_entries
class IndexWriteTest < Rugged::TestCase
def setup
path = File.dirname(__FILE__) + '/fixtures/testrepo.git/index'
- @tmppath = Tempfile.new('index').path
- FileUtils.copy(path, @tmppath)
- @index = Rugged::Index.new(@tmppath)
+
+ @tmpfile = Tempfile.new('index', Dir.tmpdir, encoding: "binary")
+ @tmpfile.write(File.binread(path))
+ @tmpfile.close
+
+ @index = Rugged::Index.new(@tmpfile.path)
end
def teardown
- File.delete(@tmppath)
+ @tmpfile.unlink
end
def test_raises_when_writing_invalid_entries
@@ -142,7 +145,7 @@ def test_can_write_index
@index.write
- index2 = Rugged::Index.new(@tmppath)
+ index2 = Rugged::Index.new(@tmpfile.path)
itr_test = index2.sort { |a, b| a[:oid] <=> b[:oid] }.map { |x| x[:path] }.join(':')
assert_equal "README:else.txt:new_path:new.txt", itr_test
@@ -157,7 +160,8 @@ def setup
@index = @repo.index
end
- def teardown
+ def teardown
+ @repo.close
FileUtils.remove_entry_secure(@tmppath)
end
@@ -202,6 +206,12 @@ def setup
@repo = sandbox_init("mergedrepo")
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_conflicts
assert @repo.index.conflicts?
end
@@ -251,6 +261,12 @@ def setup
end
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_add_all_lifecycle
Dir.chdir(@repo.workdir) do
@repo.index.add_all("file.*")
View
10 test/remote_test.rb
@@ -164,6 +164,13 @@ def setup
@remote = Rugged::Remote.lookup(@repo, 'origin')
end
+ def teardown
+ @repo.close
+ @remote_repo.close
+
+ super
+ end
+
def test_push_single_ref
result = @remote.push(["refs/heads/master", "refs/heads/master:refs/heads/foobar", "refs/heads/unit_test"])
assert_equal({}, result)
@@ -255,10 +262,11 @@ def setup
@path = Dir.mktmpdir 'dir'
@repo = Rugged::Repository.init_at(@path, false)
repo_dir = File.join(TEST_DIR, (File.join('fixtures', 'testrepo.git', '.')))
- @remote = Rugged::Remote.add(@repo, 'origin', "file://#{repo_dir}")
+ @remote = Rugged::Remote.add(@repo, 'origin', repo_dir)
end
def teardown
+ @repo.close
FileUtils.remove_entry_secure(@path)
end
View
76 test/repo_test.rb
@@ -8,6 +8,12 @@ def setup
@repo = sandbox_init "testrepo.git"
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_last_commit
assert @repo.respond_to? :last_commit
assert "36060c58702ed4c2a40832c51758d5344201d89a", @repo.last_commit.oid
@@ -19,7 +25,7 @@ def test_fails_to_open_unexisting_repos
end
assert_raises Rugged::RepositoryError do
- Rugged::Repository.new("/home/")
+ Rugged::Repository.new("test")
end
end
@@ -149,8 +155,12 @@ def test_enumerate_all_objects
def test_loading_alternates
alt_path = File.dirname(__FILE__) + '/fixtures/alternate/objects'
repo = Rugged::Repository.new(@repo.path, :alternates => [alt_path])
- assert_equal 40, repo.each_id.to_a.length
- assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
+ begin
+ assert_equal 40, repo.each_id.to_a.length
+ assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
+ ensure
+ repo.close
+ end
end
def test_alternates_with_invalid_path_type
@@ -243,22 +253,38 @@ def teardown
def test_init_bare_false
repo = Rugged::Repository.init_at(@tmppath, false)
- refute repo.bare?
+ begin
+ refute repo.bare?
+ ensure
+ repo.close
+ end
end
def test_init_bare_true
repo = Rugged::Repository.init_at(@tmppath, true)
- assert repo.bare?
+ begin
+ assert repo.bare?
+ ensure
+ repo.close
+ end
end
def test_init_bare_truthy
repo = Rugged::Repository.init_at(@tmppath, :bare)
- assert repo.bare?
+ begin
+ assert repo.bare?
+ ensure
+ repo.close
+ end
end
def test_init_non_bare_default
repo = Rugged::Repository.init_at(@tmppath)
- refute repo.bare?
+ begin
+ refute repo.bare?
+ ensure
+ repo.close
+ end
end
end
@@ -274,23 +300,32 @@ def teardown
def test_clone
repo = Rugged::Repository.clone_at(@source_path, @tmppath)
- assert_equal "hey", File.read(File.join(@tmppath, "README")).chomp
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.head.target
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/heads/master").target
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/remotes/origin/master").target
- assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/remotes/origin/packed").target
+ begin
+ assert_equal "hey", File.read(File.join(@tmppath, "README")).chomp
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.head.target
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/heads/master").target
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/remotes/origin/master").target
+ assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/remotes/origin/packed").target
+ ensure
+ repo.close
+ end
end
def test_clone_bare
repo = Rugged::Repository.clone_at(@source_path, @tmppath, :bare => true)
- assert repo.bare?
+ begin
+ assert repo.bare?
+ ensure
+ repo.close
+ end
end
def test_clone_with_progress
total_objects = indexed_objects = received_objects = received_bytes = nil
callsback = 0
- Rugged::Repository.clone_at(@source_path, @tmppath,
+ repo = Rugged::Repository.clone_at(@source_path, @tmppath,
:progress => lambda { |*args| callsback += 1 ; total_objects, indexed_objects, received_objects, received_bytes = args })
+ repo.close
assert_equal 22, callsback
assert_equal 19, total_objects
assert_equal 19, indexed_objects
@@ -326,6 +361,12 @@ def setup
@repo = sandbox_init("testrepo.git")
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_no_namespace
assert_nil @repo.namespace
end
@@ -363,6 +404,13 @@ def setup
"8496071c1b46c854b31185ea97743be6a8774479")
end
+ def teardown
+ @repo.close
+ @remote_repo.close
+
+ super
+ end
+
def test_push_single_ref
result = @repo.push("origin", ["refs/heads/master", "refs/heads/master:refs/heads/foobar", "refs/heads/unit_test"])
assert_equal({}, result)
View
2  test/test_helper.rb
@@ -74,6 +74,8 @@ def setup
end
def teardown
+ @repo.close
+ GC.start
destroy_temp_repo(@path)
end
Something went wrong with that request. Please try again.