문제

RAILS 2.3의 유닛 테스트를 실행하면 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'
.

i rake db:test:load 이전에 이르기 전에 테이블을 만들었습니다.그러나 Unit Tests 명령을 실행 한 후 mysql를 확인하면 테이블이 실제로 누락됩니다.단위 테스트를 준비하는 과정에서 테이블이 실종 될 수 있습니다.다음은 테스트를 실행하는 데있어 디버그 로그가 있습니다.

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.
.

일부 배경 : 나는 샤딩을 위해 낙지를 사용하고 있으며, 어떻게 든 것처럼 보이는 것일 수 있습니까 ??

도움이 되었습니까?

해결책

Octopus 데이터베이스 샤딩 보석을 사용하면 테스트 케이스 준비에 문제가 있습니다.github 이슈를 참조하십시오 : https://github.com/tchandy/octopus/issues/31 .

몇 가지 옵션이 있으며, 가장 쉽게 개발 환경에 대한 Octopus를 사용하지 않도록 설정할 수 있습니다.shards.yml 파일에서 "- 개발"을 제거하십시오.

그렇지 않으면 작업을 추가하여 문제를 패치 할 수 있습니다.

 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
.

또는 레일 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
.

위에 나열된 문제를 해제해야합니다.해피 코딩!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top