Permalink
Browse files

updated unit tests, better spec file

git-svn-id: http://code.sixapart.com/svn/memcached/trunk/server@557 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information...
1 parent 0aeb612 commit 7b573c21969d08de2d99eefbef0ddb40fa0af8c9 Paul Lindner committed May 12, 2007
Showing with 86 additions and 37 deletions.
  1. +5 −0 ChangeLog
  2. +18 −11 memcached.spec
  3. +13 −1 t/binary-get.t
  4. +33 −11 t/lib/MemcachedTest.pm
  5. +1 −11 t/maxconns.t
  6. +15 −2 t/unixsocket.t
  7. +1 −1 t/whitespace.t
View
@@ -1,3 +1,8 @@
+2007-05-10 Paul Lindner <lindner@inuus.com>
+
+ * Flesh out tests for unix domain sockets and binary data.
+ * Update rpm spec file to run tests
+
2007-05-07 Paul Lindner <lindner@inuus.com>
* Fix compilation bug on freebsd 6.x (and maybe others)
View
@@ -1,6 +1,6 @@
Name: memcached
Version: 1.2.2
-Release: 2%{?dist}
+Release: 4%{?dist}
Summary: High Performance, Distributed Memory Object Cache
Group: System Environment/Daemons
@@ -10,14 +10,13 @@ Source0: http://www.danga.com/memcached/dist/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libevent-devel
-
+BuildRequires: perl(Test::More)
+Requires: initscripts
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig, /sbin/service
Requires(postun): /sbin/service
-
%description
-
memcached is a high-performance, distributed memory object caching
system, generic in nature, but intended for use in speeding up dynamic
web applications by alleviating database load.
@@ -27,21 +26,21 @@ web applications by alleviating database load.
%build
-%configure \
- --enable-threads
+%configure --enable-threads
make %{?_smp_mflags}
%check
-# skip this for now, this requires perl and a bunch of other stuff
-# and may not work from within rpmbuild
-#make test
+make test
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
-# Perl script monitoring memcached
+# remove memcached-debug
+rm -f %{buildroot}/%{_bindir}/memcached-debug
+
+# Perl script for monitoring memcached
install -Dp -m0755 scripts/memcached-tool %{buildroot}%{_bindir}/memcached-tool
# Init script
@@ -84,12 +83,20 @@ exit 0
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%{_bindir}/memcached-tool
%{_bindir}/memcached
-%{_bindir}/memcached-debug
%{_mandir}/man1/memcached.1*
%{_initrddir}/memcached
%changelog
+* Sat May 12 2007 Paul Lindner <lindner@inuus.com> - 1.2.2-4
+- Remove tabs from spec file, rpmlint reports no more errors
+
+* Thu May 10 2007 Paul Lindner <lindner@inuus.com> - 1.2.2-3
+- Enable build-time regression tests
+- add dependency on initscripts
+- remove memcached-debug (not needed in dist)
+- above suggestions from Bernard Johnson
+
* Mon May 7 2007 Paul Lindner <lindner@inuus.com> - 1.2.2-2
- Tidyness improvements suggested by Ruben Kerkhof in bugzilla #238994
View
@@ -1,11 +1,23 @@
#!/usr/bin/perl
use strict;
-use Test::More skip_all => "Tests not written."; # tests => 1
+use Test::More tests => 8;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
my $server = new_memcached();
my $sock = $server->sock;
+my $count = 1;
+
+foreach my $blob ("mooo\0", "mumble\0\0\0\0\r\rblarg", "\0", "\r") {
+ my $key = "foo$count";
+ my $len = length($blob);
+ print "len is $len\n";
+ print $sock "set $key 0 0 $len\r\n$blob\r\n";
+ is(scalar <$sock>, "STORED\r\n", "stored $key");
+ mem_get_is($sock, $key, $blob);
+ $count++;
+}
+
View
@@ -1,6 +1,7 @@
package MemcachedTest;
use strict;
use IO::Socket::INET;
+use IO::Socket::UNIX;
use Exporter 'import';
use FindBin qw($Bin);
use Carp qw(croak);
@@ -99,18 +100,32 @@ sub new_memcached {
exit; # never gets here.
}
+ # unix domain sockets
+ if ($args =~ /-s (\S+)/) {
+ my $filename = $1;
+ my $conn = IO::Socket::UNIX->new(Peer => $filename) ||
+ croak("Failed to connect to unix domain socket");
+
+ return Memcached::Handle->new(pid => $childpid,
+ conn => $conn,
+ domainsocket => $filename,
+ port => $port);
+ }
+
+ # try to connect / find open port, only if we're not using unix domain
+ # sockets
+
for (1..20) {
- my $conn = IO::Socket::INET->new(PeerAddr => "127.0.0.1:$port");
- if ($conn) {
- return Memcached::Handle->new(pid => $childpid,
- conn => $conn,
- udpport => $udpport,
- port => $port);
- }
- select undef, undef, undef, 0.10;
+ my $conn = IO::Socket::INET->new(PeerAddr => "127.0.0.1:$port");
+ if ($conn) {
+ return Memcached::Handle->new(pid => $childpid,
+ conn => $conn,
+ udpport => $udpport,
+ port => $port);
+ }
+ select undef, undef, undef, 0.10;
}
croak("Failed to startup/connect to memcached server.");
-
}
############################################################################
@@ -130,13 +145,20 @@ sub udpport { $_[0]{udpport} }
sub sock {
my $self = shift;
- return $self->{conn} if $self->{conn} && getpeername($self->{conn});
+
+ if ($self->{conn} && ($self->{domainsocket} || getpeername($self->{conn}))) {
+ return $self->{conn};
+ }
return $self->new_sock;
}
sub new_sock {
my $self = shift;
- return IO::Socket::INET->new(PeerAddr => "127.0.0.1:$self->{port}");
+ if ($self->{domainsocket}) {
+ return IO::Socket::UNIX->new(Peer => $self->{domainsocket});
+ } else {
+ return IO::Socket::INET->new(PeerAddr => "127.0.0.1:$self->{port}");
+ }
}
sub new_udp_sock {
View
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 21;
+use Test::More tests => 11;
use FindBin qw($Bin);
use lib "$Bin/lib";
@@ -24,13 +24,3 @@ foreach my $conn (1..10) {
ok(defined($sock), "Made connection $conn");
push(@sockets, $sock);
}
-
-TODO: {
-local $TODO = "Need to decide on what -c semantics are";
-
-foreach my $conn (11..20) {
- $sock = $server->new_sock;
- ok(defined($sock), "Connection $conn");
- push(@sockets, $sock);
-}
-}
View
@@ -1,11 +1,24 @@
#!/usr/bin/perl
use strict;
-use Test::More skip_all => "Tests not written."; # tests => 1
+use Test::More tests => 3;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
-my $server = new_memcached();
+my $filename = "/tmp/memcachetest$$";
+
+my $server = new_memcached("-s $filename");
my $sock = $server->sock;
+ok(-S $filename, "creating unix domain socket $filename");
+
+# set foo (and should get it)
+print $sock "set foo 0 0 6\r\nfooval\r\n";
+
+is(scalar <$sock>, "STORED\r\n", "stored foo");
+mem_get_is($sock, "foo", "fooval");
+
+unlink($filename);
+
+## Just some basic stuff for now...
View
@@ -5,7 +5,7 @@ our @files;
BEGIN {
chdir "$Bin/.." or die;
- @files = grep {! /^config.h$/ } (glob("*.h"), glob("*.c"), glob("*.ac"));
+ @files = grep {! /^config.h$/ } (glob("*.h"), glob("*.c"), glob("*.ac"), "memcached.spec");
}
use Test::More tests => scalar(@files);

0 comments on commit 7b573c2

Please sign in to comment.