aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/query_cache_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #28869 from eugeneius/query_cache_all_poolsMatthew Draper2017-11-171-0/+9
|\ | | | | Enable query cache on all connection pools
| * Enable query cache on all connection poolsEugene Kenny2017-04-241-0/+9
| | | | | | | | | | | | Since the query cache no longer eagerly checks out a connection, we can enable it on all connection pools at the start of every request, and it will only take effect for requests that actually use those pools.
* | sqlite3 adapter returns integer value which used to be stringYasuo Honda2017-09-011-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `to_i` was added for SQLite3 adapter which did not handle number but sqlite3 gem already supports it then `to_i` is unnecessary. else condition is kept for adapters which return string, i.e. mysql(not mysql2) and sqlserver. Renamed `test_cache_does_not_wrap_string_results_in_arrays` to `test_cache_does_not_wrap_results_in_arrays` to explain the current behavior. most of adapters return integer, not only string. * Refer these commits: "future proofing the sqlite3 adapter code" https://github.com/rails/rails/commit/beda2d43d6ac5c3435fc2fba0cbd108c20fe1c67 "Refactor calculation test to remove unneeded SQLite special case." https://github.com/rails/rails/commit/47d568ed3fc701934ebe80b276f3d8bf6951c93f "no need to to_i, sqlite does that for us" https://github.com/rails/rails/commit/6cf44a1bd64ba10497742d70ad78fe68faa16e99
* | Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-011-3/+3
|\ \
| * \ Merge pull request #29869 from kamipo/make_type_map_to_privateRafael França2017-07-211-3/+1
| |\ \ | | | | | | | | Make `type_map` to private because it is only used in the connection adapter
| | * | Make `type_map` to private because it is only used in the connection adapterRyuta Kamizono2017-07-201-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | `type_map` is an internal API and it is only used in the connection adapter. And also, some type map initializer methods requires passed `type_map`, but those instances already has `type_map` in itself. So we don't need explicit passing `type_map` to the initializers.
| * | | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| |/ /
* | | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-07-151-23/+53
|\| |
| * | 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
| | |
| * | Should use the same connection in using query cacheRyuta Kamizono2017-06-291-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_cache_is_available_when_using_a_not_connected_connection` is always failed if running only the test since #29609. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/query_cache_test.rb -n test_cache_is_available_when_using_a_not_connected_connection Using mysql2 Run options: -n test_cache_is_available_when_using_a_not_connected_connection --seed 15043 F Finished in 0.070519s, 14.1806 runs/s, 28.3612 assertions/s. 1) Failure: QueryCacheTest#test_cache_is_available_when_using_a_not_connected_connection [test/cases/query_cache_test.rb:336]: 2 instead of 1 queries were executed. Queries: SELECT `tasks`.* FROM `tasks` WHERE `tasks`.`id` = ? LIMIT ? SET NAMES utf8 COLLATE utf8_unicode_ci, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483. Expected: 1 Actual: 2 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ``` This failure is due to `LogSubscriber` will use not connected `ActiveRecord::Base.connection` even if `Task.connection` is connected. I fixed to always pass `type_casted_binds` to log subscriber to avoid the issue.
| * | Merge pull request #29614 from kamipo/show_query_cache_keys_2Rafael França2017-06-281-1/+2
| |\ \ | | | | | | | | Show query cache keys in `test_middleware_caches`
| | * | Show query cache keys in `test_middleware_caches`Ryuta Kamizono2017-06-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | `test_middleware_caches` also failed same as #29600. https://travis-ci.org/rails/rails/jobs/248017174#L487-L489
| * | | Enable query cache if set a configurationsTsukasa OISHI2017-06-291-14/+2
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ActiveRecord query cache is available when a connection is connected. Therefore, query cache is unavailable when entering the ActiveRecord::Base.cache block without being connected. ```ruby ActiveRecord::Base.cache do Task.find(1) # access to database. Task.find(1) # access to database. unavailable query cache end ``` If we use query cache with batch script etc, we need to connect before that. ```ruby Task.connection ActiveRecord::Base.cache do Task.find(1) # access to database. Task.find(1) # available query cache end ``` Before version 3.1, query cache had been enabled if a configuration was set up. In order to solve the `DATABASE_URL` issue(#8074), ActiveRecord has checked whether a connection is connected or not. Today, ActiveRecord.configurations respect `DATABASE_URL`. https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb#L46
| * | Show query cache keys in ↵Ryuta Kamizono2017-06-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_exceptional_middleware_clears_and_disables_cache_on_error` `test_exceptional_middleware_clears_and_disables_cache_on_error` in postgresql adapter sometime fails recently. Show the query cache keys to investigte the cause. https://travis-ci.org/rails/rails/jobs/246467252#L490-L493
| * | Ensure query caching for `select_*` methods in connection adaptersRyuta Kamizono2017-06-151-0/+40
| | |
| * | Fix `Relation#exists?` queries with query cacheRyuta Kamizono2017-06-151-0/+6
| |/ | | | | | | | | | | | | | | If a connection adapter overrides `select_*` methods, query caching will doesn't work. This patch changes `select_value` to `select_one` in `Relation#exists?` to ensure query caching. Fixes #29449.
* / Only clean the connection of the current connection poolRafael Mendonça França2017-04-261-1/+1
|/ | | | This will avoid us to close the connection of the saved connection pool.
* Ensure test threads share a DB connectioneileencodes2017-02-201-0/+12
| | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* Use temporary connection pool for sqlite3_mem adapterYasuo Honda2017-01-311-11/+22
| | | | | Fixes #27826 Refer https://github.com/rails/rails/commit/f7b317175430a2d9300d9c4acfc1f34f4fdb2fbc
* Make sure to clear query cache to prevent sporadic test failureAkira Matsuda2017-01-181-0/+4
|
* oops! :scream_cat:Akira Matsuda2017-01-101-1/+1
|
* Use temporary connection pool for the tests clearing AR::Base's ↵Akira Matsuda2017-01-101-59/+92
| | | | | | | active_connections clearing AR::Base's active_connections on the "primary" pool loses connections to the in_memory DB when running sqlite3_mem tests
* Fix style guide violationsRafael Mendonça França2017-01-051-3/+3
|
* Merge pull request #25460 from maclover7/jm-uncachedSean Griffin2017-01-031-0/+21
|\ | | | | Add explicit testing for `uncached` vs. `cached`
| * Add explicit testing for `uncached` vs. `cached`Jon Moss2016-06-211-0/+21
| | | | | | | | | | | | There are a ton of middleware related tests in this file, and it seems like `cached vs. `uncached` is being neglected. Added in a test to confirm the expected behavior.
* | fix QueryCache nil dupRichard Monette2016-12-151-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | make sql statements frozen dup if arel is not our string expect runtime error dont wrap runtime error in invalid log errors will now be treated as runtime errors update changelog
* | Configure query caching (per thread) on the connection poolMatthew Draper2016-11-061-0/+34
| |
* | Clear query cache during checkin, instead of an execution callbackMatthew Draper2016-10-271-28/+68
| | | | | | | | | | | | | | It doesn't make sense for the query cache to persist while a connection moves through the pool and is assigned to a new thread. [Samuel Cochran & Matthew Draper]
* | Clear the correct query cacheSamuel Cochran2016-10-261-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This executor currently relies on `ActiveRecord::Base.connection` not changing between `prepare` and `complete`. If something else returns the current ActiveRecord connection to the pool early then this `complete` call will fail to clear the correct query cache and restore the original `query_cache_enabled` status. This has for example been happening in Sidekiq: https://github.com/mperham/sidekiq/pull/3166 We can just keep track of the connection as part of the exector state.
* | Use old typecasting method if no type casted binds are passed inAaron Patterson2016-10-201-1/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | Query cache doesn't type cast bind parameters since it isn't actually querying the database, so it can't pass those values in. Type casting in the query cache method would cause the values to be type cast twice in the case that there is a cache miss (since the methods it calls will type cast *again*). If logging is disabled, then adding the type cast code to the query cache method will needlessly typecast the values (since the only reason those values are type cast is for display in the logs). Fixes #26828.
* | Fixnum and Bignum are deprecated in Ruby trunkMatthew Draper2016-10-081-1/+1
| | | | | | | | https://bugs.ruby-lang.org/issues/12739
* | Fix "warning: assigned but unused variable - task"Ryuta Kamizono2016-08-261-1/+1
| |
* | Test that AR query cache isn't busted when types are not same objectJames Coleman2016-08-241-0/+20
| | | | | | | | | | | | | | | | | | | | This is fixed in 5.0 as an ancillary part of 574f255629a45cd67babcfb9bb8e163e091a53b8 but here I also add a test for the condition. I'd previously backported the fix (and added a test) in the below commit; this brings the fix back up to master. (cherry picked from commit fce3dbf30241f2a65c777e192a7171b0eea81453)
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-21/+21
| | | | | | | | | | 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-0/+2
| | | | | | | | | | | | Follow up to #20818. `retrieve_connection` is passed `spec_name` instead of `klass` since #24844.
* | Remove unused `ActiveRecord::Base.connection_id`Sean Griffin2016-06-291-12/+0
|/ | | | | | | | This method appears to have been partially used in connection pool caching, but it was introduced without much reasoning or any tests. One edge case test was added later on, but it was focused on implementation details. This method is no longer used outside of tests, and as such is removed.
* Fix postgresql query_cache testArthur Neves2016-06-141-0/+1
|
* Respect the current `connected?` method when calling `cache`Arthur Neves2016-06-141-0/+15
| | | | | | Before we enable query caching we check if the connection is connected. Before this fix we were always checking against the main connection, and not the model connection.
* Remove not needed line on testArthur Neves2016-06-141-1/+0
|
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-3/+2
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Publish AS::Executor and AS::Reloader APIsMatthew Draper2016-03-021-43/+13
| | | | | | These should allow external code to run blocks of user code to do "work", at a similar unit size to a web request, without needing to get intimate with ActionDipatch.
* Removed mocha from Active Record Part 1Ronak Jangir2015-08-251-32/+37
|
* PostgreSQL, Fix OID based type casts in C for primitive types.Lars Kanis2015-03-251-1/+1
| | | | | | | | | | The type map was introduced in aafee23, but wasn't properly filled. This mainly adjusts many locations, that expected strings instead of integers or boolean. add_pg_decoders is moved after setup of the StatementPool, because execute_and_clear could potentially make use of it.
* Revert ":cut: remove unnecessary rescue Exceptions"Yves Senn2015-03-061-1/+1
| | | | | | | | | | | | | | | | | This reverts commit ff18049ca6f27deb7e7f955478e1464f8d756332. This broke the AR build for every adapter: 1) Error: AssociationCallbacksTest#test_dont_add_if_before_callback_raises_exception: Exception: You can't add a post 2) Failure: QueryCacheTest#test_query_cache_doesnt_leak_cached_results_of_rolled_back_queries [/Users/senny/Projects/rails/activerecord/test/cases/query_cache_test.rb:235]: Expected: 1 Actual: 0 I'm reverting to get the build green again.
* :cut: remove unnecessary rescue ExceptionsAaron Patterson2015-03-051-1/+1
|
* Restore query cache on rollbackFlorian Weingarten2014-12-011-0/+32
|
* Make select_all on query cache accept a Relation without binds.Arthur Neves2014-03-131-0/+8
| | | | | [fixes #14361] [related #13886]
* use `teardown` for cleanup, not `setup`.Yves Senn2014-01-161-5/+2
| | | | | | | | | | | | This solves order dependent issues where the last test leaked the query cache state. This resulted in the following error: ``` QueryCacheExpiryTest#test_cache_is_expired_by_habtm_delete [test/cases/query_cache_test.rb:275]: not all expectations were satisfied unsatisfied expectations: - expected exactly twice, invoked once: #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x7f93e0c65838>.clear_query_cache(any_parameters) ```
* Currently, we clear query_cache in cache block finish, even if we may ↵Vipul A M2013-12-031-0/+9
| | | | | | already have cache true. This commit takes into account the last cache_enabled value, before clearing query_cache.