Frage

Ich führe Unit-Tests auf Rails 2.3 durch und erhalte beim Ausführen immer wieder Fehler in dieser Richtung rake test:units:

10) Error:
test_the_truth(BrokerTest):
ActiveRecord::StatementInvalid: Mysql::Error: Table 'shadow_test.users' doesn't exist: DELETE FROM `users`
    /Library/Ruby/Gems/1.8/gems/after_commit-1.0.10/lib/after_commit/connection_adapters.rb:14:in `transaction'

Ich bin gerannt rake db:test:load vorher, und es wurden die Tabellen erstellt.Wenn ich jedoch nachschaue mysql Nach dem Ausführen des Unit-Tests-Befehls fehlen die Tabellen tatsächlich.Etwas im Vorbereitungsprozess für die Unit-Tests führt dazu, dass die Tabellen verloren gehen.Hier ist das Debug-Protokoll vom Ausführen des Tests:

WARNING: 'task :t, arg, :needs => [deps]' is deprecated.  Please use 'task :t, [args] => [deps]' instead.
    at /Users/me/sources/shadow/lib/tasks/turk.rake:53
** Invoke test:units (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment 
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment 
** Execute db:schema:load
** Execute test:units
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" -I"/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib" "/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/unit/**/*_test.rb" 
/Library/Ruby/Gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:211: warning: Insecure world writable dir /usr/local/git/bin in PATH, mode 040777
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Library/Ruby/Gems/1.8/gems/rails-2.3.14/lib/rails/gem_dependency.rb:21.
WARNING: using the built-in Timeout class which is known to have issues when used for opening connections. Install the SystemTimer gem if you want to make sure the Redis client will not hang.
/Users/me/sources/shadow/test/unit/../test_helper.rb:36: warning: already initialized constant BEANSTALK
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader
Started
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Finished in 3.389328 seconds.

Noch ein paar Hintergrundinformationen:Ich verwende Octopus zum Sharding und das könnte die Dinge irgendwie stören??

War es hilfreich?

Lösung

Verwendung der Octopus Das Datenbank-Sharding-Gem weist einige Probleme bei der Vorbereitung von Testfällen auf.Siehe GitHub-Problem: https://github.com/tchandy/octopus/issues/31.

Ihnen stehen mehrere Optionen zur Verfügung, die einfachste Möglichkeit besteht darin, sie zu deaktivieren Octopus für Ihre Entwicklungsumgebung.Entfernen Sie „- development“ aus Ihrem shards.yml Datei.

Andernfalls können Sie das Problem beheben, indem Sie folgende Aufgabe hinzufügen:

 task :reconnect_octopus do
   if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
     ActiveRecord::Base.connection.initialize_shards(Octopus.config)
   end
 end
 task :'db:test:clone_structure' => :reconnect_octopus

oder für Rails 3:

 task :reconnect_octopus do
   if ActiveRecord::Base.connection.is_a?(Octopus::Proxy)
     ActiveRecord::Base.connection.initialize_shards(Octopus.config)
   end
 end
 task :'db:structure:load' => :reconnect_octopus

Dies sollte Ihr oben aufgeführtes Problem beheben.Viel Spaß beim Codieren!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top