aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_adapters/connection_handler_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-5/+5
|
* Skip test that use fork in the memory store dbRafael Mendonça França2018-01-241-32/+34
|
* Make discard safe when it follows a manual disconnectMatthew Draper2018-01-251-0/+40
| | | | | | It doesn't have to do anything, but it shouldn't fail. Fixes #31766.
* Don't pass `object_id` to `refute_nil` since `object_id` never to be nilRyuta Kamizono2017-12-261-6/+6
| | | | And prefer `assert_same` over `assert_equal`.
* Improve AR connection fork safetyMatthew Draper2017-11-181-0/+32
| | | | | | Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* `DEFAULT_ENV` falls back to `default_env` when `RAILS_ENV` or `RACK_ENV` is ↵Ryuta Kamizono2017-05-251-0/+11
| | | | | | an empty string Follow up of #27399.
* Allow 3-level DB configs to group connections by environmentMatthew Draper2017-02-221-0/+60
| | | | [Arthur Nogueira Neves & Matthew Draper]
* Fix pool_from_any_process to use most recent speceileencodes2017-01-131-0/+35
| | | | | | | | | | | | | If a process is forked more than once, the pool was grabbing the oldest spec, not the most recent spec. This wasn't noticed before because most folks are lilely forking the process only once. If you're forking the process multiple times however the wrong spec name will be returned and an incorrect connection will be used for the process. This fixes the issue by reversing the list of spec names so we can grab the most recent spec rather than the oldest spec.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-7/+7
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add to_hash to specificationArthur Neves2016-05-251-1/+1
|
* Remove `name` from `establish_connection`Arthur Neves2016-05-241-3/+2
| | | | | Instead of passing a separete name variable, we can make the resolver merge a name on the config, and use that before creating the Specification.
* remove_connection should not remove parent connectionArthur Neves2016-05-111-0/+7
| | | | | | When calling remove_connection in a subclass, that should not fallback to the parent, otherwise it will remove the parent connection from the handler.
* Dont cache the conn_spec_name when emptyArthur Neves2016-05-111-1/+10
| | | | | | | | We cannot cache the connection_specification_name when it doesnt exist. Thats because the parent value could change, and we should keep failling back to the parent. If we cache that in a children as an ivar, we would not fallback anymore in the next call, so the children would not get the new parent spec_name.
* Make sure we reset the connection_specification_name onArthur Neves2016-05-101-0/+14
| | | | | | | | | | | | | | remove_connection When calling `remove_connection` on a model, we delete the pool so we also need to reset the `connection_specification_name` so it will fallback to the parent. This was the current behavior before rails 5, which will fallback to the parent connection pool. [fixes #24959] Special thanks to @jrafanie for working with me on this fix.
* s/specification_id/specification_nameArthur Neves2016-05-051-7/+7
|
* Use spec key, when given as spec_idArthur Neves2016-05-051-19/+15
|
* Refactor connection handlerArthur Neves2016-05-051-21/+23
| | | | | | | | | | | | | | | ConnectionHandler will not have any knowlodge of AR models now, it will only know about the specs. Like that we can decouple the two, and allow the same model to use more than one connection. Historically, folks used to create abstract AR classes on the fly in order to have multiple connections for the same model, and override the connection methods. With this, now we can override the `specificiation_id` method in the model, to return a key, that will be used to find the connection_pool from the handler.
* Add schema cache to new connection pool after forkEugene Kenny2015-05-171-0/+46
| | | | | | | | | | | | | | Active Record detects when the process has forked and automatically creates a new connection pool to avoid sharing file descriptors. If the existing connection pool had a schema cache associated with it, the new pool should copy it to avoid unnecessarily querying the database for its schema. The code to detect that the process has forked is in ConnectionHandler, but the existing test for it was in the ConnectionManagement test file. I moved it to the right place while I was writing the new test for this change.
* Return an array of pools from `connection_pools`Rafael Mendonça França2015-01-041-3/+1
|
* Rearrange deck chairs on the titanic. Organize connection handling test cases.Jeremy Kemper2014-04-211-193/+0
|
* Drop in @jeremy's new database.yml template textMatthew Draper2014-04-091-0/+8
| | | | | In passing, allow multi-word adapters to be referenced in a URL: underscored_name must become hyphened-name.
* Don't deprecate after allMatthew Draper2014-04-091-11/+9
|
* Less ambition, more deprecationMatthew Draper2014-04-091-59/+11
| | | | | | | | The "DATABASE_URL_*" idea was moving in the wrong direction. Instead, let's deprecate the situation where we end up using ENV['DATABASE_URL'] at all: the Right Way is to explicitly include it in database.yml with ERB.
* Ensure we correctly and immediately load all ENV entriesMatthew Draper2014-04-081-0/+21
| | | | .. even when the supplied config made no hint that name was relevant.
* Give a deprecation message even when the lookup failsMatthew Draper2014-04-081-2/+4
| | | | | | | | | | | | If the supplied string doesn't contain a colon, it clearly cannot be a database URL. They must have intended to do a key lookup, so even though it failed, give the explanatory deprecation warning, and raise the exception that lists the known configs. Conveniently, this also simplifies our logical behaviour: if the string matches a known configuration, or doesn't contain a colon (and is therefore clearly not a URL), then we output a deprecation warning, and behave exactly as we would if it were a symbol.
* Test DATABASE_URL has precendance over DATABASE_URL_#{environment}Rafael Mendonça França2014-04-081-0/+9
|
* Make sure DEFAULT_URL only override current environment databaseRafael Mendonça França2014-04-081-9/+29
| | | | configuration
* Only apply DATABASE_URL for Rails.envMatthew Draper2014-04-081-17/+26
| | | | | As we like ENV vars, also support DATABASE_URL_#{env}, for more obscure use cases.
* Avoid a spurious deprecation warning for database URLsMatthew Draper2014-04-031-0/+48
| | | | | | | | | | | | | | | | | | This is all about the case where we have a `DATABASE_URL`, and we have a `database.yml` present, but the latter doesn't contain the key we're looking for. If the key is a symbol, we'll always connect to `DATABASE_URL`, per the new behaviour in 283a2edec2f8ccdf90fb58025608f02a63948fa0. If the key is a string, on the other hand, it should always be a URL: the ability to specify a name not present in `database.yml` is new in this version of Rails, and that ability does not stretch to the deprecated use of a string in place of a symbol. Uncovered by @guilleiguaran while investigating #14495 -- this actually may be related to the original report, but we don't have enough info to confirm.
* Merge pull request #14380 from ↵Yves Senn2014-03-151-1/+1
|\ | | | | | | | | tgxworld/use_teardown_helper_method_in_activerecord Use teardown helper method.
| * Use teardown helper method.Guo Xiang Tan2014-03-141-1/+1
| | | | | | | | | | | | | | | | Follow-Up to https://github.com/rails/rails/pull/14348 Ensure that SQLCounter.clear_log is called after each test. This is a step to prevent side effects when running tests. This will allow us to run them in random order.
* | Allow custom JDBC urlsschneems2014-03-141-0/+6
|/ | | | mitigates #14323
* Handle missing environment from non empty configschneems2014-02-211-15/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | If using a `DATABASE_URL` and a `database.yml`. The connection information in `DATABASE_URL` should be merged into whatever environment we are in. As released in 4.1.0rc1 if someone has a database.yml but is missing a key like production: ```yml development: host: localhost ``` Then the check for blank config will return false so the information from the `DATABASE_URL` will not be used when attempting to connect to the `production` database and the connection will incorrectly fail. This commit fixes this problem and adds a test for the behavior. In addition the ability to specify a connection url in a `database.yml` like this: ``` production: postgres://localhost/foo ``` Was introduced in 4.1.0rc1 though should not be used, instead using a url sub key ``` production: url: postgres://localhost/foo ``` This url sub key was also introduced in 4.1.0rc1 though the `production: postgres://localhost/foo` was not removed. As a result we should not test this behavior.
* Restore DATABASE_URL even if it's nil in connection_handler testPrathamesh Sonpatki2014-01-101-1/+1
| | | | | - We have to restore DATABASE_URL to its previous state irrespective of previous value is nil or not
* Ensure Active Record connection consistencyschneems2014-01-091-0/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently Active Record can be configured via the environment variable `DATABASE_URL` or by manually injecting a hash of values which is what Rails does, reading in `database.yml` and setting Active Record appropriately. Active Record expects to be able to use `DATABASE_URL` without the use of Rails, and we cannot rip out this functionality without deprecating. This presents a problem though when both config is set, and a `DATABASE_URL` is present. Currently the `DATABASE_URL` should "win" and none of the values in `database.yml` are used. This is somewhat unexpected to me if I were to set values such as `pool` in the `production:` group of `database.yml` they are ignored. There are many ways that active record initiates a connection today: - Stand Alone (without rails) - `rake db:<tasks>` - ActiveRecord.establish_connection - With Rails - `rake db:<tasks>` - `rails <server> | <console>` - `rails dbconsole` We should make all of these behave exactly the same way. The best way to do this is to put all of this logic in one place so it is guaranteed to be used. Here is my prosed matrix of how this behavior should work: ``` No database.yml No DATABASE_URL => Error ``` ``` database.yml present No DATABASE_URL => Use database.yml configuration ``` ``` No database.yml DATABASE_URL present => use DATABASE_URL configuration ``` ``` database.yml present DATABASE_URL present => Merged into `url` sub key. If both specify `url` sub key, the `database.yml` `url` sub key "wins". If other paramaters `adapter` or `database` are specified in YAML, they are discarded as the `url` sub key "wins". ``` ### Implementation Current implementation uses `ActiveRecord::Base.configurations` to resolve and merge all connection information before returning. This is achieved through a utility class: `ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig`. To understand the exact behavior of this class, it is best to review the behavior in activerecord/test/cases/connection_adapters/connection_handler_test.rb though it should match the above proposal.
* Fix memory leak in development modeJon Leighton2012-11-301-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Keying these hashes by klass causes reloadable classes to never get freed. Thanks to @thedarkone for pointing this out in the comments on 221571beb6b4bb7437989bdefaf421f993ab6002. This doesn't seem to make a massive difference to performance. Benchmark --------- require 'active_record' require 'benchmark/ips' class Post < ActiveRecord::Base establish_connection adapter: 'sqlite3', database: ':memory:' end GC.disable Benchmark.ips(20) do |r| r.report { Post.connection } end Before ------ Calculating ------------------------------------- 5632 i/100ms ------------------------------------------------- 218671.0 (±1.9%) i/s - 4364800 in 19.969401s After ----- Calculating ------------------------------------- 8743 i/100ms ------------------------------------------------- 206525.9 (±17.8%) i/s - 4039266 in 19.992590s
* Properly deprecate ConnectionHandler#connection_poolsJon Leighton2012-11-091-1/+7
| | | | | | | | Rather than just changing it and hoping for the best. Requested by @jeremy: https://github.com/rails/rails/commit/ba1544d71628abff2777c9c514142d7e9a159111#commitcomment-2106059
* Remove ActiveRecord::ModelJon Leighton2012-10-261-2/+2
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* rename AR::Model::Tag to AR::Tag - fixes #7714Francesco Rodriguez2012-09-201-2/+2
|
* Cache the connection pool for a given classJon Leighton2012-08-311-0/+2
|
* Make connection pool retrieval fasterJon Leighton2012-08-311-9/+4
| | | | | | * Loop rather than recurse in retrieve_connection_pool * Key the hash by class rather than class name. This avoids creating unnecessary strings.
* Simplify AR configuration code.Jon Leighton2012-06-151-3/+2
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Extract common logic into a methodJon Leighton2011-12-241-0/+3
|
* pools are 1:1 with spec now rather than 1:1 with classAaron Patterson2011-11-281-2/+0
|
* Merge pull request #2897 from rsutphin/ar31-remove_connectionAaron Patterson2011-09-061-1/+20
| | | | Patch for issue #2820