• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

lib/Test/H03-May-2022-296115

t/H03-May-2022-181144

Build.PLH A D27-Apr-2019301 134

ChangesH A D27-Apr-2019334 1610

LICENSEH A D27-Apr-201918 KiB379292

MANIFESTH A D27-Apr-2019180 1515

META.jsonH A D27-Apr-20192.1 KiB8382

META.ymlH A D27-Apr-20191.1 KiB4746

README.mdH A D27-Apr-20193.1 KiB14290

cpanfileH A D27-Apr-2019333 1412

minil.tomlH A D27-Apr-201975 53

README.md

1[![Build Status](https://travis-ci.org/fujiwara/Test-UNIXSock.svg?branch=master)](https://travis-ci.org/fujiwara/Test-UNIXSock)
2# NAME
3
4Test::UNIXSock - testing UNIX domain socket program
5
6# SYNOPSIS
7
8    use Test::UNIXSock;
9
10    my $server = Test::UNIXSock->new(
11        code => sub {
12            my $path = shift;
13            ...
14        },
15    );
16    my $client = MyClient->new( sock => $server->path );
17    undef $server; # kill child process on DESTROY
18
19Using memcached:
20
21    use Test::UNIXSock;
22
23    my $memcached = Test::UNIXSock->new(
24        code => sub {
25            my $path = shift;
26
27            exec $bin, '-s' => $path;
28            die "cannot execute $bin: $!";
29        },
30    );
31    my $memd = Cache::Memcached->new({servers => [$memcached->path]});
32    ...
33
34And functional interface is available:
35
36    use Test::UNIXSock;
37    test_unix_sock(
38        client => sub {
39            my ($path, $server_pid) = @_;
40            # send request to the server
41        },
42        server => sub {
43            my $path = shift;
44            # run server
45        },
46    );
47
48# DESCRIPTION
49
50Test::UNIXSock is a test utility to test UNIX domain socket server programs.
51
52This is based on [Test::TCP](https://metacpan.org/pod/Test::TCP).
53
54# METHODS
55
56- test\_unixsock
57
58    Functional interface.
59
60        test_unixsock(
61            client => sub {
62                my $path = shift;
63                # send request to the server
64            },
65            server => sub {
66                my $path = shift;
67                # run server
68            },
69            # optional
70            path => "/tmp/mytest.sock", # if not specified, create a sock in tmpdir
71            max_wait => 3, # seconds
72        );
73
74- wait\_unix\_sock
75
76        wait_unix_sock({ path => $path });
77
78    Waits for a particular path is available for connect.
79
80# Object Oriented interface interface
81
82- my $server = Test::UNIXSock->new(%args);
83
84    Create new instance of Test::UNIXSock.
85
86    Arguments are following:
87
88    - $args{auto\_start}: Boolean
89
90        Call `$server->start()` after create instance.
91
92        Default: true
93
94    - $args{code}: CodeRef
95
96        The callback function. Argument for callback function is: `$code->($pid)`.
97
98        This parameter is required.
99
100    - $args{max\_wait} : Number
101
102        Will wait for at most `$max_wait` seconds before checking port.
103
104        See also [Net::EmptyPort](https://metacpan.org/pod/Net::EmptyPort).
105
106        _Default: 10_
107
108- $server->start()
109
110    Start the server process. Normally, you don't need to call this method.
111
112- $server->stop()
113
114    Stop the server process.
115
116- my $pid = $server->pid();
117
118    Get the pid of child process.
119
120- my $port = $server->port();
121
122    Get the port number of child process.
123
124# FAQ
125
126See also [Test::TCP](https://metacpan.org/pod/Test::TCP) FAQ section.
127
128# AUTHOR
129
130Fujiwara Shunichiro <fujiwara.shunichiro@gmail.com>
131
132# SEE ALSO
133
134[Test::TCP](https://metacpan.org/pod/Test::TCP)
135
136# LICENSE
137
138This library is free software; you can redistribute it and/or modify
139it under the same terms as Perl itself.
140
141This module is based on [Test::TCP](https://metacpan.org/pod/Test::TCP). copyright (c) 2013 by Tokuhiro Matsuno <tokuhirom@gmail.com>.
142