Issue #6771 has been updated by Jeff McCune.

Status changed from In Topic Branch Pending Review to Merged - Pending Release
Target version changed from 2.7.x to 2.7.11

# Merged into 2.7.x #

As: 
<https://github.com/puppetlabs/puppet/commit/36c807c01b9d8e9d51bce9c72e27f3967081a117>

<pre>

commit 36c807c01b9d8e9d51bce9c72e27f3967081a117 (from 
b9353392eb9b94db80cf329daddfb5fb49f4a9ea)
Merge: b935339 e81de1e
Author: Jeff McCune <[email protected]>
Date:   Wed Jan 25 14:44:01 2012 -0800

    Merge branch 
'bug/2.7.x/6771-always-close-activerecord-connections-in-tests' into 2.7.x
    
    * bug/2.7.x/6771-always-close-activerecord-connections-in-tests:
      (#6771) Check for ActiveRecord::Base instead of Puppet.features.rails?
      (#6771) Stop other AR connection handling.
      (#6771) Stop stubbing some feature tests.
      (#6771) Disconnect any ActiveRecord connection after every test.
      Document why we disable GC during the test runs.

diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e0227be..d5beddb 100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -34,6 +34,9 @@ RSpec.configure do |config|
   config.mock_with :mocha
 
   config.before :each do
+    # Disabling garbage collection inside each test, and only running it at
+    # the end of each block, gives us an ~ 15 percent speedup, and more on
+    # some platforms *cough* windows *cough* that are a little slower.
     GC.disable
 
     # We need to preserve the current state of all our indirection cache and
@@ -102,6 +105,17 @@ RSpec.configure do |config|
     end
     $saved_indirection_state = nil
 
+    # Some tests can cause us to connect, in which case the lingering
+    # connection is a resource that can cause unexpected failure in later
+    # tests, as well as sharing state accidentally.
+    # We're testing if ActiveRecord::Base is defined because some test cases
+    # may stub Puppet.features.rails? which is how we should normally
+    # introspect for this functionality.
+    ActiveRecord::Base.remove_connection if defined?(ActiveRecord::Base)
+
+    # This will perform a GC between tests, but only if actually required.  We
+    # experimented with forcing a GC run, and that was less efficient than
+    # just letting it run all the time.
     GC.enable
   end
 end
diff --git a/spec/unit/indirector/facts/inventory_active_record_spec.rb 
b/spec/unit/indirector/facts/inventory_active_record_spec.rb
index 43dcc7c..b14262b 100755
--- a/spec/unit/indirector/facts/inventory_active_record_spec.rb
+++ b/spec/unit/indirector/facts/inventory_active_record_spec.rb
@@ -34,7 +34,6 @@ describe "Puppet::Node::Facts::InventoryActiveRecord", :if => 
(Puppet.features.r
 
   after :each do
     Puppet::Rails.teardown
-    ActiveRecord::Base.remove_connection
   end
 
   describe "#save" do
diff --git a/spec/unit/indirector/resource/active_record_spec.rb 
b/spec/unit/indirector/resource/active_record_spec.rb
index c923f79..4c00976 100755
--- a/spec/unit/indirector/resource/active_record_spec.rb
+++ b/spec/unit/indirector/resource/active_record_spec.rb
@@ -20,10 +20,6 @@ describe "Puppet::Resource::ActiveRecord", :if => 
(Puppet.features.rails? and de
     Puppet[:storeconfigs] = true
   end
 
-  after :each do
-    ActiveRecord::Base.remove_connection
-  end
-
   subject {
     require 'puppet/indirector/resource/active_record'
     Puppet::Resource.indirection.terminus(:active_record)
diff --git a/spec/unit/parser/collector_spec.rb 
b/spec/unit/parser/collector_spec.rb
index c651ab8..633254b 100755
--- a/spec/unit/parser/collector_spec.rb
+++ b/spec/unit/parser/collector_spec.rb
@@ -287,22 +287,16 @@ describe Puppet::Parser::Collector, "when collecting 
exported resources", :if =>
 
   context "with storeconfigs enabled" do
     before :each do
-      ActiveRecord::Base.remove_connection
-
       dir = Pathname(tmpdir('puppet-var'))
       Puppet[:vardir]       = dir.to_s
       Puppet[:dbadapter]    = 'sqlite3'
       Puppet[:dblocation]   = (dir + 'storeconfigs.sqlite').to_s
       Puppet[:storeconfigs] = true
       Puppet[:environment]  = "production"
-      Puppet[:storeconfigs_backend] = :active_record
+      Puppet[:storeconfigs_backend] = "active_record"
       Puppet::Rails.init
     end
 
-    after :each do
-      ActiveRecord::Base.remove_connection
-    end
-
     it "should return all matching resources from the current compile and mark 
them non-virtual and non-exported" do
       one = Puppet::Parser::Resource.new('notify', 'one',
                                          :virtual  => true,
diff --git a/spec/unit/provider/confine/feature_spec.rb 
b/spec/unit/provider/confine/feature_spec.rb
index 959c7a3..04040dd 100755
--- a/spec/unit/provider/confine/feature_spec.rb
+++ b/spec/unit/provider/confine/feature_spec.rb
@@ -18,24 +18,22 @@ describe Puppet::Provider::Confine::Feature do
 
   describe "when testing values" do
     before do
-      @features = mock 'features'
-      Puppet.stubs(:features).returns @features
       @confine = Puppet::Provider::Confine::Feature.new("myfeature")
       @confine.label = "eh"
     end
 
     it "should use the Puppet features instance to test validity" do
-      @features.expects(:myfeature?)
+      Puppet.features.expects(:myfeature?)
       @confine.valid?
     end
 
     it "should return true if the feature is present" do
-      @features.expects(:myfeature?).returns true
+      Puppet.features.add(:myfeature) do true end
       @confine.pass?("myfeature").should be_true
     end
 
     it "should return false if the value is false" do
-      @features.expects(:myfeature?).returns false
+      Puppet.features.add(:myfeature) do false end
       @confine.pass?("myfeature").should be_false
     end
 
</pre>
----------------------------------------
Bug #6771: Mysterious ActiveRecord disk I/O Error
https://projects.puppetlabs.com/issues/6771

Author: Max Martin
Status: Merged - Pending Release
Priority: Normal
Assignee: 
Category: testing
Target version: 2.7.11
Affected Puppet version: 
Keywords: 
Branch: https://github.com/puppetlabs/puppet/pull/406


Some of us (but not others) have been getting a mysterious failure when running 
the spec tests:

    Failures:

    1) Puppet::Node::ActiveRecord should call fact_merge when a node is found
     Failure/Error: ar = Puppet::Node::ActiveRecord.new
     ActiveRecord::StatementInvalid:
       SQLite3::IOException: disk I/O error: CREATE TABLE "resources" ("id" 
INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" text NOT NULL, "restype" 
varchar(255) NOT NULL, "host_id" integer, "source_file_id" integer, "exported" 
boolean, "line" integer, "updated_at" datetime, "created_at" datetime) 
     # ./spec/../lib/puppet/rails/database/schema.rb:9:in `init'
     # ./spec/../lib/puppet/rails/database/schema.rb:8:in `init'
     # ./lib/puppet/util.rb:193:in `benchmark'
     # ./lib/puppet/util.rb:192:in `benchmark'
     # ./spec/../lib/puppet/rails/database/schema.rb:4:in `init'
     # ./spec/../lib/puppet/rails.rb:81:in `init'
     # ./spec/../lib/puppet/indirector/active_record.rb:17:in `initialize'
     # ./spec/unit/indirector/node/active_record_spec.rb:31:in `new'
     # ./spec/unit/indirector/node/active_record_spec.rb:31

Finished in 250.66 seconds
11249 examples, 1 failure, 45 pending

On my machine, it could be due to some weirdness with homebrew-installed SQLite.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to