From 738ca3595fb88580a84072b31ce8a999af4762d6 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 22 Apr 2021 15:32:22 +0200 Subject: [PATCH] Eagerly close Dalli connections in MemCachedStoreTest Otherwise the test suite is flaky when ran repeatedly on the same machine because of file descriptors exhaustion. --- .../test/cache/stores/mem_cache_store_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/activesupport/test/cache/stores/mem_cache_store_test.rb b/activesupport/test/cache/stores/mem_cache_store_test.rb index fa0437ecc3..968c600deb 100644 --- a/activesupport/test/cache/stores/mem_cache_store_test.rb +++ b/activesupport/test/cache/stores/mem_cache_store_test.rb @@ -36,7 +36,9 @@ class MemCacheStoreTest < ActiveSupport::TestCase end def lookup_store(options = {}) - ActiveSupport::Cache.lookup_store(*store, { namespace: @namespace }.merge(options)) + cache = ActiveSupport::Cache.lookup_store(*store, { namespace: @namespace }.merge(options)) + (@_stores ||= []) << cache + cache end def setup @@ -48,6 +50,15 @@ class MemCacheStoreTest < ActiveSupport::TestCase @cache.logger = ActiveSupport::Logger.new(File::NULL) end + def after_teardown + stores, @_stores = @_stores, [] + stores.each do |store| + # Eagerly closing Dalli connection avoid file descriptor exhaustion. + # Otherwise the test suite is flaky when ran repeatedly + store.instance_variable_get(:@data).close + end + end + include CacheStoreBehavior include CacheStoreVersionBehavior include CacheStoreCoderBehavior