Build.PL000644001750001750 350612234075635 15614 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use warnings; use utf8; use Module::Build; use File::Basename; use File::Spec; use CPAN::Meta; use CPAN::Meta::Prereqs; my %args = ( license => 'perl', dynamic_config => 0, configure_requires => { 'Module::Build' => 0.38, }, name => 'Test-TCP', module_name => 'Test::TCP', allow_pureperl => 0, script_files => [glob('script/*'), glob('bin/*')], c_source => [qw()], PL_files => {}, test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', recursive_test_files => 1, ); if (-d 'share') { $args{share_dir} = 'share'; } my $builder = Module::Build->subclass( class => 'MyBuilder', code => q{ sub ACTION_distmeta { die "Do not run distmeta. Install Minilla and `minil install` instead.\n"; } sub ACTION_installdeps { die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n"; } } )->new(%args); $builder->create_build_script(); my $mbmeta = CPAN::Meta->load_file('MYMETA.json'); my $meta = CPAN::Meta->load_file('META.json'); my $prereqs_hash = CPAN::Meta::Prereqs->new( $meta->prereqs )->with_merged_prereqs( CPAN::Meta::Prereqs->new($mbmeta->prereqs) )->as_string_hash; my $mymeta = CPAN::Meta->new( { %{$meta->as_struct}, prereqs => $prereqs_hash } ); print "Merging cpanfile prereqs to MYMETA.yml\n"; $mymeta->save('MYMETA.yml', { version => 1.4 }); print "Merging cpanfile prereqs to MYMETA.json\n"; $mymeta->save('MYMETA.json', { version => 2 }); Changes000644001750001750 1362612234075635 15637 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02Revision history for Perl extension Test::TCP 2.02 2013-10-30T03:22:39Z - Fixed fork(2) error handling. (tokuhirom) 2.01 2013-09-22T04:13:53Z commit 95cd6a0669d422e10f2d3b09f35346c86f7e3257 Author: Christian Walde Date: Sat Sep 21 16:19:49 2013 +0200 test waitport argument by running full code-chain, not with partial mocking The partial mocks cause stuck forks on win32 at times, causing the test to hang. With the full code chain present the test runs reliably 2.00 2013-06-11T04:41:43Z [INCOMPATIBLE CHANGES] - Change wait_port() API to take max_wait seconds, and wait exponentially. Dropped wait_port_retry argument introduced at 1.27. (miyagawa) 1.30 2013-06-03T05:06:28Z - Increase the default sleep and retry: 0.01 sec and 1000 times (miyagawa) 1.29 2013-05-29T01:12:47Z - Care the `test_tcp(port => undef)` case. https://github.com/tokuhirom/Test-TCP/issues/13 1.28 2013-05-28T11:14:27Z - Added wait_port_sleep and wait_port_retry option for Test::TCP::wait_port, Test::TCP#new, test_tcp(). (tokuhirom) 1.27 2013-05-15T10:13:18Z - export wait_port from Net::EmptyPort (Pavel Shaydo) - Make default wait_port() sleeping time shorter. 0.1sec => 0.0001sec. (tokuhirom) 1.26 2013-03-29T08:46:20Z - Remove unused deps from cpanfile. 1.25 2013-03-29T08:07:24Z - re packaging, again & again 1.24 2013-03-28T02:49:32Z - re-packing, again. 1.23 2013-03-27T01:37:08Z - Just re-packaging 1.22 2013-03-27T01:17:38Z - Add doc for Test::TCP::CheckPort (Tatsuhiko Miyagawa) - revert b4fc237697648234c960f6714d995210d4250e42 to fix Win32 breakage Test::TCP::CheckPort must be used on win32 because it prints to STDOUT (Christian Walde) - Add UDP support to Net::EmptyPort (Brendan Byrd) 1.21 2013-03-03T12:33:49 - Added Net::EmptyPort::wait_port() (tokuhirom) 1.20 2013-03-02T18:30:25 - bump up version 1.19 2013-02-27T14:02:13 - Split empty_port() function to Net::EmptyPort (Thomas Klausner) 1.18 - Added more documentation about empty_port() 1.17 commit 0f4510d83ae2f2ce112288c64289fa36d32865b3 Author: Christian Walde Date: Sat Jul 28 07:04:40 2012 +0200 fix port checking on Win32 by performing it in another process On Win32 fork is emulating by creating another thread in the same process. This leads to a possible bug/race condition when a server tries to open a port and listen on it, while in the same process a client tries to connect to the same port. This manifests by the accept call of the server failing with an error of "Bad file descriptor". This is easily fixed by having another process perform the port checking, since that will not interfere with the internals. 1.16 [TEST FIX] - 1.15 breaks AIX fix on 1.14. t/05_sigint.t skips on perl <= 5.8.8. 1.15 [TEST FIX] ${^CHILD_ERROR_NATIVE} is only available in perl 5.8.9 and later. (kazeburo++) 1.14 - Fixed testing issue on AIX. https://rt.cpan.org/Public/Bug/Display.html?id=72779 (w.phillip.moore) - depend to Test::SharedFork 0.19 for better TB2 support (tokuhirom) 1.13 - RT#67292: Tests are blocking in Windows 7. https://rt.cpan.org/Ticket/Display.html?id=67292 - change port number range from 10000 .. 11000 to 50000 .. 60000 to respect IANA. https://rt.cpan.org/Ticket/Display.html?id=64012 1.12 - workaround for win32 test fails. https://rt.cpan.org/Ticket/Display.html?id=66016 - more diagnostic messages 1.11 - localize $@ in Test::TCP::DESTROY 1.10 - added Test::TCP->stop method 1.09 - added document in FAQ section 1.08 - no feature changes 1.07_01 - new OO interface! 1.07 - allow forking in the client(lestrrat) 1.06 - depend to Test::SharedFork 0.14. It fixes issue with Test::Builder2. 1.05 - workaround for $@ issue in test case. Data::Util's method modifier clears $@. 1.04 - fixed local $@ issue. this happens on some version of perl5. 1.03 - release to cpan - fixed win32 issue(charsbar) 1.02_02 - use randomness on finding empty port(suggested by kazuhooku) - try to connect the port before bind(Tatsuhiko Miyagawa) 1.02_01 - better cleanup code by RAII pattern. https://rt.cpan.org/Ticket/Display.html?id=60657 (reported by dgl) 1.02 - lazy loading issue was fixed at Test::SharedFork 0.12. Depend to it. https://rt.cpan.org/Public/Bug/Display.html?id=60426 (reported by J.) 1.01 - remove unused deps for use_test_base(). 1.00 - bump up version! 0.16_02 - oops. packaging miss. 0.16_01 - Do not depend to IO::Socket::INET 1.31. Test::TCP works well with older IO, I hope. (suggested by mst) 0.16 - check port asap(suggested by Hideki YAMAMURA) 0.15 - fixed win32 issue(by charsbar++) 0.14 - support win32 0.13 - handle sigint(reported by kazuho++) 0.12 - fixed broken test on solaris 0.11 - fixed broken test, reported by drangon3++ 0.10 - don't leak the process when get a SIGDIE - diag when get SIGPIPE 0.09 - don't leak the control by SIGTERM, some tcp server return the control by SIGTERM. (reported by kazuho++) 0.08 - oops. I forget to remove 'use Params::Validate' statement. 0.07 - diag when get a SIGABRT 0.06 - pass the pid to client(kazuho) - remove deps for Params::Validate(tokuhirom) 0.05 - updated docs - set ReuseAddr as true 0.04 - Test::SharedFork 0.03 has a bug. depend to 0.04 0.03 - do not depend to Sub::Exporter - use Test::SharedFork 0.02 - fixed deps for Sub::Exporter(by yappo++) 0.01 Sun Aug 17 15:00:46 2008 - original version LICENSE000644001750001750 4377012234075635 15354 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02This software is copyright (c) 2013 by Tokuhiro Matsuno . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Tokuhiro Matsuno . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program 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 1, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Tokuhiro Matsuno . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End META.json000644001750001750 542312234075635 15741 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02{ "abstract" : "testing TCP program", "author" : [ "Tokuhiro Matsuno " ], "dynamic_config" : 0, "generated_by" : "Minilla/v0.7.5", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-TCP", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "configure" : { "requires" : { "CPAN::Meta" : "0", "CPAN::Meta::Prereqs" : "0", "Module::Build" : "0.38" } }, "develop" : { "requires" : { "File::Which" : "0", "Perl::Critic" : "1.105", "Test::CPAN::Meta" : "0", "Test::MinimumVersion" : "0.10108", "Test::Perl::Critic" : "1.02", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "IO::Socket::INET" : "0", "Test::More" : "0", "Test::SharedFork" : "0.19", "Time::HiRes" : "0", "perl" : "5.008001" } }, "test" : { "requires" : { "File::Temp" : "0", "Socket" : "0", "Test::More" : "0.98" } } }, "provides" : { "Net::EmptyPort" : { "file" : "lib/Net/EmptyPort.pm" }, "Test::TCP" : { "file" : "lib/Test/TCP.pm", "version" : "2.02" }, "Test::TCP::CheckPort" : { "file" : "lib/Test/TCP/CheckPort.pm" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/tokuhirom/Test-TCP/issues" }, "homepage" : "https://github.com/tokuhirom/Test-TCP", "repository" : { "url" : "git://github.com/tokuhirom/Test-TCP.git", "web" : "https://github.com/tokuhirom/Test-TCP" } }, "version" : "2.02", "x_contributors" : [ "tokuhirom ", "mattn ", "yappo ", "奥 一穂 ", "gfx ", "Kenichi Ishigaki ", "lestrrat ", "Masahiro Nagano ", "Thomas Klausner ", "Brendan Byrd ", "Pavel Shaydo ", "Tatsuhiko Miyagawa ", "Christian Walde " ] } README.md000644001750001750 1045712234075635 15622 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02# NAME Test::TCP - testing TCP program # SYNOPSIS use Test::TCP; my $server = Test::TCP->new( code => sub { my $port = shift; ... }, ); my $client = MyClient->new(host => '127.0.0.1', port => $server->port); undef $server; # kill child process on DESTROY Using memcached: use Test::TCP; my $memcached = Test::TCP->new( code => sub { my $port = shift; exec $bin, '-p' => $port; die "cannot execute $bin: $!"; }, ); my $memd = Cache::Memcached->new({servers => ['127.0.0.1:' . $memcached->port]}); ... And functional interface is available: use Test::TCP; test_tcp( client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $port = shift; # run server }, ); # DESCRIPTION Test::TCP is test utilities for TCP/IP programs. # METHODS - test\_tcp Functional interface. test_tcp( client => sub { my $port = shift; # send request to the server }, server => sub { my $port = shift; # run server }, # optional port => 8080, max_wait => 3, # seconds ); - wait\_port wait_port(8080); Waits for a particular port is available for connect. # OO-ish interface - my $server = Test::TCP->new(%args); Create new instance of Test::TCP. Arguments are following: - $args{auto\_start}: Boolean Call `$server->start()` after create instance. Default: true - $args{code}: CodeRef The callback function. Argument for callback function is: `$code->($pid)`. This parameter is required. - $args{max\_wait} : Number Will wait for at most `$max_wait` seconds before checking port. See also [Net::EmptyPort](http://search.cpan.org/perldoc?Net::EmptyPort). _Default: 10_ - $server->start() Start the server process. Normally, you don't need to call this method. - $server->stop() Stop the server process. - my $pid = $server->pid(); Get the pid of child process. - my $port = $server->port(); Get the port number of child process. # FAQ - How to invoke two servers? You can call test\_tcp() twice! test_tcp( client => sub { my $port1 = shift; test_tcp( client => sub { my $port2 = shift; # some client code here }, server => sub { my $port2 = shift; # some server2 code here }, ); }, server => sub { my $port1 = shift; # some server1 code here }, ); Or use OO-ish interface instead. my $server1 = Test::TCP->new(code => sub { my $port1 = shift; ... }); my $server2 = Test::TCP->new(code => sub { my $port2 = shift; ... }); # your client code here. ... - How do you test server program written in other languages like memcached? You can use `exec()` in child process. use strict; use warnings; use utf8; use Test::More; use Test::TCP 1.08; use File::Which; my $bin = scalar which 'memcached'; plan skip_all => 'memcached binary is not found' unless defined $bin; my $memcached = Test::TCP->new( code => sub { my $port = shift; exec $bin, '-p' => $port; die "cannot execute $bin: $!"; }, ); use Cache::Memcached; my $memd = Cache::Memcached->new({servers => ['127.0.0.1:' . $memcached->port]}); $memd->set(foo => 'bar'); is $memd->get('foo'), 'bar'; done_testing; # AUTHOR Tokuhiro Matsuno # THANKS TO kazuhooku dragon3 charsbar Tatsuhiko Miyagawa lestrrat # SEE ALSO # LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. cpanfile000644001750001750 57512234075635 16007 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02requires 'perl', 5.008_001; requires 'IO::Socket::INET'; requires 'Test::SharedFork', '0.19'; requires 'Test::More'; requires 'Time::HiRes'; on test => sub { requires 'Test::More', '0.98'; requires 'File::Temp'; requires 'Socket'; }; on develop => sub { requires 'Perl::Critic', '1.105'; requires 'Test::Perl::Critic', '1.02'; requires 'File::Which'; }; EmptyPort.pm000644001750001750 1106012234075635 20127 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/lib/Netpackage Net::EmptyPort; use strict; use warnings; use base qw/Exporter/; use IO::Socket::INET; use Time::HiRes (); our @EXPORT = qw/ empty_port check_port wait_port /; # get a empty port on 49152 .. 65535 # http://www.iana.org/assignments/port-numbers sub empty_port { my $port = do { if (defined $_[0]) { my $p = $_[0]; $p = 49152 unless $p =~ /^[0-9]+$/ && $p < 49152; $p; } else { 50000 + int(rand()*1000); } }; my $proto = $_[1] ? lc($_[1]) : 'tcp'; while ( $port++ < 60000 ) { # Remote checks don't work on UDP, and Local checks would be redundant here... next if ($proto eq 'tcp' && check_port($port)); my $sock = IO::Socket::INET->new( (($proto eq 'udp') ? () : (Listen => 5)), LocalAddr => '127.0.0.1', LocalPort => $port, Proto => $proto, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ); return $port if $sock; } die "empty port not found"; } sub check_port { my $port = $_[0]; my $proto = $_[1] ? lc($_[1]) : 'tcp'; # for TCP, we do a remote port check # for UDP, we do a local port check, like empty_port does my $sock = ($proto eq 'tcp') ? IO::Socket::INET->new( Proto => 'tcp', PeerAddr => '127.0.0.1', PeerPort => $port, ) : IO::Socket::INET->new( Proto => $proto, LocalAddr => '127.0.0.1', LocalPort => $port, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ) ; if ($sock) { close $sock; return 1; # The port is used. } else { return 0; # The port is not used. } } sub _make_waiter { my $max_wait = shift; my $waited = 0; my $sleep = 0.001; return sub { return 0 if $waited > $max_wait; Time::HiRes::sleep($sleep); $waited += $sleep; $sleep *= 2; return 1; }; } sub wait_port { my ($port, $max_wait, $proto); if (@_==4) { # backward compat. ($port, (my $sleep), (my $retry), $proto) = @_; $max_wait = $max_wait*$retry; $proto = $proto ? lc($proto) : 'tcp'; } else { ($port, $max_wait, $proto) = @_; $proto = $proto ? lc($proto) : 'tcp'; } my $waiter = _make_waiter($max_wait); while ( $waiter->() ) { if ($^O eq 'MSWin32' ? `$^X -MTest::TCP::CheckPort -echeck_port $port $proto` : check_port( $port, $proto )) { return 1; } } return 0; } 1; __END__ =encoding utf8 =head1 NAME Net::EmptyPort - find a free TCP/UDP port =head1 SYNOPSIS use Net::EmptyPort qw(empty_port check_port); # get a random free port my $port = empty_port(); # check if a port is already used if (check_port(5000)) { say "Port 5000 already in use"; } =head1 DESCRIPTION Net::EmptyPort helps finding an empty TCP/UDP port. =head1 METHODS =over 4 =item C<< empty_port() >> my $port = empty_port(); Get the available port number, you can use. Normally, empty_port() finds empty port number from 49152..65535. See L But you want to use another range, use a following form: # 5963..65535 my $port = empty_port(5963); You can also find an empty UDP port by specifying the protocol as the second parameter: my $port = empty_port(1024, 'udp'); # use 49152..65535 range my $port = empty_port(undef, 'udp'); =item C<< check_port($port:Int) >> my $true_or_false = check_port(5000); Checks if the given port is already in use. Returns true if it is in use (i.e. if the port is NOT free). Returns false if the port is free. Also works for UDP: my $true_or_false = check_port(5000, 'udp'); =item C<< wait_port($port:Int[, $max_wait:Number,$proto:String]) >> Waits for a particular port is available for connect. This method waits the C<< $port >> number is ready to accept a request. C<$port> is a port number to check. Sleep up to C<$max_wait> seconds for checking the port. I : Return true if the port is available, false otherwise. B: Before 2.0, C<< wait_port($port:Int[, $sleep:Number, $retry:Int, $proto:String]) >> is a signature. =back =head1 AUTHOR Tokuhiro Matsuno Etokuhirom@gmail.comE =head1 THANKS TO kazuhooku dragon3 charsbar Tatsuhiko Miyagawa lestrrat =head1 SEE ALSO =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut TCP.pm000644001750001750 1745512234075635 17021 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/lib/Testpackage Test::TCP; use strict; use warnings; use 5.00800; our $VERSION = '2.02'; use base qw/Exporter/; use IO::Socket::INET; use Test::SharedFork 0.12; use Test::More (); use Config; use POSIX; use Time::HiRes (); use Carp (); use Net::EmptyPort qw(empty_port check_port); our @EXPORT = qw/ empty_port test_tcp wait_port /; # process does not die when received SIGTERM, on win32. my $TERMSIG = $^O eq 'MSWin32' ? 'KILL' : 'TERM'; sub test_tcp { my %args = @_; for my $k (qw/client server/) { die "missing madatory parameter $k" unless exists $args{$k}; } my $server_code = delete $args{server}; my $port = delete($args{port}) || empty_port(); my $client_code = delete $args{client}; my $server = Test::TCP->new( code => $server_code, port => $port, %args, ); $client_code->($server->port, $server->pid); undef $server; # make sure } sub wait_port { my ($port, $max_wait); if (@_==3) { # backward compat ($port, (my $sleep), (my $retry)) = @_; $max_wait = $sleep * $retry; } else { ($port, $max_wait) = @_; } $max_wait ||= 10; Net::EmptyPort::wait_port($port, $max_wait) or die "cannot open port: $port"; } # ------------------------------------------------------------------------- # OO-ish interface sub new { my $class = shift; my %args = @_==1 ? %{$_[0]} : @_; Carp::croak("missing mandatory parameter 'code'") unless exists $args{code}; my $self = bless { auto_start => 1, max_wait => 10, _my_pid => $$, %args, }, $class; $self->{port} = empty_port() unless exists $self->{port}; $self->start() if $self->{auto_start}; return $self; } sub pid { $_[0]->{pid} } sub port { $_[0]->{port} } sub start { my $self = shift; my $pid = fork(); die "fork() failed: $!" unless defined $pid; if ( $pid ) { # parent process. $self->{pid} = $pid; Test::TCP::wait_port($self->port, $self->{max_wait}); return; } else { # child process $self->{code}->($self->port); # should not reach here if (kill 0, $self->{_my_pid}) { # warn only parent process still exists warn("[Test::TCP] Child process does not block(PID: $$, PPID: $self->{_my_pid})"); } exit 0; } } sub stop { my $self = shift; return unless defined $self->{pid}; return unless $self->{_my_pid} == $$; # This is a workaround for win32 fork emulation's bug. # # kill is inherently unsafe for pseudo-processes in Windows # and the process calling kill(9, $pid) may be destabilized # The call to Sleep will decrease the frequency of this problems # # SEE ALSO: # http://www.gossamer-threads.com/lists/perl/porters/261805 # https://rt.cpan.org/Ticket/Display.html?id=67292 Win32::Sleep(0) if $^O eq "MSWin32"; # will relinquish the remainder of its time slice kill $TERMSIG => $self->{pid}; Win32::Sleep(0) if $^O eq "MSWin32"; # will relinquish the remainder of its time slice local $?; # waitpid modifies original $?. LOOP: while (1) { my $kid = waitpid( $self->{pid}, 0 ); if ($^O ne 'MSWin32') { # i'm not in hell if (POSIX::WIFSIGNALED($?)) { my $signame = (split(' ', $Config{sig_name}))[POSIX::WTERMSIG($?)]; if ($signame =~ /^(ABRT|PIPE)$/) { Test::More::diag("your server received SIG$signame"); } } } if ($kid == 0 || $kid == -1) { last LOOP; } } undef $self->{pid}; } sub DESTROY { my $self = shift; local $@; $self->stop(); } 1; __END__ =for stopwords OO-ish =encoding utf8 =head1 NAME Test::TCP - testing TCP program =head1 SYNOPSIS use Test::TCP; my $server = Test::TCP->new( code => sub { my $port = shift; ... }, ); my $client = MyClient->new(host => '127.0.0.1', port => $server->port); undef $server; # kill child process on DESTROY Using memcached: use Test::TCP; my $memcached = Test::TCP->new( code => sub { my $port = shift; exec $bin, '-p' => $port; die "cannot execute $bin: $!"; }, ); my $memd = Cache::Memcached->new({servers => ['127.0.0.1:' . $memcached->port]}); ... And functional interface is available: use Test::TCP; test_tcp( client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $port = shift; # run server }, ); =head1 DESCRIPTION Test::TCP is test utilities for TCP/IP programs. =head1 METHODS =over 4 =item test_tcp Functional interface. test_tcp( client => sub { my $port = shift; # send request to the server }, server => sub { my $port = shift; # run server }, # optional port => 8080, max_wait => 3, # seconds ); =item wait_port wait_port(8080); Waits for a particular port is available for connect. =back =head1 OO-ish interface =over 4 =item my $server = Test::TCP->new(%args); Create new instance of Test::TCP. Arguments are following: =over 4 =item $args{auto_start}: Boolean Call C<< $server->start() >> after create instance. Default: true =item $args{code}: CodeRef The callback function. Argument for callback function is: C<< $code->($pid) >>. This parameter is required. =item $args{max_wait} : Number Will wait for at most C<$max_wait> seconds before checking port. See also L. I =back =item $server->start() Start the server process. Normally, you don't need to call this method. =item $server->stop() Stop the server process. =item my $pid = $server->pid(); Get the pid of child process. =item my $port = $server->port(); Get the port number of child process. =back =head1 FAQ =over 4 =item How to invoke two servers? You can call test_tcp() twice! test_tcp( client => sub { my $port1 = shift; test_tcp( client => sub { my $port2 = shift; # some client code here }, server => sub { my $port2 = shift; # some server2 code here }, ); }, server => sub { my $port1 = shift; # some server1 code here }, ); Or use OO-ish interface instead. my $server1 = Test::TCP->new(code => sub { my $port1 = shift; ... }); my $server2 = Test::TCP->new(code => sub { my $port2 = shift; ... }); # your client code here. ... =item How do you test server program written in other languages like memcached? You can use C in child process. use strict; use warnings; use utf8; use Test::More; use Test::TCP 1.08; use File::Which; my $bin = scalar which 'memcached'; plan skip_all => 'memcached binary is not found' unless defined $bin; my $memcached = Test::TCP->new( code => sub { my $port = shift; exec $bin, '-p' => $port; die "cannot execute $bin: $!"; }, ); use Cache::Memcached; my $memd = Cache::Memcached->new({servers => ['127.0.0.1:' . $memcached->port]}); $memd->set(foo => 'bar'); is $memd->get('foo'), 'bar'; done_testing; =back =head1 AUTHOR Tokuhiro Matsuno Etokuhirom@gmail.comE =head1 THANKS TO kazuhooku dragon3 charsbar Tatsuhiko Miyagawa lestrrat =head1 SEE ALSO =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut CheckPort.pm000644001750001750 124412234075635 20650 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/lib/Test/TCPpackage Test::TCP::CheckPort; use strict; use warnings; use base qw/Exporter/; use Net::EmptyPort qw(); our @EXPORT = qw/ check_port /; sub check_port { print Net::EmptyPort::check_port( @ARGV ) } 1; __END__ =head1 NAME Test::TCP::CheckPort - check if a port is open from command line =head1 SYNOPSIS $^X -MTest::TCP::CheckPort -echeck_port 8080 =head1 DESCRIPTION This is a wrapper for L which checks if a given port is open, from the command line argument (C<@ARGV>). Because it works with port numbers in the argument list, you don't need to quote it when running with the perl executable. =head1 SEE ALSO L L =cut 00_compile.t000644001750001750 15712234075635 16656 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use Test::More tests => 1; BEGIN { use_ok 'Test::TCP' } diag "Test::More: $Test::More::VERSION"; 01_simple.t000644001750001750 171212234075635 16536 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse warnings; use strict; use Test::More tests => 22; use Test::TCP; use IO::Socket::INET; use t::Server; test_tcp( client => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; my $sock = IO::Socket::INET->new( PeerPort => $port, PeerAddr => '127.0.0.1', Proto => 'tcp' ) or die "Cannot open client socket: $!"; note "send 1"; print {$sock} "foo\n"; my $res = <$sock>; is $res, "foo\n"; note "send 2"; print {$sock} "bar\n"; my $res2 = <$sock>; is $res2, "bar\n"; note "finalize"; print {$sock} "quit\n"; }, server => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; t::Server->new($port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }, ); 02_abrt.t000644001750001750 153612234075635 16202 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use warnings; use Test::TCP; use Test::More; use Socket; use IO::Socket::INET; use t::Server; plan skip_all => "win32 doesn't support embedded function named dump()" if $^O eq 'MSWin32'; plan tests => 2; test_tcp( client => sub { my $port = shift; my $sock = IO::Socket::INET->new( PeerPort => $port, PeerAddr => '127.0.0.1', Proto => 'tcp' ) or die "Cannot open client socket: $!"; print {$sock} "dump\n"; my $res = <$sock>; is $res, "dump\n"; $sock->close(); ok 1; }, server => sub { my $port = shift; t::Server->new($port)->run(sub { my ($remote, $line) = @_; print {$remote} $line; if ($line =~ /dump/) { return CORE::dump() } }); }, ); 03_return_when_sigterm.t000644001750001750 211412234075635 21336 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse warnings; use strict; use Test::More tests => 2; use Test::TCP; use t::Server; # ABOUT: some tcp server related software returns control when received SIGTERM instead of exit. # This test emulate it's situation. test_tcp( client => sub { ok 1; # nop... but after this statement, Test::TCP send SIGTERM to server process. }, server => sub { my $port = shift; my $sock = new_sock($port); my $term_received = 0; $SIG{TERM} = sub { $term_received++ }; while ($term_received == 0) { my $csock = $sock->accept; if ($csock) { $csock->close(); } } # suppress warnings: [Test::TCP] Child process does not block(PID: 84792, PPID: 84791) # I do it on purpose! $SIG{__WARN__} = sub { }; }, ); if ($?) { # It's maybe ActivePerl's bug. # http://ppm4.activestate.com/MSWin32-x86/5.12/1200/T/TO/TOKUHIROM/Test-TCP-1.11.d/log-20101221T221845.txt diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } ok 1, 'test finished.'; 04_die.t000644001750001750 144412234075635 16013 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse warnings; use strict; use Test::More tests => 3; use Test::TCP; use IO::Socket::INET; use t::Server; my $child_pid; eval { test_tcp( client => sub { my ($port, $pid) = @_; $child_pid = $pid; sleep 3; # wait till the server actually starts die "sinamon"; }, server => sub { my $port = shift; t::Server->new($port)->run(sub { }); }, ); }; my $e = $@; ok $e; like $e, qr/sinamon/; my $killed = kill 9, $child_pid; is $killed, 0, "already killed by test_tcp"; if ($?) { # It's maybe ActivePerl's bug. # http://ppm4.activestate.com/MSWin32-x86/5.12/1200/T/TO/TOKUHIROM/Test-TCP-1.11.d/log-20101221T221845.txt diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } 05_sigint.t000644001750001750 466312234075635 16556 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use warnings; use Test::TCP; use IO::Socket::INET; use POSIX; use Test::More; use Config; plan skip_all => "this test requires SIGUSR1" unless $Config{sig_name} =~ /USR1/; plan skip_all => "Perl<5.8.8 does not supports \${^CHILD_ERROR_NATIVE}" if $] <= 5.008008; plan tests => 2; my $pid = Test::SharedFork->fork; # my $killed_server = 0; # $SIG{USR1} = sub { $killed_server = 1 }; if ($pid > 0) { sleep 1; kill 'INT', $pid; waitpid($pid, 0); # NOTE. $? is broken on AIX platform. see also __END__ comments on this file. ok POSIX::WIFSIGNALED(${^CHILD_ERROR_NATIVE}); is [split / /, $Config{sig_name}]->[POSIX::WTERMSIG(${^CHILD_ERROR_NATIVE})], 'INT', "sigint"; # ok $killed_server, "really killed"; } elsif ($pid == 0) { # $SIG{CHLD} = sub { # kill 'USR1', POSIX::getppid(); # }; test_tcp( client => sub { sleep 3; }, server => sub { my $port = shift; my $sock = IO::Socket::INET->new( LocalAddr => '127.0.0.1', LocalPort => $port, Listen => 5, ReuseAddr => 1, ) or die $!; sleep 6; }, ); fail "should not reach here"; } else { die 'sucks'; } __END__ Following comments are copy & paste from : https://rt.cpan.org/Public/Bug/Display.html?id=72779 The test suite passes for RHEL5 and Solaris 10, but fails on AIX 6. The results are independent of the core perl version. The test failure output is: [efsops@shou18l560-02 Test-TCP-1.13]$ perl -Mblib t/05_sigint.t 1..2 ok 1 not ok 2 - sigint # Failed test 'sigint' # at t/05_sigint.t line 20. # got: 'ZERO' # expected: 'INT' # Looks like you failed 1 test of 2. The reason for the failure is somewhat subtle. On AIX, the value assigned to $? by wiatpid can not be passed to the POSIX functions. However, if the ${^CHILD_ERROR_NATIVE} value is used, then this works fine, and on ALL of the above platforms. While the root cause of this problem is likely a bug in perl related to how $? is handled internally, the patch I've provided seems correct when you consider that the documentation for CHILD_ERROR_NATIVE specifically documents THIS variable (and not $?/$CHILD_ERROR) as the one to pass to the POSIX functions. I suspect that passing $? works for backwards compatibility, but clearly, it doesn't work on ALL platforms, and the core perl tests seem to reflect this as well. 06_nest.t000644001750001750 114312234075635 16221 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use warnings; use Test::TCP; use Test::More tests => 1; use t::Server; test_tcp( client => sub { my $port1 = shift; test_tcp( client => sub { my $port2 = shift; isnt $port1, $port2, "$port1, $port2"; }, server => sub { my $port2 = shift; t::Server->new($port2)->run; }, ); }, server => sub { my $port1 = shift; t::Server->new($port1)->run; }, ); if ($?) { diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } 07_optional.t000644001750001750 26012234075635 17055 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse Test::More tests => 2; ok( 1, 'One' ); SKIP: { eval { require Test::SharedFork }; skip 'Test::SharedFork needed for tests', 1 if $@; ok( 2, 'Two' ); } 1; 08_exit.t000644001750001750 236512234075635 16232 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use warnings; use Test::More tests => 5; use Test::TCP; use File::Temp (); use Fcntl qw/:seek/; use t::Server; use POSIX; my $tmp = File::Temp->new(); my $pid = fork(); die "cannot fork: $!" unless defined $pid; if ($pid) { # parent # waiting 'client' SKIP: { waitpid($pid, 0); skip 'not implemented on Win32', 4 if $^O eq 'MSWin32'; ok WIFEXITED($?); ok !WIFSIGNALED($?); ok !WIFSTOPPED($?); is WEXITSTATUS($?), 1; } # killing 'server' { seek $tmp, 0, SEEK_SET; my $child_pid = do { local $/; <$tmp> }; is kill(($^O eq 'MSWin32' ? 'KILL' : 'TERM'), $child_pid), 0; my $kid; do { $kid = waitpid($child_pid, 0); } while $kid > 0; } } else { # child test_tcp( client => sub { my $port = shift; note "CLIENT: $$"; exit 1; }, server => sub { my $port = shift; note "SEVER: $$"; print {$tmp} $$; $tmp->close; t::Server->new($port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }, ); } 09_fork.t000644001750001750 300412234075635 16212 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use Test::More tests => 6; use Test::TCP; use t::Server; test_tcp client => sub { my $port = shift; my $pid = fork(); if (! ok defined $pid, "Successfully forked child $pid") { return diag("Could not fork: $!"); } if (! $pid) { eval { ok 1, "Successfully executed child $$"; }; my $e = $@; if (! ok !$e, "child exited normally") { diag( "Encountered an error $e" ); } exit; } waitpid($pid, 0); # after the child has exited, we need to make sure that # the server hasn't gone away. my $sock = IO::Socket::INET->new( PeerPort => $port, PeerAddr => '127.0.0.1', Proto => 'tcp' ); if (! ok $sock, "socket is connected") { return diag("Cannot open client socket: $!"); } print {$sock} "Hello server\n"; my $res = <$sock>; is $res, "Hello server\n", "got expected reply"; }, server => sub { my $port = shift; t::Server->new($port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); } ; if ($?) { # It's maybe ActivePerl's bug. # http://ppm4.activestate.com/MSWin32-x86/5.12/1200/T/TO/TOKUHIROM/Test-TCP-1.11.d/log-20101221T221845.txt diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } 10_oo.t000644001750001750 205312234075635 15661 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse warnings; use strict; use Test::More tests => 22; use Test::TCP; use IO::Socket::INET; use t::Server; my $server = Test::TCP->new( code => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; t::Server->new($port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); } ); ok $server->port, "test case for sharedfork" for 1..10; my $sock = IO::Socket::INET->new( PeerPort => $server->port, PeerAddr => '127.0.0.1', Proto => 'tcp' ) or die "Cannot open client socket: $!"; note "send 1"; print {$sock} "foo\n"; my $res = <$sock>; is $res, "foo\n"; note "send 2"; print {$sock} "bar\n"; my $res2 = <$sock>; is $res2, "bar\n"; note "finalize"; print {$sock} "quit\n"; if ($?) { # It's maybe ActivePerl's bug. # http://ppm4.activestate.com/MSWin32-x86/5.12/1200/T/TO/TOKUHIROM/Test-TCP-1.11.d/log-20101221T221845.txt diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } done_testing; 11_net_empty_port.t000644001750001750 56412234075635 20302 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use warnings; use Test::More; use Net::EmptyPort; my $port = empty_port; ok $port, "found an empty port"; ok !wait_port( $port, 0.1 ), "port is closed"; my $sock = IO::Socket::INET->new( LocalAddr => '127.0.0.1', LocalPort => $port, Listen => 1, ) or die "Couldn't create socket: $!"; ok wait_port( $port, 3 ), "port is open"; done_testing; 12_pass_wait_port_options.t000644001750001750 357412234075635 22070 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse strict; use warnings; use utf8; use Test::More; use Test::TCP; use IO::Socket::INET; use t::Server; my ($port, $max_wait); my $old = \&Net::EmptyPort::wait_port; my $return = sub { 1 }; { no warnings 'redefine'; *Net::EmptyPort::wait_port = sub { ($port, $max_wait) = @_; $return->(@_); }; } # Test::TCP::wait_port arguments are passed to Net::EmptyPort::wait_port. { Test::TCP::wait_port(1, 1); is($max_wait, 1); } $return = sub { $old->(@_) }; my $server = sub { my $port = shift; ok $port, "test case for sharedfork" for 1 .. 10; t::Server->new($port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }; my $client = sub { my $port = shift; ok $port, "test case for sharedfork" for 1 .. 10; my $sock = IO::Socket::INET->new( PeerPort => $port, PeerAddr => '127.0.0.1', Proto => 'tcp' ) or die "Cannot open client socket: $!"; note "send 1"; print {$sock} "foo\n"; my $res = <$sock>; is $res, "foo\n"; note "send 2"; print {$sock} "bar\n"; my $res2 = <$sock>; is $res2, "bar\n"; note "finalize"; print {$sock} "quit\n"; }; # Test::TCP#new arguments are passed to Net::EmptyPort::wait_port. { my $tcp = Test::TCP->new( code => $server, max_wait => 3, ); $client->($tcp->port); if ($?) { # It's maybe ActivePerl's bug. # http://ppm4.activestate.com/MSWin32-x86/5.12/1200/T/TO/TOKUHIROM/Test-TCP-1.11.d/log-20101221T221845.txt diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } is($max_wait, 3); } # test_tcp() arguments are passed to Net::EmptyPort::wait_port. { test_tcp( client => $client, server => $server, max_wait => 2, ); is($max_wait, 2); } done_testing; 13_undef_port.t000644001750001750 174312234075635 17421 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tuse warnings; use strict; use Test::More tests => 22; use Test::TCP; use IO::Socket::INET; use t::Server; test_tcp( client => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; my $sock = IO::Socket::INET->new( PeerPort => $port, PeerAddr => '127.0.0.1', Proto => 'tcp' ) or die "Cannot open client socket: $!"; note "send 1"; print {$sock} "foo\n"; my $res = <$sock>; is $res, "foo\n"; note "send 2"; print {$sock} "bar\n"; my $res2 = <$sock>; is $res2, "bar\n"; note "finalize"; print {$sock} "quit\n"; }, server => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; t::Server->new($port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }, port => undef, # XXX ); Server.pm000644001750001750 137212234075635 16366 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/tpackage t::Server; use strict; use warnings; use base qw/Exporter/; use IO::Socket::INET; our @EXPORT = qw/new_sock/; sub new_sock { my $port = shift; my $sock = IO::Socket::INET->new( LocalPort => $port, LocalAddr => '127.0.0.1', Proto => 'tcp', Listen => 5, Type => SOCK_STREAM, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ) or die "Cannot open server socket: $!"; return $sock; } sub new { my ($class, $port) = @_; my $sock = new_sock($port); bless { sock => $sock }, $class; } sub run { my ($self, $code) = @_; while (my $remote = $self->{sock}->accept) { while (my $line = <$remote>) { $code->($remote, $line); } } } 1; 02_perlcritic.t000644001750001750 240312234075635 17574 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/xtuse strict; use warnings; use Test::More; eval { require Perl::Critic; Perl::Critic->VERSION(1.105); require Test::Perl::Critic; Test::Perl::Critic->VERSION(1.02); Test::Perl::Critic->import( -profile => \(join q{}, ) ); }; note $@ if $@; plan skip_all => "Perl::Critic 1.105+ or Test::Perl::Critic 1.02+ is not installed." if $@; all_critic_ok('lib', 'script', 'bin'); __END__ only=1 # ------------------------------------------------------------------------- # Not important. [BuiltinFunctions::ProhibitSleepViaSelect] [BuiltinFunctions::RequireGlobFunction] [ClassHierarchies::ProhibitOneArgBless] # ------------------------------------------------------------------------- # Bug detection [InputOutput::ProhibitBarewordFileHandles] [Modules::RequireFilenameMatchesPackage] [Subroutines::ProhibitNestedSubs] [Subroutines::ProhibitReturnSort] [TestingAndDebugging::RequireUseStrict] [Variables::ProhibitConditionalDeclarations] [Variables::RequireLexicalLoopIterators] [TestingAndDebugging::ProhibitNoStrict] allow=refs # ------------------------------------------------------------------------- # Security issue detection [InputOutput::RequireEncodingWithUTF8Layer] [Modules::ProhibitEvilModules] [InputOutput::ProhibitTwoArgOpen] 04_dependents.t000644001750001750 101712234075635 17567 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/xtuse strict; use warnings; use Test::More 0.98; BEGIN { plan skip_all => "AUTHOR_TESTING is required." unless $ENV{AUTHOR_TESTING}; } use File::Which; use File::Temp qw(tempdir); plan skip_all => "No cpanm" unless which('cpanm'); local $ENV{PERL_CPANM_OPT} = '--no-man-pages --no-prompt --no-interactive'; my $tmp = tempdir(CLEANUP => 1); is(system("cpanm --notest -l $tmp ."), 0); for (qw(Monoceros Plack POSIX::getpeername Starman Dancer2)) { is(system("cpanm -l $tmp --reinstall $_"), 0, $_); } done_testing; 11_net_emptyport.t000644001750001750 253312234075635 21653 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02/xt/authoruse warnings; use strict; use Test::More tests => 11; use Net::EmptyPort qw(empty_port check_port); use IO::Socket::INET; # This UDP test case does not portable if there is DNS cache server. my ($port, $new_port, $sock); foreach my $proto_uc ('TCP', 'UDP') { my $proto = lc $proto_uc; $port = empty_port(5000, $proto); ok( $port, $proto_uc.': port found via empty_port' ); diag "Port: $port - $proto"; $sock = new_ok( 'IO::Socket::INET' => [ (($proto eq 'udp') ? () : (Listen => 5)), LocalAddr => '127.0.0.1', LocalPort => $port, Proto => $proto, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ] ); $new_port = empty_port($port, $proto); isnt( $new_port, $port, $proto_uc.': different port found via empty_port' ); diag "New port: $new_port - $proto"; $sock->close; $sock = new_ok( 'IO::Socket::INET' => [ (($proto eq 'udp') ? () : (Listen => 5)), LocalAddr => '127.0.0.1', LocalPort => $port, PeerAddr => '127.0.0.1', PeerPort => $new_port, Proto => $proto, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ] ); is( check_port($port) , 0, $proto_uc.': check_port($port) == 0') if ($proto eq 'udp'); is( check_port($new_port), 0, $proto_uc.': check_port($new_port) == 0'); $sock->close; } 1; META.yml000644001750001750 320512234075635 15565 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02--- abstract: 'testing TCP program' author: - 'Tokuhiro Matsuno ' build_requires: File::Temp: 0 Socket: 0 Test::More: 0.98 configure_requires: CPAN::Meta: 0 CPAN::Meta::Prereqs: 0 Module::Build: 0.38 dynamic_config: 0 generated_by: 'Minilla/v0.7.5, CPAN::Meta::Converter version 2.132510' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Test-TCP no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: Net::EmptyPort: file: lib/Net/EmptyPort.pm Test::TCP: file: lib/Test/TCP.pm version: 2.02 Test::TCP::CheckPort: file: lib/Test/TCP/CheckPort.pm requires: IO::Socket::INET: 0 Test::More: 0 Test::SharedFork: 0.19 Time::HiRes: 0 perl: 5.008001 resources: bugtracker: https://github.com/tokuhirom/Test-TCP/issues homepage: https://github.com/tokuhirom/Test-TCP repository: git://github.com/tokuhirom/Test-TCP.git version: 2.02 x_contributors: - 'tokuhirom ' - 'mattn ' - 'yappo ' - '奥 一穂 ' - 'gfx ' - 'Kenichi Ishigaki ' - 'lestrrat ' - 'Masahiro Nagano ' - 'Thomas Klausner ' - 'Brendan Byrd ' - 'Pavel Shaydo ' - 'Tatsuhiko Miyagawa ' - 'Christian Walde ' MANIFEST000644001750001750 66612234075635 15435 0ustar00tokuhiromtokuhirom000000000000Test-TCP-2.02Build.PL Changes LICENSE META.json README.md cpanfile lib/Net/EmptyPort.pm lib/Test/TCP.pm lib/Test/TCP/CheckPort.pm t/00_compile.t t/01_simple.t t/02_abrt.t t/03_return_when_sigterm.t t/04_die.t t/05_sigint.t t/06_nest.t t/07_optional.t t/08_exit.t t/09_fork.t t/10_oo.t t/11_net_empty_port.t t/12_pass_wait_port_options.t t/13_undef_port.t t/Server.pm xt/02_perlcritic.t xt/04_dependents.t xt/author/11_net_emptyport.t META.yml MANIFEST