Fork
Maybe you remember my test idea for bad requests. The problem was the server script, which sat on my virtual server. If this machine shuts down, the test won’t work, which is bad. With a fork, this problem can be solved, in one process lives the server, the IO::Socket client in the other and they can communicate as if the server were elsewhere:
my $port = 42666;
my $pid = fork;
die "couldn't fork: $!" unless defined $pid;
# Server
if ($pid == 0) {
# Silence!
app->log->level('warn');
# Simple response
get '/' => {text => 'OK'};
# Start on defined port
app->start(daemon => "--listen=http://*:$port");
}
# Client
else {
# IO::Socket connect here
# tests here
# We're done: kill the server
kill 9 => $pid;
}
The only problem seems to be the port choice, which isn’t very variable. I think I should at least provide the possibility to choose the port via environment.
…