Changes100644000766000024 2417013547042705 14475 0ustar00miyagawastaff000000000000Test-TCP-2.22Revision history for Perl module Test::TCP 2.22 2019-10-08T08:15:34Z - Portability fixes for Win32 and non-linux #83, #87 2.21 2019-10-03T03:15:22Z - Fix race condition in check_port(UDP) #78 2.20 2019-08-03T22:47:58Z - Fix test for . not in @INC by default #58 2.19 2017-05-11T13:02:47Z commit aac1b06c1e3b0d73ca964794bab0c444d454ebcc Author: Yasuhiro Matsumoto Date: Thu May 11 18:40:13 2017 +0900 don't run command when the port is empty Test::TCP do hack on Windows for checking port used. https://github.com/tokuhirom/Test-TCP/commit/0f4510d8 But this way always return 0 with succeeded with empty port. This is not expected behavior. So this change fix to call check_port if the port is not defined. fixes #60 2.18 2017-04-24T06:00:25Z - let the kernel select an empty port #59 https://github.com/tokuhirom/Test-TCP/pull/59 (i110) 2.17 2016-08-18T14:42:56Z - check_port can take 'host' argument(#55) - Fix test on Windows issue(#55) 2.16 2016-04-13T02:27:43Z commit 3ae73a349f70f06c60de3f635916929bc8643429 Author: Alex Vandiver Date: Tue Apr 12 00:33:21 2016 -0700 Ensure that IO::Socket::IP is DESTROY'd before can_bind returns be316f1f worked around a core perl bug[1] which causes Perl < 5.24.0 to DESTROY the IO::Socket::IP object too late, causing the empty port to not actually be empty if it was used immediately. Unfortunately, this change was lost in ba745fd1, which again put the return of `can_bind` on the stack along with the actual return value, re-instating the bug. Split the statement across two statements again, and add a comment on the importance of preserving it. [1] https://rt.perl.org/Public/Bug/Display.html?id=124248 2.15 2016-03-15T00:25:52Z - Add listen_socket function and listen option for race-free operation 2.14 2015-09-29T22:36:44Z - Fix race condition in t/10_oo.t(exodist) 2.13 2015-07-24T02:30:17Z - check whether the OS implements IPV6_V6ONLY before using it 2.12 2015-05-18T08:14:30Z - Fixed spelling mistake (Reported by gregor herrmann) 2.11 2015-04-07T00:07:25Z - declare IO::Socket::IP as dependency #36 2.10 2015-04-06T19:23:43Z - ensure the test object is DESTROYed when Net::EmptyPort::empty_port exits https://rt.cpan.org/Public/Bug/Display.html?id=103299 2.09 2015-04-02T21:55:18Z - fix tests running for a long time on systems that do not support IPv6 #35 2.08 2015-04-02T04:04:33Z - add `host` argument to various functions for binding to arbitrary address (incl. IPv6) #33 - add function `Net::EmptyPort::can_bind` #34 2.07 2015-01-22T10:44:21Z Old versions of Test::SharedFork are incompatibles with the new Test::Builder: I had "missing TB2::History" errors. It would be helpful to upgrade the Test::SharedFork dependency to help the user to avoid to encounter such hard to track deep errors. (Reported by dolmen++) 2.06 2014-07-01T10:01:44Z commit 8259d5eb28919bc766c8b500151d5be7e944b7f2 Author: Petr Písař Date: Fri Jun 27 13:37:20 2014 +0200 Wait infinitely if max_wait is negative The t/12_pass_wait_port_options.t will fail if the server process does not start listening in max_wait limit. This can happen if the host is loaded or just if the scheduler decides to postpone the process. This patch adds possibility to wait infitely by passing a negative max_wait value to the Test::TCP object and it changes the t/12_pass_wait_port_options.t test to use this feature. https://github.com/tokuhirom/Test-TCP/issues/28 Signed-off-by: Petr Písař 2.05 2014-06-24T00:49:45Z - Release again with latest minil. 2.04 2014-06-23T23:42:28Z - Release. 2.03_02 2014-06-23T23:37:07Z - Release to CPAN. 2.03_01 2014-06-23T23:34:38Z - Switch to ExtUtils::MakeMaker. 2.03 2014-06-23T10:18:53Z - Re-packaging with Minilla v2.0.0-TRIAL 2.02 2013-10-30T03:22:39Z - Fixed fork(2) error handling. (tokuhirom) 2.01 2013-09-22T04:13:53Z [Changes from MITHALDU (Christian Walde)] - 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 2012-10-25 - Added more documentation about empty_port() 1.17 2012-07-27 [Changes from MITHALDU (Christian Walde)] - 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 2012-06-30 [TEST FIX] - 1.15 breaks AIX fix on 1.14. t/05_sigint.t skips on perl <= 5.8.8. 1.15 2012-01-31 [TEST FIX] - ${^CHILD_ERROR_NATIVE} is only available in perl 5.8.9 and later. (kazeburo++) 1.14 2011-11-29 - 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 2011-05-31 - 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 2011-03-03 - workaround for win32 test fails. https://rt.cpan.org/Ticket/Display.html?id=66016 - more diagnostic messages 1.11 2010-12-20 - localize $@ in Test::TCP::DESTROY 1.10 2010-12-18 - added Test::TCP->stop method 1.09 2010-12-18 - added document in FAQ section 1.08 2010-12-16 - no feature changes 1.07_01 2010-12-16 - new OO interface! 1.07 2010-11-11 - allow forking in the client(lestrrat) 1.06 2010-09-11 - depend to Test::SharedFork 0.14. It fixes issue with Test::Builder2. 1.05 2010-09-10 - workaround for $@ issue in test case. Data::Util's method modifier clears $@. 1.04 2010-08-24 - fixed local $@ issue. this happens on some version of perl5. 1.03 2010-08-23 - release to cpan - fixed win32 issue(charsbar) 1.02_02 2010-08-23 - use randomness on finding empty port(suggested by kazuhooku) - try to connect the port before bind(Tatsuhiko Miyagawa) 1.02_01 2010-08-23 - better cleanup code by RAII pattern. https://rt.cpan.org/Ticket/Display.html?id=60657 (reported by dgl) 1.02 2010-08-17 - 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 2010-08-15 - remove unused deps for use_test_base(). 1.00 2010-08-08 - bump up version! 0.16_02 2010-02-20 - oops. packaging miss. 0.16_01 2010-02-20 - Do not depend to IO::Socket::INET 1.31. Test::TCP works well with older IO, I hope. (suggested by mst) 0.16 2010-01-04 - check port asap(suggested by Hideki YAMAMURA) 0.15 2009-11-28 - fixed win32 issue(by charsbar++) 0.14 2009-10-18 - support win32 0.13 2009-10-14 - handle sigint(reported by kazuho++) 0.12 2009-10-04 - fixed broken test on solaris 0.11 2009-09-17 - fixed broken test, reported by drangon3++ 0.10 2009-09-17 - don't leak the process when get a SIGDIE - diag when get SIGPIPE 0.09 2009-09-15 - don't leak the control by SIGTERM, some tcp server return the control by SIGTERM. (reported by kazuho++) 0.08 2009-09-14 - oops. I forget to remove 'use Params::Validate' statement. 0.07 2009-09-13 - diag when get a SIGABRT 0.06 2009-09-08 - pass the pid to client(kazuho) - remove deps for Params::Validate(tokuhirom) 0.05 2009-06-22 - updated docs - set ReuseAddr as true 0.04 2009-03-25 - Test::SharedFork 0.03 has a bug. depend to 0.04 0.03 2009-03-25 - do not depend to Sub::Exporter - use Test::SharedFork 0.02 2008-08-28 - fixed deps for Sub::Exporter(by yappo++) 0.01 2008-08-17 - original version LICENSE100644000766000024 4377013547042705 14216 0ustar00miyagawastaff000000000000Test-TCP-2.22This 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 MANIFEST.SKIP100644000766000024 7213547042705 15013 0ustar00miyagawastaff000000000000Test-TCP-2.22.appveyor.yml .travis.yml cpanfile minil.toml .git .build META.json100644000766000024 714413547042705 14605 0ustar00miyagawastaff000000000000Test-TCP-2.22{ "abstract" : "testing TCP program", "author" : [ "Tokuhiro Matsuno " ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.1.4", "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" : { "ExtUtils::MakeMaker" : "6.64" } }, "develop" : { "requires" : { "File::Which" : "0", "Perl::Critic" : "1.105", "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.04", "Test::Perl::Critic" : "1.02", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "IO::Socket::INET" : "0", "IO::Socket::IP" : "0", "Test::More" : "0", "Test::SharedFork" : "0.29", "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.22" }, "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.22", "x_contributors" : [ "Alex Vandiver ", "Andrii Melnykov ", "Bartosz Jakubski ", "Brendan Byrd ", "Chad Granum ", "Christian Walde ", "Dagfinn Ilmari Mannsåker ", "David Precious ", "Ichito Nagata ", "Ivan Baidakou ", "Kazuho Oku ", "Kenichi Ishigaki ", "Kent Fredric ", "Masahiro Nagano ", "Mohammad S Anwar ", "Neil Bowers ", "Pavel Shaydo ", "Pete Houston ", "Petr Písař ", "Syohei YOSHIDA ", "Tatsuhiko Miyagawa ", "Tatsuhiko Miyagawa ", "Thomas Klausner ", "Yasuhiro Matsumoto ", "gfx ", "lestrrat ", "mattn ", "openstrike ", "richard.leach ", "yappo ", "奥 一穂 " ], "x_static_install" : 1 } Makefile.PL100644000766000024 152713547042705 15135 0ustar00miyagawastaff000000000000Test-TCP-2.22# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.006; use strict; use ExtUtils::MakeMaker 6.64; my %WriteMakefileArgs = ( NAME => 'Test::TCP', DISTNAME => 'Test-TCP', VERSION => '2.22', EXE_FILES => [glob('script/*'), glob('bin/*')], CONFIGURE_REQUIRES => { "ExtUtils::MakeMaker" => "6.64" } , BUILD_REQUIRES => {} , TEST_REQUIRES => { "File::Temp" => 0, "Socket" => 0, "Test::More" => "0.98" } , PREREQ_PM => { "IO::Socket::INET" => 0, "IO::Socket::IP" => 0, "Test::More" => 0, "Test::SharedFork" => "0.29", "Time::HiRes" => 0, "perl" => "5.008001" } , ); WriteMakefile(%WriteMakefileArgs); README.md100644000766000024 1444713547042705 14467 0ustar00miyagawastaff000000000000Test-TCP-2.22# NAME Test::TCP - testing TCP program # SYNOPSIS use Test::TCP; my $server = Test::TCP->new( listen => 1, code => sub { my $socket = shift; ... }, ); my $client = MyClient->new(host => '127.0.0.1', port => $server->port); undef $server; # kill child process on DESTROY If using a server that can only accept a port number, e.g. 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]}); ... **N.B.**: This is vulnerable to race conditions, if another process binds to the same port after [Net::EmptyPort](https://metacpan.org/pod/Net::EmptyPort) found it available. And functional interface is available: use Test::TCP; test_tcp( listen => 1, client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $socket = shift; # run server, calling $socket->accept }, ); test_tcp( client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $port = shift; # run server, binding to $port }, ); # DESCRIPTION Test::TCP is a test utility to test TCP/IP-based server programs. # METHODS - test\_tcp Functional interface. test_tcp( listen => 1, client => sub { my $port = shift; # send request to the server }, server => sub { my $socket = shift; # run server }, # optional host => '127.0.0.1', # specify '::1' to test using IPv6 port => 8080, max_wait => 3, # seconds ); If `listen` is false, `server` is instead passed a port number that was free before it was called. - wait\_port wait_port(8080); Waits for a particular port is available for connect. # Object Oriented 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->($socket)` or `$code->($port)`, depending on the value of `listen`. This parameter is required. - $args{max\_wait} : Number Will wait for at most `$max_wait` seconds before checking port. See also [Net::EmptyPort](https://metacpan.org/pod/Net::EmptyPort). _Default: 10_ - $args{listen} : Boolean If true, open a listening socket and pass this to the callback. Otherwise find a free port and pass the number of it to the callback. - $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 the OO 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; - How do I use address other than "127.0.0.1" for testing? You can use the `host` parameter to specify the bind address. # let the server bind to "0.0.0.0" for testing test_tcp( client => sub { ... }, server => sub { ... }, host => '0.0.0.0', ); - How should I write IPv6 tests? You should use the ["can\_bind" in Net::EmptyPort](https://metacpan.org/pod/Net::EmptyPort#can_bind) function to check if the program can bind to the loopback address of IPv6, as well as the `host` parameter of the ["test\_tcp"](#test_tcp) function to specify the same address as the bind address. use Net::EmptyPort qw(can_bind); plan skip_all => "IPv6 not available" unless can_bind('::1'); test_tcp( client => sub { ... }, server => sub { ... }, host => '::1', ); # 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. EmptyPort.pm100644000766000024 2176613547042705 17007 0ustar00miyagawastaff000000000000Test-TCP-2.22/lib/Netpackage Net::EmptyPort; use strict; use warnings; use base qw/Exporter/; use Errno qw/ECONNREFUSED/; use Fcntl; use IO::Socket::IP; use Time::HiRes (); our @EXPORT = qw/ can_bind empty_port check_port wait_port /; our @EXPORT_OK = qw/ listen_socket /; sub can_bind { my ($host, $port, $proto) = @_; # The following must be split across two statements, due to # https://rt.perl.org/Public/Bug/Display.html?id=124248 my $s = _listen_socket($host, $port, $proto); return defined $s; } sub _listen_socket { my ($host, $port, $proto) = @_; $port ||= 0; $proto ||= 'tcp'; IO::Socket::IP->new( (($proto eq 'udp') ? () : (Listen => 5)), LocalAddr => $host, LocalPort => $port, Proto => $proto, V6Only => 1, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ); } sub listen_socket { my ($host, $proto) = @{$_[0]}{qw(host proto)}; $host = '127.0.0.1' unless defined $host; return _listen_socket($host, undef, $proto); } # get a empty port on 49152 .. 65535 # http://www.iana.org/assignments/port-numbers sub empty_port { my ($host, $port, $proto) = @_ && ref $_[0] eq 'HASH' ? ($_[0]->{host}, $_[0]->{port}, $_[0]->{proto}) : (undef, @_); $host = '127.0.0.1' unless defined $host; $proto = $proto ? lc($proto) : 'tcp'; if (defined $port) { # to ensure lower bound, check one by one in order $port = 49152 unless $port =~ /^[0-9]+$/ && $port < 49152; while ( $port++ < 65000 ) { # Remote checks don't work on UDP, and Local checks would be redundant here... next if ($proto eq 'tcp' && check_port({ host => $host, port => $port })); return $port if can_bind($host, $port, $proto); } } else { # kernel will select an unused port while ( my $sock = _listen_socket($host, undef, $proto) ) { $port = $sock->sockport; $sock->close; next if ($proto eq 'tcp' && check_port({ host => $host, port => $port })); return $port; } } die "empty port not found"; } sub check_port { my ($host, $port, $proto) = @_ && ref $_[0] eq 'HASH' ? ($_[0]->{host}, $_[0]->{port}, $_[0]->{proto}) : (undef, @_); $host = '127.0.0.1' unless defined $host; return _check_port_udp($host, $port) if $proto && lc($proto) eq 'udp'; # TCP, check if possible to connect my $sock = IO::Socket::IP->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port, V6Only => 1, ); if ($sock) { close $sock; return 1; # The port is used. } else { return 0; # The port is not used. } } sub _check_port_udp { my ($host, $port) = @_; # send some UDP data and see if ICMP error is being sent back (i.e. ECONNREFUSED) my $sock = IO::Socket::IP->new( Proto => 'udp', PeerAddr => $host, PeerPort => $port, V6Only => 1, Blocking => 0, ) or die "failed to create bound UDP socket:$!"; $sock->send("0", 0) or die "failed to send a UDP packet:$!"; my ($rfds, $efds) = ('', ''); vec($rfds, fileno($sock), 1) = 1; vec($efds, fileno($sock), 1) = 1; select $rfds, undef, $efds, 0.1; # after 0.1 second of silence, we assume that the server is up my $up = defined($sock->recv(my $data, 1000)) || ( ($^O eq 'MSWin32') ? ($^E != Errno::WSAECONNRESET() && $^E != Errno::WSAECONNREFUSED()) : ($! != ECONNREFUSED) ); close $sock; $up; } sub _make_waiter { my $max_wait = shift; my $waited = 0; my $sleep = 0.001; return sub { return 0 if $max_wait >= 0 && $waited > $max_wait; Time::HiRes::sleep($sleep); $waited += $sleep; $sleep *= 2; return 1; }; } sub wait_port { my ($host, $port, $max_wait, $proto); if (@_ && ref $_[0] eq 'HASH') { ($host, $port, $max_wait, $proto) = ($_[0]->{host}, $_[0]->{port}, $_[0]->{max_wait}, $_[0]->{proto}); } elsif (@_==4) { # backward compat. ($port, (my $sleep), (my $retry), $proto) = @_; $max_wait = $sleep * $retry; } else { ($port, $max_wait, $proto) = @_; } $host = '127.0.0.1' unless defined $host; $max_wait ||= 10; $proto = $proto ? lc($proto) : 'tcp'; my $waiter = _make_waiter($max_wait); while ( $waiter->() ) { if ($^O eq 'MSWin32' && defined($port) ? `$^X -MTest::TCP::CheckPort -echeck_port $host $port $proto` : check_port({ host => $host, port => $port, proto => $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 socket listening on a random free port my $socket = listen_socket(); # 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<< listen_socket() >> =item C<< listen_socket(\%args) >> my $socket = listen_socket(); Returns a socket listening on a free port. The function recognizes the following keys in the hashref argument. =over 4 =item C<< host >> The address on which to listen. Default is C<< 127.0.0.1 >>. =item C<< proto >> Name of the protocol. Default is C<< tcp >>. You can get an UDP socket by specifying C<< udp >>. =back =item C<< empty_port() >> =item C<< empty_port(\%args) >> =item C<< empty_port($port) >> =item C<< empty_port($port, $proto) >> my $port = empty_port(); Returns a port number that is NOT in use. The function recognizes the following keys when given a hashref as the argument. =over 4 =item C<< host >> specifies the address on which the search should be performed. Default is C<< 127.0.0.1 >>. =item C<< port >> Lower bound of the search for an empty port. If omitted, the function searches for an empty port within 49152..65535. See L =item C<< proto >> Name of the protocol. Default is C<< tcp >>. You can find an empty UDP port by specifying C<< udp >>. =back To maintain backwards compatibility, the function accepts scalar arguments as well. For example, 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(\%args) >> =item C<< check_port($port) >> =item C<< check_port($port, $proto) >> 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. The function recognizes the following keys when given a hashref as the argument. When UDP is specified as the protocol, the `check_port` function sends a probe UDP packet to the designated port to see if an ICMP error message is returned, which indicates that the port is unassigned. The port is assumed to be assigned, unless such response is observed within 0.1 seconds. =over 4 =item C<< host >> specifies the address on which the search should be performed. Default is C<< 127.0.0.1 >>. =item C<< port >> specifies the port to check. This argument is mandatory. =item C<< proto >> name of the protocol. Default is C<< tcp >>. =back To maintain backwards compatibility, the function accepts scalar arguments as well in the form described above. =item C<< wait_port(\%args) >> =item C<< wait_port($port) >> =item C<< wait_port($port, $max_wait) >> =item C<< wait_port($port, $max_wait, $proto) >> Waits until a particular port becomes ready to connect to. Returns true if the port becomes ready, or false if otherwise. The function recognizes the following keys when given a hashref as the argument. =over 4 =item C<< host >> specifies the address on which the search should be performed. Default is C<< 127.0.0.1 >>. =item C<< port >> specifies the port to check. This argument is mandatory. =item C<< max_wait >> maximum seconds to wait for (default is 10 seconds). Pass a negative value to wait infinitely. =item C<< proto >> name of the protocol. Default is C<< tcp >>. =back To maintain backwards compatibility, the function accepts scalar arguments as well in the form described above. B: Before 2.0, C<< wait_port($port:Int[, $sleep:Number, $retry:Int, $proto:String]) >> is a signature. =item C<< can_bind($host) >> =item C<< can_bind($host, $port) >> =item C<< can_bind($host, $port, $proto) >> Checks if the application is capable of binding to given port. =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.pm100644000766000024 2417713547042705 15662 0ustar00miyagawastaff000000000000Test-TCP-2.22/lib/Testpackage Test::TCP; use strict; use warnings; use 5.00800; our $VERSION = '2.22'; use base qw/Exporter/; 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 mandatory parameter $k" unless exists $args{$k}; } my $server_code = delete $args{server}; my $client_code = delete $args{client}; my $server = Test::TCP->new( code => $server_code, %args, ); $client_code->($server->port, $server->pid); undef $server; # make sure } sub wait_port { my ($host, $port, $max_wait); if (@_ && ref $_[0] eq 'HASH') { $host = $_[0]->{host}; $port = $_[0]->{port}; $max_wait = $_[0]->{max_wait}; } elsif (@_ == 3) { # backward compat ($port, (my $sleep), (my $retry)) = @_; $max_wait = $sleep * $retry; } else { ($port, $max_wait) = @_; } $host = '127.0.0.1' unless defined $host; $max_wait ||= 10; Net::EmptyPort::wait_port({ host => $host, port => $port, max_wait => $max_wait }) or die "cannot open port: $host:$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, host => '127.0.0.1', _my_pid => $$, %args, }, $class; if ($self->{listen}) { $self->{socket} ||= Net::EmptyPort::listen_socket({ host => $self->{host}, proto => $self->{proto}, }) or die "Cannot listen: $!"; $self->{port} = $self->{socket}->sockport; } else { $self->{port} ||= empty_port({ host => $self->{host} }); } $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({ host => $self->{host}, port => $self->port, max_wait => $self->{max_wait} }) unless $self->{socket}; return; } else { # child process $self->{code}->($self->{socket} || $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 loopback =encoding utf8 =head1 NAME Test::TCP - testing TCP program =head1 SYNOPSIS use Test::TCP; my $server = Test::TCP->new( listen => 1, code => sub { my $socket = shift; ... }, ); my $client = MyClient->new(host => '127.0.0.1', port => $server->port); undef $server; # kill child process on DESTROY If using a server that can only accept a port number, e.g. 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]}); ... B: This is vulnerable to race conditions, if another process binds to the same port after L found it available. And functional interface is available: use Test::TCP; test_tcp( listen => 1, client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $socket = shift; # run server, calling $socket->accept }, ); test_tcp( client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $port = shift; # run server, binding to $port }, ); =head1 DESCRIPTION Test::TCP is a test utility to test TCP/IP-based server programs. =head1 METHODS =over 4 =item test_tcp Functional interface. test_tcp( listen => 1, client => sub { my $port = shift; # send request to the server }, server => sub { my $socket = shift; # run server }, # optional host => '127.0.0.1', # specify '::1' to test using IPv6 port => 8080, max_wait => 3, # seconds ); If C is false, C is instead passed a port number that was free before it was called. =item wait_port wait_port(8080); Waits for a particular port is available for connect. =back =head1 Object Oriented 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->($socket) >> or C<< $code->($port) >>, depending on the value of C. 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 =item $args{listen} : Boolean If true, open a listening socket and pass this to the callback. Otherwise find a free port and pass the number of it to the callback. =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 the OO 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; =item How do I use address other than "127.0.0.1" for testing? You can use the C<< host >> parameter to specify the bind address. # let the server bind to "0.0.0.0" for testing test_tcp( client => sub { ... }, server => sub { ... }, host => '0.0.0.0', ); =item How should I write IPv6 tests? You should use the L function to check if the program can bind to the loopback address of IPv6, as well as the C parameter of the L function to specify the same address as the bind address. use Net::EmptyPort qw(can_bind); plan skip_all => "IPv6 not available" unless can_bind('::1'); test_tcp( client => sub { ... }, server => sub { ... }, host => '::1', ); =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.pm100644000766000024 147613547042705 17521 0ustar00miyagawastaff000000000000Test-TCP-2.22/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 { if ( @ARGV == 3) { print Net::EmptyPort::check_port( { host => $ARGV[0], port => $ARGV[1], proto => $ARGV[2] } ); } else { 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.t100644000766000024 15713547042705 15520 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use Test::More tests => 1; BEGIN { use_ok 'Test::TCP' } diag "Test::More: $Test::More::VERSION"; 01_simple.t100644000766000024 266413547042705 15407 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse warnings; use strict; use Test::More; use Test::TCP; use Net::EmptyPort qw(can_bind); use IO::Socket::IP; BEGIN { require './t/Server.pm' } sub doit { my $host = shift; ok 1, "starting the test"; test_tcp( client => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; my $sock = IO::Socket::IP->new( PeerPort => $port, PeerAddr => $host, Proto => 'tcp', V6Only => 1, ) 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($host, $port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }, host => $host, ); } subtest 'v4' => sub { doit('127.0.0.1'); }; subtest 'v6' => sub { plan skip_all => "IPv6 not supported" unless eval { Socket::IPV6_V6ONLY } and can_bind("::1"); doit('::1'); }; done_testing; 02_abrt.t100644000766000024 157613547042705 15050 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use warnings; use Test::TCP; use Test::More; use Socket; use IO::Socket::INET; BEGIN { require './t/Server.pm' } 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('127.0.0.1', $port)->run(sub { my ($remote, $line) = @_; print {$remote} $line; if ($line =~ /dump/) { return CORE::dump() } }); }, ); 03_return_when_sigterm.t100644000766000024 220613547042705 20202 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse warnings; use strict; use Test::More tests => 2; use Test::TCP; BEGIN { require './t/Server.pm'; t::Server->import(); } # 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('127.0.0.1', $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.t100644000766000024 241713547042705 14656 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse warnings; use strict; use Test::More tests => 9; use Test::TCP; use IO::Socket::INET; BEGIN { require './t/Server.pm' } 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('127.0.0.1', $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; } eval { test_tcp (); }; $e = $@; ok ($e, 'No client is fatal error'); like ($e, qr/missing mandatory parameter client/, 'No client is fatal error'); eval { test_tcp (client => 1); }; $e = $@; ok ($e, 'No server is fatal error'); like ($e, qr/missing mandatory parameter server/, 'No server is fatal error'); eval { Test::TCP->new (); }; $e = $@; ok ($e, 'No code is fatal error'); like ($e, qr/missing mandatory parameter 'code'/, 'No code is fatal error'); 05_sigint.t100644000766000024 507213547042705 15413 0ustar00miyagawastaff000000000000Test-TCP-2.22/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. diag "\$Config{sig_name}: " . $Config{sig_name}; diag "CHILD_ERROR_NATIVE: " . ${^CHILD_ERROR_NATIVE}; diag "\$?: " . $?; 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.t100644000766000024 122013547042705 15057 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use warnings; use Test::TCP; use Test::More tests => 1; BEGIN { require './t/Server.pm' } 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('127.0.0.1', $port2)->run; }, ); }, server => sub { my $port1 = shift; t::Server->new('127.0.0.1', $port1)->run; }, ); if ($?) { diag "test_tcp() leaks \$?. Maybe it's Perl bug?: $?"; $? = 0; } 07_optional.t100644000766000024 26013547042705 15717 0ustar00miyagawastaff000000000000Test-TCP-2.22/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.t100644000766000024 242513547042705 15071 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use warnings; use Test::More tests => 5; use Test::TCP; use File::Temp (); use Fcntl qw/:seek/; BEGIN { require './t/Server.pm' } 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('127.0.0.1', $port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }, ); } 09_fork.t100644000766000024 304413547042705 15060 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use Test::More tests => 6; use Test::TCP; BEGIN { require './t/Server.pm' } 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('127.0.0.1', $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.t100644000766000024 272713547042705 14533 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse warnings; use strict; use Test::More tests => 24; use Test::TCP; use IO::Socket::INET; BEGIN { require './t/Server.pm' } my $server = Test::TCP->new( code => sub { my $port = shift; ok $port, "test case for sharedfork" for 1..10; t::Server->new('127.0.0.1', $port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; exit 0 if $line eq "quit\n"; }); } ); 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; } waitpid($server->pid, 0); my $s2 = Test::TCP->new ( code => sub { return 1; }, port => 8080, auto_start => 0 ); is ($s2->port, 8080, 'Specify port'); $s2 = Test::TCP->new ( { code => sub { return 1; }, port => 8080, auto_start => 0 } ); is ($s2->port, 8080, 'Args as hashref'); done_testing; 11_net_empty_port.t100644000766000024 547613547042705 17173 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use warnings; use IO::Socket::IP; use Test::More; use Net::EmptyPort; sub doit { my $host = shift; my $port = empty_port(); ok $port, "found an empty port on $host"; ok !wait_port({ host => $host, port => $port, max_wait => 0.1 }), "port $port on $host is closed"; my $sock = IO::Socket::IP->new( LocalAddr => $host, LocalPort => $port, Listen => 1, V6Only => 1, ) or die "Couldn't create socket: $!"; ok wait_port({ host => $host, port => $port, max_wait => 3 }), "port $port on $host is now open"; }; ok can_bind('127.0.0.1'), 'bind to 127.0.0.1'; # Skip this check if binding to non-local addresses is enabled (most common # on load balancers with floating IPs) SKIP: { if (-f '/proc/sys/net/ipv4/ip_nonlocal_bind') { open my $fh, "<", "/proc/sys/net/ipv4/ip_nonlocal_bind"; if (<$fh> =~ /1/) { skip "Binding to non-local adddresses is allowed"; } else { ok ! can_bind('8.8.8.8'), 'Cannot bind to an unavailable address'; } } } subtest 'v4' => sub { doit('127.0.0.1'); }; subtest 'v6' => sub { plan skip_all => "IPv6 not supported" unless eval { Socket::IPV6_V6ONLY } and can_bind("::1"); diag "found an empty IPv6 port"; doit('::1'); }; subtest 'return value' => sub { my $sock = IO::Socket::IP->new( LocalAddr => '127.0.0.1', LocalPort => empty_port(), Listen => 1, ); ok $sock; }; my $port = empty_port (8080, 'tcp'); ok ($port, 'Non hashref arg to empty_port'); cmp_ok ($port, '<', 49152, 'Specified low port to empty_port'); $port = empty_port (50000, 'tcp'); cmp_ok ($port, '>', 49151, 'Specified high port to empty_port'); $port = empty_port ('alpha', 'tcp'); cmp_ok ($port, '>', 49151, 'Specified non-numeric port to empty_port'); $port = empty_port ('alpha', 'udp'); cmp_ok ($port, '>', 49151, 'Specified non-numeric port and udp proto to empty_port'); $port = empty_port (); ok (!wait_port ($port, 0.1, 2, 'tcp'), '4 args to wait_port (backwards compat)'); ok (!wait_port ($port, 0.2, 'tcp'), '3 args to wait_port'); eval { wait_port (); }; like ($@, qr/Expected .PeerService./, 'No args to wait_port is fatal'); ok (!wait_port ($port), 'No max_wait to wait_port'); eval { check_port (); }; like ($@, qr/Expected .PeerService./, 'No args to check_port is fatal'); ok (!check_port (empty_port(), 'tcp'), '2 args to check_port'); subtest 'udp-wait-port' => sub { my $port = empty_port({proto => 'udp'}); ok !check_port($port, 'udp'), "port is down"; my $sock = IO::Socket::IP->new( Proto => 'udp', LocalAddr => '127.0.0.1', LocalPort => $port, V6Only => 1, ) or die "failed to bind to a UDP socket:$!"; ok check_port($port, 'udp'), "port is up"; }; done_testing; 12_pass_wait_port_options.t100644000766000024 441713547042705 20727 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse strict; use warnings; use utf8; use Test::More; use Test::TCP; use IO::Socket::INET; BEGIN { require './t/Server.pm' } my %wait_port_args; my $old = \&Net::EmptyPort::wait_port; my $return = sub { 1 }; { no warnings 'redefine'; *Net::EmptyPort::wait_port = sub { %wait_port_args = %{$_[0]}; $return->(@_); }; } # Test::TCP::wait_port arguments are passed to Net::EmptyPort::wait_port. { Test::TCP::wait_port(1, 1); is($wait_port_args{max_wait}, 1); Test::TCP::wait_port (); is($wait_port_args{max_wait}, 10, 'Default max_wait'); is($wait_port_args{host}, '127.0.0.1', 'Default host'); Test::TCP::wait_port (2, 5, 7); is($wait_port_args{port}, 2, 'Backwards compatible port'); is($wait_port_args{max_wait}, 35, 'Backwards compatible max_wait'); } $return = sub { $old->(@_) }; my $server = sub { my $port = shift; ok $port, "test case for sharedfork" for 1 .. 10; t::Server->new('127.0.0.1', $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($wait_port_args{max_wait}, -3); } # test_tcp() arguments are passed to Net::EmptyPort::wait_port. { test_tcp( client => $client, server => $server, max_wait => -2, ); is($wait_port_args{max_wait}, -2); } done_testing; 13_undef_port.t100644000766000024 200313547042705 16251 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse warnings; use strict; use Test::More tests => 22; use Test::TCP; use IO::Socket::INET; BEGIN { require './t/Server.pm' } 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('127.0.0.1', $port)->run(sub { note "new request"; my ($remote, $line, $sock) = @_; print {$remote} $line; }); }, port => undef, # XXX ); 14_listen.t100644000766000024 134013547042705 15406 0ustar00miyagawastaff000000000000Test-TCP-2.22/tuse warnings; use strict; use Test::More; use Test::TCP; use Test::SharedFork; use IO::Socket::IP; test_tcp( client => sub { my ($port, $pid) = @_; ok $port, 'got port'; ok my $sock = IO::Socket::IP->new( PeerPort => $port, PeerHost => '127.0.0.1', Proto => 'tcp', V6Only => 1, ), 'connected' or die "Cannot open client socket: $!"; ok($sock->print("foo\n"), "send 1"); is(<$sock>, "foo\n", "recv 1"); }, server => sub { my ($sock) = @_; while (my $remote = $sock->accept) { note "new request"; $remote->print(scalar <$remote>); } }, listen => 1, ); done_testing; Server.pm100644000766000024 143413547042705 15227 0ustar00miyagawastaff000000000000Test-TCP-2.22/tpackage t::Server; use strict; use warnings; use base qw/Exporter/; use IO::Socket::IP; our @EXPORT = qw/new_sock/; sub new_sock { my ($host, $port) = @_; my $sock = IO::Socket::IP->new( LocalPort => $port, LocalAddr => $host, Proto => 'tcp', Listen => 5, Type => SOCK_STREAM, V6Only => 1, (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)), ) or die "Cannot open server socket: $!"; return $sock; } sub new { my ($class, $host, $port) = @_; my $sock = new_sock($host, $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.t100644000766000024 236213547042705 16442 0ustar00miyagawastaff000000000000Test-TCP-2.22/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'); __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.t100644000766000024 107613547042705 16436 0ustar00miyagawastaff000000000000Test-TCP-2.22/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'; local $ENV{RELEASE_TESTING}; local $ENV{AUTHOR_TESTING}; my $tmp = tempdir(CLEANUP => 1); is(system("cpanm --notest -l $tmp ."), 0); for (qw(Plack POSIX::getpeername Starman Dancer2)) { is(system("cpanm -l $tmp --reinstall $_"), 0, $_); } done_testing; 11_net_emptyport.t100644000766000024 253313547042705 20515 0ustar00miyagawastaff000000000000Test-TCP-2.22/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.yml100644000766000024 461713547042705 14437 0ustar00miyagawastaff000000000000Test-TCP-2.22--- abstract: 'testing TCP program' author: - 'Tokuhiro Matsuno ' build_requires: File::Temp: '0' Socket: '0' Test::More: '0.98' configure_requires: ExtUtils::MakeMaker: '6.64' dynamic_config: 0 generated_by: 'Minilla/v3.1.4, CPAN::Meta::Converter version 2.143240' 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.22' Test::TCP::CheckPort: file: lib/Test/TCP/CheckPort.pm requires: IO::Socket::INET: '0' IO::Socket::IP: '0' Test::More: '0' Test::SharedFork: '0.29' 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.22' x_contributors: - 'Alex Vandiver ' - 'Andrii Melnykov ' - 'Bartosz Jakubski ' - 'Brendan Byrd ' - 'Chad Granum ' - 'Christian Walde ' - 'Dagfinn Ilmari Mannsåker ' - 'David Precious ' - 'Ichito Nagata ' - 'Ivan Baidakou ' - 'Kazuho Oku ' - 'Kenichi Ishigaki ' - 'Kent Fredric ' - 'Masahiro Nagano ' - 'Mohammad S Anwar ' - 'Neil Bowers ' - 'Pavel Shaydo ' - 'Pete Houston ' - 'Petr Písař ' - 'Syohei YOSHIDA ' - 'Tatsuhiko Miyagawa ' - 'Tatsuhiko Miyagawa ' - 'Thomas Klausner ' - 'Yasuhiro Matsumoto ' - 'gfx ' - 'lestrrat ' - 'mattn ' - 'openstrike ' - 'richard.leach ' - 'yappo ' - '奥 一穂 ' x_static_install: 1 MANIFEST100644000766000024 71413547042705 14271 0ustar00miyagawastaff000000000000Test-TCP-2.22Changes LICENSE MANIFEST.SKIP META.json Makefile.PL README.md 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/14_listen.t t/Server.pm xt/02_perlcritic.t xt/04_dependents.t xt/author/11_net_emptyport.t META.yml MANIFEST