Travis Walters
2007-Aug-06 02:08 UTC
[Cruisecontrolrb-users] rake build issue related to foreign key constraints?
I''m setting up cruisecontrol.rb to build a simple rails project. When I run rake test from the work directory manually all tests pass and the build is successful but when I run the build thru cc it fails with an error on a create table statement saying the table already exists. Any suggestions would be very much appreciated. Also, if I run the rake command with a trace the results show different values when run through cc than when I run the same test task manually (Execute environment call when run manually doesn''t appear in my trace for cc).
Thibaut Barrère
2007-Aug-06 07:21 UTC
[Cruisecontrolrb-users] rake build issue related to foreign key constraints?
Hi Travis could you copy your cc failing building logs to give more details ? best Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/cruisecontrolrb-users/attachments/20070806/c95c1197/attachment.html
Travis Walters
2007-Aug-06 13:45 UTC
[Cruisecontrolrb-users] rake build issue related to foreign key constraints?
Sure, here is the contents of my build.log file: -> 0.0038s == CreateProjects: migrated (0.0039s) ========================================== CreateObjectives: migrating ===============================================-- create_table(:objectives) -> 0.0052s -- execute("alter table objectives add constraint fk_objectives_projects foreign key (project_id) references projects(id)") -> 0.0057s == CreateObjectives: migrated (0.0109s) ======================================== CreateMeasurements: migrating =============================================-- create_table(:measurements) -> 0.0018s -- execute("alter table measurements add constraint fk_measurements_objectives foreign key (objective_id) references objectives(id)") -> 0.0037s == CreateMeasurements: migrated (0.0057s) ====================================== CreateBenchmarks: migrating ===============================================-- create_table(:benchmarks) -> 0.0019s -- execute("alter table benchmarks add constraint fk_benchmarks_measurements foreign key (measurement_id) references measurements(id)") -> 0.0038s == CreateBenchmarks: migrated (0.0058s) ======================================== CreateMetrics: migrating ==================================================-- create_table(:metrics) -> 0.0029s -- execute("alter table metrics add constraint fk_metrics_measurements foreign key (measurement_id) references measurements(id)") -> 0.0035s == CreateMetrics: migrated (0.0065s) =========================================== AddSessions: migrating ====================================================-- create_table(:sessions) -> 0.0024s -- add_index(:sessions, :session_id) -> 0.0031s -- add_index(:sessions, :updated_at) -> 0.0079s == AddSessions: migrated (0.0136s) ===========================================** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump [CruiseControl] Invoking Rake task "test" ** Invoke test (first_time) ** Execute test ** Invoke test:units (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump ** Invoke db:test:purge ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Invoke test:functionals (first_time) ** Invoke db:test:prepare ** Execute test:functionals Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader Started ........ Finished in 0.056911 seconds. 8 tests, 20 assertions, 0 failures, 0 errors /usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" ** Invoke test:integration (first_time) ** Invoke db:test:prepare ** Execute test:integration Mysql::Error: #42S01Table ''measurements'' already exists: CREATE TABLE measurements (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `qualifier` varchar(255) DEFAULT NULL, `objective_id` int(11) DEFAULT NULL) ENGINE=InnoDB /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract_adapter.rb:128:in `log'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:243:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:104:in `create_table'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:353:in `create_table'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:275:in `send'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:275:in `method_missing'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:259:in `say_with_time'' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:259:in `say_with_time'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:273:in `method_missing'' ./db/schema.rb:16 /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/schema.rb:43:in `instance_eval'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/schema.rb:43:in `define'' ./db/schema.rb:5 /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in `load'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:31 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:76 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:153 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:369:in `invoke_prerequisites'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1003:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1003:in `send'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1003:in `each'' /usr/local/lib/ruby/gems/1.rake aborted! Test failures /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:53 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake:5:in `invoke_rake_task'' /usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake:59 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'' -e:1 8/gems/rake-0.7.3/lib/rake.rb:368:in `invoke_prerequisites'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:361:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:45 /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:43:in `collect'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/testing.rake:43 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake:5:in `invoke_rake_task'' /usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake:59 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'' -e:1 dir : /usr/lib/cruisecontrolrb-1.1.0/projects/goalkeeper/work command : ruby -e "require ''rubygems'' rescue nil; require ''rake''; load ''/usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake''; ARGV << ''--nosearch'' << ''--trace'' << ''cc:build''; Rake.application.run" executed command : echo /usr/lib/cruisecontrolrb-1.1.0/projects/goalkeeper/work twalters$ ruby -e "require ''rubygems'' rescue nil; require ''rake''; load ''/usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake''; ARGV << ''--nosearch'' << ''--trace'' << ''cc:build''; Rake.application.run" >> /usr/lib/cruisecontrolrb-1.1.0/projects/goalkeeper/build-42/build.log && ruby -e "require ''rubygems'' rescue nil; require ''rake''; load ''/usr/lib/cruisecontrolrb-1.1.0/tasks/cc_build.rake''; ARGV << ''--nosearch'' << ''--trace'' << ''cc:build''; Rake.application.run" >> /usr/lib/cruisecontrolrb-1.1.0/projects/goalkeeper/build-42/build.log 2>&1 exitstatus: 1 STDERR TAIL START STDERR TAIL END [root at Ricdev3 build-42]# here''s a trace run from running rake test manually against the same code base: [root at Ricdev3 work]# rake test (in /usr/lib/cruisecontrolrb-1.1.0/projects/goalkeeper/work) /usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" "test/unit/project_test.rb" Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader Started .... Finished in 0.022967 seconds. 4 tests, 7 assertions, 0 failures, 0 errors /usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" "test/functional/admin_controller_test.rb" Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader Started ........ Finished in 0.058725 seconds. 8 tests, 20 assertions, 0 failures, 0 errors /usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" [root at Ricdev3 work]# From: Thibaut Barr?re Sent: Mon 8/6/2007 3:21 AM To: Travis Walters Cc: cruisecontrolrb-users at rubyforge.org Subject: Re: [Cruisecontrolrb-users] rake build issue related to foreign key constraints? Hi Travis could you copy your cc failing building logs to give more details ? best Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/cruisecontrolrb-users/attachments/20070806/43426f86/attachment-0001.html
Patrick Joyce
2007-Nov-07 19:16 UTC
[Cruisecontrolrb-users] rake build issue related to foreign key constraints?
Did anyone ever find a solution to this? My tests pass when I run "rake test" in the work directory but when cc.rb runs the tests I get an error on every test after the test in which the Schedules fixture is loaded. All tests before the schedules fixture is loaded pass. It seems as though that table isn''t being cleared. Any idea why this would happen? Name: test_should_allow_site_admin(Admin::TemplatesControllerTest) Type: Error Message: ActiveRecord::StatementInvalid: Mysql::Error: #23000Cannot delete or update a parent row: a foreign key constraint fails (`sandwichboard_cruisecontrol/schedules`, CONSTRAINT `fk_schedule_restaurants` FOREIGN KEY (`restaurant_id`) REFERENCES `restaurants` (`id`)): TRUNCATE TABLE restaurants /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:128:in `log'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:243:in `execute'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:258:in `update'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:47:in `delete'' ./test/functional/admin/../../test_helper.rb:96:in `delete_existing_fixtures_for'' ./test/functional/admin/../../test_helper.rb:92:in `delete_existing_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:256:in `create_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:256:in `each'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:256:in `create_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:255:in `create_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/base.rb:867:in `silence'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in `create_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:593:in `load_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:538:in `setup_with_fixtures'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/rails/activerecord/lib/active_record/fixtures.rb:575:in `setup'' /Users/patrick/cruisecontrolrb/projects/SandwichBoard/work/vendor/plugins/mocha/lib/mocha/test_case_adapter.rb:18:in `run'' Travis Walters-2 wrote:> > I''m setting up cruisecontrol.rb to build a simple rails project. When I > run rake test from the work directory manually all tests pass and the > build is successful but when I run the build thru cc it fails with an > error on a create table statement saying the table already exists. Any > suggestions would be very much appreciated. Also, if I run the rake > command with a trace the results show different values when run through cc > than when I run the same test task manually (Execute environment call when > run manually doesn''t appear in my trace for cc). > > > > > _______________________________________________ > Cruisecontrolrb-users mailing list > Cruisecontrolrb-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/cruisecontrolrb-users > >-- View this message in context: http://www.nabble.com/rake-build-issue-related-to-foreign-key-constraints--tf4221922.html#a13633265 Sent from the CruiseControl.rb - Users mailing list archive at Nabble.com.
Neill Zero
2007-Nov-08 19:53 UTC
[Cruisecontrolrb-users] rake build issue related to foreign key constraints?
Patrick Joyce wrote:> > Did anyone ever find a solution to this? My tests pass when I run "rake > test" in the work directory but when cc.rb runs the tests I get an error > on every test after the test in which the Schedules fixture is loaded. All > tests before the schedules fixture is loaded pass. It seems as though that > table isn''t being cleared. Any idea why this would happen? >Hi Patrick, I had a similar but not identical issue some time ago. I traced it to the fact that rake, under the standard cruise build task, was not executing db:test:purge every time it was "invoked". In my case, my migrations loaded seed data into the tables, which was not then purged before tests ran. Fixture loading then caused FK constraint violations. At the time, I worked around the issue with a custom build task to use under cruise which did almost the same but forced a purge at the critical point. Here''s the detail of what I found, and the workaround I used. Hopefully it is also applicable in your situation. To understand the problem, I needed to understand what ''rake test'' was doing. I''ve put a diagram of the dependencies at http://abstractplain.net/blog/?p=1019. If we look at a trace of the test task in a stand-alone rake invocation, side-by-side with the cruise build task, and if we look only at what tasks are actually being *executed* (rather than invoked) we have the following (view it with a fixed width font): rake stand-alone cruise build ---------------------------------------------------------- Execute cc:build Execute environment Execute db:test:purge Execute db:migrate Execute db:schema:dump Execute test Execute test Execute environment < Execute db:test:prepare Execute db:test:prepare Execute db:schema:dump < Execute db:test:purge < Execute db:test:clone Execute db:test:clone Execute db:schema:load Execute db:schema:load [runs tests] [runs tests] You can see that on the cruise side, the tasks ''environment'', ''db:schema:dump'' and ''db:test:purge'' are not called when running the test task! If you look at a fuller trace, you''ll see it is being invoked (the db:test:clone requires it) but not executed! Rake thinks this declared "dependency" has been met, because rake called them earlier in the cruise task; cruise invokes "db:test:purge" explicitly on line 49 of tasks/cc_build.rake (in cruise v1.1.0), and then ''db:migrate'' a little later. So no purge is being done between cruise''s running of migrations and running the tests. In my case (where migrations populated some tables with seed data), I believe that this meant that when the tests ran, even before fixtures were loaded, there was data in the test db. FK constraint violations occurred when the fixtures tried to delete and load their tables, due to the presence of these left-over records). Do your migrations include seed data? I got around this issue by having cruise run a custom task. Mine does almost exactly what cruise''s standard build task does, but also ensures that purge is executed when it needs to be. A better solution might involve ensuring that cruise''s calls to ''db:test:purge'', ''db:migrate'', and ''test'' are have separate rake contexts. Finally, here''s my custom task for building under cruise. ( I''ve also posted it at: http://abstractplain.net/blog/?p=1024 ) #This builds from migrations each time (slower, but more reliable). #Must then empty seed data before tests start to delete stuff, or FK constraints get violated. #NOTE: currently needs db:test:purgetwo to exist (just copy paste db:test:purge task) task :cruise do ENV[''RAILS_ENV''] = ''test'' puts "custom cruise task invoked. env is hardcoded to test" Rake::Task["environment"].invoke #start from scratch with just the test db Rake::Task["db:test:purge"].invoke #necessary to reconnect, as purge drops database (and w mysql the conn) CruiseControl::reconnect #run all migrations from scratch. slow but clean Rake::Task["db:migrate"].invoke #empty the db of data - migration has loaded seed data into the tables, #which''ll be deleted badly by test fixtures loader. #NOTE: db:test:purgetwo is just a quick hack to force this #identical action to be called again #TODO: replace with the correct way to force execution of a task in rake Rake::Task["db:test:purgetwo"].invoke #necessary to reconnect, as purge drops database (and w mysql the conn) CruiseControl::reconnect #the migration has already done a schema dump Rake::Task["db:schema:load"].invoke success = Rake::Task["test"].invoke success end #good luck, neill -- View this message in context: http://www.nabble.com/rake-build-issue-related-to-foreign-key-constraints--tf4221922.html#a13654415 Sent from the CruiseControl.rb - Users mailing list archive at Nabble.com.
Patrick Joyce
2007-Nov-08 21:52 UTC
[Cruisecontrolrb-users] rake build issue related to foreign key constraints?
Thanks for your response, Neil. My problem is somewhat different but I imagine that your solution may help someone else. It turns out that there is a known issue with Rails leaving fixture data in the DB after a TestCase runs. (http://dev.rubyonrails.org/ticket/2404) Therefore this actually was a Rails issue, not a cruisecontrol.rb issue. My tests would pass when running "rake test" from the command line because "rake test" builds the test DB schema from schema.rb. Schema.rb is created by db:schema:dump which ignores foreign keys. So I''ve been running my tests against a DB without the foreign keys. The issue only showed up with cruisecontrol because cruise builds the test DB directly from the migrations. For now, I''ve created a :cruise rake task that builds in the same way as "rake test" (without foreign keys). I set up dev and test databases for cruisecontrol and then invoke the rake tasks "db:migrate" and "test" in my :cruise task. desc ''Continuous build target'' task :cruise do Rake::Task[''db:migrate''].invoke Rake::Task["test"].invoke end This runs the migrations against the development DB, moves the schema to the test DB without the foreign keys, and runs the tests. When I figure out how to properly handle fixtures with foreign keys I''ll change the task to reflect it. Thanks again for all your help. - Patrick Joyce On Nov 8, 2007 2:53 PM, Neill Zero <neillzero at yahoo.co.uk> wrote:> > > > Patrick Joyce wrote: > > > > Did anyone ever find a solution to this? My tests pass when I run "rake > > test" in the work directory but when cc.rb runs the tests I get an error > > on every test after the test in which the Schedules fixture is loaded. All > > tests before the schedules fixture is loaded pass. It seems as though that > > table isn''t being cleared. Any idea why this would happen? > > > > Hi Patrick, > > I had a similar but not identical issue some time ago. I traced it to the > fact that rake, under the standard cruise build task, was not executing > db:test:purge every time it was "invoked". In my case, my migrations loaded > seed data into the tables, which was not then purged before tests ran. > Fixture loading then caused FK constraint violations. At the time, I worked > around the issue with a custom build task to use under cruise which did > almost the same but forced a purge at the critical point. > > Here''s the detail of what I found, and the workaround I used. Hopefully it > is also applicable in your situation. > > To understand the problem, I needed to understand what ''rake test'' was > doing. I''ve put a diagram of the dependencies at > http://abstractplain.net/blog/?p=1019. > > If we look at a trace of the test task in a stand-alone rake invocation, > side-by-side with the cruise build task, and if we look only at what tasks > are actually being *executed* (rather than invoked) we have the following > (view it with a fixed width font): > > rake stand-alone cruise build > ---------------------------------------------------------- > Execute cc:build > Execute environment > Execute db:test:purge > Execute db:migrate > Execute db:schema:dump > Execute test Execute test > Execute environment < > Execute db:test:prepare Execute db:test:prepare > Execute db:schema:dump < > Execute db:test:purge < > Execute db:test:clone Execute db:test:clone > Execute db:schema:load Execute db:schema:load > [runs tests] [runs tests] > > You can see that on the cruise side, the tasks ''environment'', > ''db:schema:dump'' and ''db:test:purge'' are not called when running the test > task! If you look at a fuller trace, you''ll see it is being invoked (the > db:test:clone requires it) but not executed! Rake thinks this declared > "dependency" has been met, because rake called them earlier in the cruise > task; cruise invokes "db:test:purge" explicitly on line 49 of > tasks/cc_build.rake (in cruise v1.1.0), and then ''db:migrate'' a little > later. > > So no purge is being done between cruise''s running of migrations and running > the tests. In my case (where migrations populated some tables with seed > data), I believe that this meant that when the tests ran, even before > fixtures were loaded, there was data in the test db. FK constraint > violations occurred when the fixtures tried to delete and load their tables, > due to the presence of these left-over records). Do your migrations include > seed data? > > I got around this issue by having cruise run a custom task. Mine does > almost exactly what cruise''s standard build task does, but also ensures that > purge is executed when it needs to be. > > A better solution might involve ensuring that cruise''s calls to > ''db:test:purge'', ''db:migrate'', and ''test'' are have separate rake contexts. > > Finally, here''s my custom task for building under cruise. ( I''ve also > posted it at: http://abstractplain.net/blog/?p=1024 ) > > #This builds from migrations each time (slower, but more reliable). > #Must then empty seed data before tests start to delete stuff, or FK > constraints get violated. > #NOTE: currently needs db:test:purgetwo to exist (just copy paste > db:test:purge task) > task :cruise do > ENV[''RAILS_ENV''] = ''test'' > puts "custom cruise task invoked. env is hardcoded to test" > > Rake::Task["environment"].invoke > > #start from scratch with just the test db > Rake::Task["db:test:purge"].invoke > > #necessary to reconnect, as purge drops database (and w mysql the conn) > CruiseControl::reconnect > > #run all migrations from scratch. slow but clean > Rake::Task["db:migrate"].invoke > > #empty the db of data - migration has loaded seed data into the tables, > #which''ll be deleted badly by test fixtures loader. > > #NOTE: db:test:purgetwo is just a quick hack to force this > #identical action to be called again > #TODO: replace with the correct way to force execution of a task in rake > Rake::Task["db:test:purgetwo"].invoke > > #necessary to reconnect, as purge drops database (and w mysql the conn) > CruiseControl::reconnect > > #the migration has already done a schema dump > Rake::Task["db:schema:load"].invoke > > success = Rake::Task["test"].invoke > success > end > > > #good luck, neill > > -- > View this message in context: http://www.nabble.com/rake-build-issue-related-to-foreign-key-constraints--tf4221922.html#a13654415 > > > > Sent from the CruiseControl.rb - Users mailing list archive at Nabble.com. > > _______________________________________________ > Cruisecontrolrb-users mailing list > Cruisecontrolrb-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/cruisecontrolrb-users >