summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/p5-Server-Starter/t/03-starter-unix.t
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--web/server/h2o/libh2o/misc/p5-Server-Starter/t/03-starter-unix.t40
1 files changed, 40 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/misc/p5-Server-Starter/t/03-starter-unix.t b/web/server/h2o/libh2o/misc/p5-Server-Starter/t/03-starter-unix.t
new file mode 100644
index 00000000..965de6b6
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/p5-Server-Starter/t/03-starter-unix.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+use File::Temp ();
+use IO::Socket::UNIX;
+use Test::More tests => 4;
+use Test::SharedFork;
+
+use Server::Starter qw(start_server);
+
+$SIG{PIPE} = sub {};
+
+my $sockfile = File::Temp::tmpnam();
+
+my $pid = fork;
+die "fork failed: $!"
+ unless defined $pid;
+if ($pid == 0) {
+ # child
+ start_server(
+ path => $sockfile,
+ exec => [ $^X, qw(t/03-starter-unix-echod.pl) ],
+ );
+ exit 0;
+} else {
+ # parent
+ sleep 1
+ until -e $sockfile;
+ my $sock = IO::Socket::UNIX->new(
+ Peer => $sockfile,
+ ) or die "failed to connect to unix socket:$!";
+ is $sock->syswrite('hello', 5), 5, 'write';
+ is $sock->sysread(my $buf, 5), 5, 'read length';
+ is $buf, 'hello', 'read data';
+ kill 'TERM', $pid;
+ while (wait != $pid) {}
+ ok ! -e $sockfile, 'socket file removed after shutdown';
+}
+
+unlink $sockfile;