From e73c6574f3e83e2b2f5a30d899100a09a148e05d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 21 Aug 2014 15:08:15 -0300 Subject: [PATCH] [PASSED QA] Bug 12800: running unit tests that use Koha::Cache breaks cache usage from Apache If the user runs: $ prove t/Cache.t with it's system user, two situations can happen: 1) If MEMCACHED_NAMESPACE is set on koha-httpd.xml other than the default 'koha', then Apache sets /tmp/sharefile-koha- and the problem is not present: running the test creates /tmp/sharefile-koha-koha != /tmp/sharefile-koha- => SUCCESS: no problem 2) If MEMCACHED_NAMESPACE is not set (or eq 'koha'), then there is a permission problem either running the unit tests, or when using any funcitonality on the UI that needs Koha::Cache. Explanation: the one that is run first will set the /tmp/sharefile-koha-koha ownership so it will be either the dev's sys user, or www-data (or whatever apache is using). This patch sets a namespace for the unit tests, so there is no collision. To test: - On your dev setup, having MEMCACHED_NAMESPACE unset on koha-httpd.conf - Edit a marc framework. If it fails, remove /tmp/sharefile-koha-koha, and try again -> fixed. Now try running $ prove t/Cache.t => FAIL: test fails because of permission problem - Apply the patch - Re-run the test => SUCCESS: test passes Try changing the order, etc. The temporary file that is used is deleted after the tests are run. Sponsored-by: Universidad Nacional de Cordoba Signed-off-by: Chris Cormack Signed-off-by: Kyle M Hall --- t/Cache.t | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-) diff --git a/t/Cache.t b/t/Cache.t index 65cf52b..4c50a2b 100644 --- a/t/Cache.t +++ b/t/Cache.t @@ -1,9 +1,21 @@ #!/usr/bin/perl -# Tests Koha::Cache and whichever type of cache is enabled (through Koha::Cache) - -use strict; -use warnings; +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; use Test::More tests => 32; @@ -16,6 +28,9 @@ BEGIN { } SKIP: { + # Set a special namespace for testing, to avoid breaking + # if test is run with a different user than Apache's. + $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests'; my $cache = Koha::Cache->get_instance(); skip "Cache not enabled", 28 @@ -151,9 +166,14 @@ SKIP: { END { SKIP: { + $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests'; my $cache = Koha::Cache->get_instance(); skip "Cache not enabled", 1 unless ( $cache->is_cache_active() ); is( $destructorcount, 1, 'Destructor run exactly once' ); + # cleanup temporary file + my $tmp_file = $cache->{ fastmmap_cache }->{ share_file }; + unlink $tmp_file if defined $tmp_file; + } } -- 1.7.2.5