aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_pool_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-6/+6
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix `payload[:class_name]` to `payload[:spec_name]`Ryuta Kamizono2016-07-171-2/+2
| | | | | | Follow up to #20818. `retrieve_connection` is passed `spec_name` instead of `klass` since #24844.
* Create connection.active_record notification and use that to ensure that lazy-Jeremy Wadsack2016-07-121-0/+12
| | | | | | | | | | | | | | | | | | | loaded model classes have their connections wrapped in transactions. See #17776 In Rails 4 config.eager_load was changed to false in the test environment. This means that model classes that connect to alternate databases with establish_connection are not loaded at start up. If use_transactional_fixtures is enabled, transactions are wrapped around the connections that have been established only at the start of the test suite. So model classes loaded later don't have transactions causing data created in the alternate database not to be removed. This change resolves that by creating a new connection.active_record notification that gets fired whenever a connection is established. I then added a subscriber after we set up transactions in the test environment to listen for additional connections and wrap those in transactions as well.
* Make connection stealing more explicitMatthew Draper2016-07-061-1/+4
|
* fix testArthur Neves2016-05-051-8/+7
|
* Refactor connection handlerArthur Neves2016-05-051-8/+8
| | | | | | | | | | | | | | | 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.
* Require only necessary concurrent-ruby classes.Jerry D'Antonio2015-11-041-1/+1
|
* Replaced `ActiveSupport::Concurrency::Latch` with concurrent-ruby.Jerry D'Antonio2015-07-131-14/+14
| | | | | | | | | | The concurrent-ruby gem is a toolset containing many concurrency utilities. Many of these utilities include runtime-specific optimizations when possible. Rather than clutter the Rails codebase with concurrency utilities separate from the core task, such tools can be superseded by similar tools in the more specialized gem. This commit replaces `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch`, which is functionally equivalent.
* sqlite3_mem has an existing connectionMatthew Draper2015-05-181-1/+3
| | | | | We must account for receiving one less call to #new_connection, but the test otherwise remains valid.
* AR::ConPool - remove synchronization around connection cache.thedarkone2015-05-141-4/+132
| | | | | | | | | | | | | | | | | | | | Renamed `@reserved_connections` -> `@thread_cached_conns`. New name clearly conveys the purpose of the cache, which is to speed-up `#connection` method. The new `@thread_cached_conns` now also uses `Thread` objects as keys (instead of previously `Thread.current.object_id`). Since there is no longer any synchronization around `@thread_cached_conns`, `disconnect!` and `clear_reloadable_connections!` methods now pre-emptively obtain ownership (via `checkout`) of all existing connections, before modifying internal data structures. A private method `release` has been renamed `thread_conn_uncache` to clear-up its purpose. Fixed some brittle `thread.status == "sleep"` tests (threads can go into sleep even without locks).
* AR::ConPool - establish connections outside of critical section.thedarkone2015-05-141-0/+34
|
* Apply schema cache dump when creating connectionsEugene Kenny2015-04-291-0/+15
| | | | | | | | | | | | | | | The `db:schema:cache:dump` rake task dumps the database schema structure to `db/schema_cache.dump`. If this file is present, the schema details are loaded into the currently checked out connection by a railtie while Rails is booting, to avoid having to query the database for its schema. The schema cache dump is only applied to the initial connection used to boot the application though; other connections from the same pool are created with an empty schema cache, and still have to load the structure of each table directly from the database. With this change, a copy of the schema cache is associated with the connection pool and applied to connections as they are created.
* Fix typos and improve the documentationJon Atack2015-04-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a squash of the following commits, from first to last: - Fix minor, random things I’ve come across lately that individually did not seem worth making a PR for, so I saved them for one commit. One common error is using “it’s” (which is an abbreviation of “it is”) when the possessive “its” should be used for indicating possession. - Changes include the name of a test, so remove the `[skip ci]` (thanks @senny). - Line wrap the changes at 80 chars and add one more doc fix. - Add a missing line wrap in the Contributing to Ruby on Rails Guide. - Line wrap the `TIP` section in the Contributing to Ruby on Rails Guide as well. Rendering the guide locally with `bundle exec rake guides:generate` did not show any change in on-screen formatting after adding the line wrap. The HTML generated is (extra line added to illustrate where the line wrap takes place): <div class="info"><p>Please squash your commits into a single commit when appropriate. This simplifies future cherry picks and also keeps the git log clean.</p></div> - Squash commits.
* test should only pass if the pool.size+1 checkout failsAaron Patterson2014-03-171-3/+2
| | | | | Previously, any of the connection checkouts could have failed, and this test would pass.
* use a latch to avoid busy loopsAaron Patterson2014-03-171-3/+4
|
* Reap connections based on owning-thread deathMatthew Draper2014-03-181-10/+13
| | | | | | | | | | | | | | | | .. not a general timeout. Now, if a thread checks out a connection then dies, we can immediately recover that connection and re-use it. This should alleviate the pool exhaustion discussed in #12867. More importantly, it entirely avoids the potential issues of the reaper attempting to check whether connections are still active: as long as the owning thread is alive, the connection is its business alone. As a no-op reap is now trivial (only entails checking a thread status per connection), we can also perform one in-line any time we decide to sleep for a connection.
* Use teardown helper method.Guo Xiang Tan2014-03-141-2/+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.
* Reaper has access to threadsafe active? callKevin Casey2014-02-081-1/+1
|
* if we remove the connection from the pool, we should close itAaron Patterson2013-07-081-0/+1
|
* fix typosAngelo Capilleri2013-06-151-1/+1
|
* MOAR cleanups.Vipul A M2013-03-141-1/+1
|
* Whitespaces :scissors:Rafael Mendonça França2013-01-221-7/+4
| | | | [ci skip]
* fix anonymous class issueDavid2013-01-201-0/+14
|
* ConnectionPool, unify exceptions, ConnectionTimeoutErrorJonathan Rochkind2012-09-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As a result of different commits, ConnectionPool had become of two minds about exceptions, sometimes using PoolFullError and sometimes using ConnectionTimeoutError. In fact, it was using ConnectionTimeoutError internally, but then recueing and re-raising as a PoolFullError. There's no reason for this bifurcation, standardize on ConnectionTimeoutError, which is the rails2 name and still accurately describes semantics at this point. History In Rails2, ConnectionPool raises a ConnectionTimeoutError if it can't get a connection within timeout. Originally in master/rails3, @tenderlove had planned on removing wait/blocking in connectionpool entirely, at that point he changed exception to PoolFullError. But then later wait/blocking came back, but exception remained PoolFullError. Then in 02b233556377 pmahoney introduced fair waiting logic, and brought back ConnectionTimeoutError, introducing the weird bifurcation. ConnectionTimeoutError accurately describes semantics as of this point, and is backwards compat with rails2, there's no reason for PoolFullError to be introduced, and no reason for two different exception types to be used internally, no reason to rescue one and re-raise as another. Unify!
* Remove warnings and unused codeRafael Mendonça França2012-06-111-2/+2
|
* Make connection pool fair with respect to waiting threads.Patrick Mahoney2012-05-251-0/+104
| | | | | | | | | | | | | | | The core of this fix is a threadsafe, fair Queue class. It is very similar to Queue in stdlib except that it supports waiting with a timeout. The issue this solves is that if several threads are contending for database connections, an unfair queue makes is possible that a thread will timeout even while other threads successfully acquire and release connections. A fair queue means the thread that has been waiting the longest will get the next available connection. This includes a few test fixes to avoid test ordering issues that cropped up during development of this patch.
* ConnectionPool wait_timeout no longer used for different types of timeouts. ↵Jonathan Rochkind2012-05-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #6441 An AR ConnectionSpec `wait_timeout` is pre-patch used for three different things: * mysql2 uses it for MySQL's own wait_timeout (how long MySQL should allow an idle connection before closing it), and defaults to 2592000 seconds. * ConnectionPool uses it for "number of seconds to block and wait for a connection before giving up and raising a timeout error", default 5 seconds. * ConnectionPool uses it for the Reaper, for deciding if a 'dead' connection can be reaped. Default 5 seconds. Previously, if you want to change these from defaults, you need to change them all together. This is problematic _especially_ for the mysql2/ConnectionPool conflict, you will generally _not_ want them to be the same, as evidenced by their wildly different defaults. This has caused real problems for people #6441 #2894 But as long as we're changing this, forcing renaming the ConnectionPool key to be more specific, it made sense to seperate the two ConnectionPool uses too -- these two types of ConnectionPool timeouts ought to be able to be changed independently, you won't neccesarily want them to be the same, even though the defaults are (currently) the same.
* Revert "Merge pull request #6416 from pmahoney/threadsafe-connection-pool"Rafael Mendonça França2012-05-221-115/+0
| | | | | | | | | | | | This reverts commit d2901f0fc4270a765717ad572d559dc49a56b3a8, reversing changes made to 525839fdd8cc34d6d524f204528d5b6f36fe410c. Conflicts: activerecord/test/cases/connection_pool_test.rb Reason: This change broke the build (http://travis-ci.org/#!/rails/rails/builds/1391490) and we don't have any solution until now. I asked the author to try to fix it and open a new pull request.
* Remove not used variables from connection poll testCarlos Antonio da Silva2012-05-211-2/+2
| | | | These variables were issuing some "not used" warnings.
* Make connection pool fair with respect to waiting threads.Patrick Mahoney2012-05-201-0/+115
|
* opening a connection will block if the pool is fullAaron Patterson2012-04-151-0/+24
|
* make sure connections returned after close are marked as in_useAaron Patterson2012-03-121-0/+10
|
* ensure that released connections move between threadsAaron Patterson2012-03-081-0/+18
|
* make active_connection? return true only if there is an open connection in ↵Aaron Patterson2012-03-081-0/+35
| | | | use for the current thread. fixes #5330
* actually disconnect from the database at the end of each testAaron Patterson2012-01-031-2/+2
|
* raise a pull full error when the connection pool is full and no connection ↵Aaron Patterson2011-12-301-0/+8
| | | | can be obtained
* connections are only removed if they are inactveAaron Patterson2011-12-301-2/+18
|
* connections can be reaped via the `reap` methodAaron Patterson2011-12-301-0/+15
|
* deal with removing connections associated with the current threadAaron Patterson2011-12-301-0/+8
|
* connections can be removed from the poolAaron Patterson2011-12-301-0/+19
|
* connections must be checked in at the end of a threadAaron Patterson2011-12-301-14/+3
|
* Automatic closure of connections in threads is deprecated. For exampleAaron Patterson2011-11-291-26/+5
| | | | | | | | | | | | | | | | | the following code is deprecated: Thread.new { Post.find(1) }.join It should be changed to close the database connection at the end of the thread: Thread.new { Post.find(1) Post.connection.close }.join Only people who spawn threads in their application code need to worry about this change.
* pushing caching and visitors down to the connectionAaron Patterson2011-11-191-37/+0
|
* Make it the responsibility of the connection to hold onto an ARel visitor ↵Jon Leighton2011-08-081-0/+4
| | | | for generating SQL. This improves the code architecture generally, and solves some problems with marshalling. Adapter authors please take note: you now need to define an Adapter.visitor_for method, but it degrades gracefully with a deprecation warning for now.
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* adding active_connection? to the connection poolAaron Patterson2011-03-281-0/+8
|
* Fix test/cases/connection_pool_test.rb for sqlite3 in-memory dbJon Leighton2011-02-141-0/+10
|
* primary keys should not be cleared on cache clear, fixing oracle testsAaron Patterson2011-02-081-3/+1
|
* column cache now lives on the connection poolAaron Patterson2011-02-041-0/+20
|