Bugzilla – Attachment 92931 Details for
Bug 13193
Make Memcached usage fork safe
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[Draft] Integration test Koha::Cache and memcached
Draft-Integration-test-KohaCache-and-memcached.patch (text/plain), 3.55 KB, created by
David Cook
on 2019-09-18 05:03:42 UTC
(
hide
)
Description:
[Draft] Integration test Koha::Cache and memcached
Filename:
MIME Type:
Creator:
David Cook
Created:
2019-09-18 05:03:42 UTC
Size:
3.55 KB
patch
obsolete
>From 83f33c5ff60e3edf80b300495e280141c174fa09 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Wed, 18 Sep 2019 15:01:34 +1000 >Subject: [PATCH] [Draft] Integration test Koha::Cache and memcached > >This test is not 100% reliable. When run with Cache::Memcached::Fast, >it will usually generate errors, but not always. > >When run with Cache::Memcached::Fast::Safe, it never generates errors. > >https://bugs.koha-community.org/show_bug.cgi?id=13193 >--- > t/02-memcached.t | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 102 insertions(+) > create mode 100644 t/02-memcached.t > >diff --git a/t/02-memcached.t b/t/02-memcached.t >new file mode 100644 >index 0000000000..77491135d3 >--- /dev/null >+++ b/t/02-memcached.t >@@ -0,0 +1,102 @@ >+#!/usr/bin/perl >+ >+use strict; >+use warnings; >+ >+use Koha::Caches; >+use Test::More tests => 1; >+use Cache::Memcached::Fast; >+use IO::Select; >+ >+my $cache = Koha::Caches->get_instance('syspref'); >+ >+my $map = { >+ 'syspref_timeout' => '1d', >+ 'syspref_independentbranches' => '0', >+ 'syspref_version' => '18.1101000' >+}; >+#Set keys for test >+foreach my $key ( keys %$map ){ >+ $cache->set_in_cache($key,$map->{$key}); >+} >+ >+my @children = (); >+my $select = IO::Select->new(); >+for ( 1..10 ){ >+ my ($read_child,$write_parent); >+ pipe($read_child,$write_parent); >+ my $pid = fork; >+ if ($pid == 0){ >+ close($read_child); >+ my $a_problems = check_cache({ >+ keys => ["syspref_version","syspref_timeout","syspref_independentbranches"], >+ iterations => int(rand(50)), >+ }); >+ my $b_problems = check_cache({ >+ keys => ["syspref_version","syspref_timeout","syspref_independentbranches"], >+ iterations => int(rand(50)), >+ }); >+ my $c_problems = check_cache({ >+ keys => ["syspref_version","syspref_timeout","syspref_independentbranches"], >+ iterations => int(rand(50)), >+ }); >+ my $total_problems = $a_problems + $b_problems + $c_problems; >+ >+ print $write_parent "$total_problems\n"; >+ close($write_parent); >+ exit; >+ } >+ else { >+ close($write_parent); >+ $select->add($read_child); >+ push(@children,$pid); >+ } >+} >+ >+my $problems = 0; >+while ( my @ready = $select->can_read(.25) ){ >+ foreach my $fh (@ready){ >+ my $msg = <$fh>; >+ if ($msg){ >+ chomp($msg); >+ $problems += $msg; >+ $select->remove($fh); >+ $fh->close; >+ } >+ } >+} >+ >+foreach my $child (@children){ >+ waitpid($child,0); >+} >+warn "Finished $problems\n"; >+is($problems,0,"There should be no problems reported."); >+ >+sub check_cache { >+ my ($args) = @_; >+ my $problems = 0; >+ my $keys = $args->{keys}; >+ my $iterations = $args->{iterations}; >+ if ($keys && defined $iterations){ >+ $iterations++; >+ for ( 1 .. $iterations ){ >+ my $index = int(rand(3)); >+ my $key = $keys->[$index]; >+ my $cached_value = $cache->get_from_cache($key); >+ Koha::Caches->flush_L1_caches(); >+ my $problem = ""; >+ if ( ! defined $cached_value ){ >+ $cached_value = 'NULL'; >+ $problem = 1; >+ } >+ elsif ($cached_value ne $map->{$key}){ >+ $problem = 1; >+ } >+ if ($problem){ >+ $problems++; >+ warn "Process:$$\t Key: $key\t Correct value: $map->{$key}\t Cached value: $cached_value\n"; >+ } >+ } >+ } >+ return $problems; >+} >-- >2.16.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13193
:
92827
|
92835
|
92867
|
92868
|
92926
|
92931
|
98546
|
98550