Skip to content

Commit

Permalink
Quiet check_schema_cache_dump_version errors:
Browse files Browse the repository at this point in the history
* "Ignoring db/schema_cache.yml because it has expired."

Before:

```
bin/test test/application/rake/multi_dbs_test.rb -n "schema_cache is loaded on primary db in multi-db app"
Run options: -n "schema_cache is loaded on primary db in multi-db app" --seed 13139

Ignoring db/schema_cache.yml because it has expired. The current schema version is 20231017102756, but the one in the schema cache file is 20231017102755.
.
```

Added test cases for this error and "Failed to validate schema cache" in `test/application/rake/dbs_test.rb`.
  • Loading branch information
zzak committed Oct 31, 2023
1 parent 344e59e commit 0803589
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
31 changes: 31 additions & 0 deletions railties/test/application/rake/dbs_test.rb
Expand Up @@ -496,6 +496,37 @@ def db_schema_cache_dump
end
end

test "db:schema:cache:dump ignores expired version" do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:schema:cache:dump"
rails "generate", "model", "cat", "color:string"
rails "db:migrate"

expired_warning = capture(:stderr) do
cache_size = rails("runner", "p ActiveRecord::Base.connection.schema_cache.size", stderr: true).strip
assert_equal "0", cache_size
end
assert_match(/Ignoring .*\.yml because it has expired/, expired_warning)
end
end

test "db:schema:cache:dump ignores validation errors" do
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
rails "db:migrate"
rails "db:schema:cache:dump"

ActiveRecord::Migrator.stub(:current_version, -> { raise ActiveRecord::ActiveRecordError, "stubbed error" }) do
validation_warning = capture(:stderr) do
cache_tables = rails("runner", "p ActiveRecord::Base.connection.schema_cache.columns('books')", stderr: true).strip
assert_includes cache_tables, "title", "expected cache_tables to include a title entry"
end
assert_match(/Failed to validate the schema cache because of ActiveRecord::ActiveRecordError: stubbed error/, validation_warning)
end
end
end

def db_fixtures_load(expected_database)
Dir.chdir(app_path) do
rails "generate", "model", "book", "title:string"
Expand Down
7 changes: 5 additions & 2 deletions railties/test/application/rake/multi_dbs_test.rb
Expand Up @@ -822,8 +822,11 @@ class TwoMigration < ActiveRecord::Migration::Current
cache_tables_a = rails("runner", "p ActiveRecord::Base.connection.schema_cache.columns('books')").strip
assert_includes cache_tables_a, "title", "expected cache_tables_a to include a title entry"

cache_size_b = rails("runner", "p AnimalsBase.connection.schema_cache.size", stderr: true).strip
assert_equal "0", cache_size_b
expired_warning = capture(:stderr) do
cache_size_b = rails("runner", "p AnimalsBase.connection.schema_cache.size", stderr: true).strip
assert_equal "0", cache_size_b
end
assert_match(/Ignoring .*\.yml because it has expired/, expired_warning)

cache_tables_b = rails("runner", "p AnimalsBase.connection.schema_cache.columns('dogs')").strip
assert_includes cache_tables_b, "name", "expected cache_tables_b to include a name entry"
Expand Down

0 comments on commit 0803589

Please sign in to comment.