App-OpenHAP
view release on metacpan or search on metacpan
lib/App/OpenHAP/Test/Integration.pm view on Meta::CPAN
return 1;
}
sub http_request ( $self, $method, $path, $body = undef, $headers = {} )
{
my $socket = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => $self->{hap_port},
Proto => 'tcp',
Timeout => 2,
);
return unless defined $socket;
push @{ $self->{sockets} }, $socket;
print {$socket} Protocol::HAP::HTTP::build_request(
method => $method,
path => $path,
body => $body,
headers => { Host => "127.0.0.1:$self->{hap_port}", %$headers },
lib/App/OpenHAP/Test/Integration.pm view on Meta::CPAN
sub wait_for_hap_port ( $self, $timeout = 30 )
{
my $port = $self->get_config_value('hap_port') // DEFAULT_HAP_PORT;
my $deadline = time + $timeout;
while ( time < $deadline ) {
my $socket = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => $port,
Proto => 'tcp',
Timeout => 2,
);
if ( defined $socket ) {
$socket->close;
return 1;
}
sleep 0.25;
}
return;
}
lib/Protocol/HAP/Controller.pm view on Meta::CPAN
# --- transport ---------------------------------------------------------
sub _connect ($self)
{
return 1 if $self->{transport} || $self->{socket};
my $socket = IO::Socket::INET->new(
PeerAddr => $self->{host},
PeerPort => $self->{port},
Proto => 'tcp',
Timeout => $self->{timeout},
);
unless ( defined $socket ) {
$self->{last_error} = "connect: $!";
return;
}
$self->{socket} = $socket;
return 1;
}
lib/Protocol/HAP/HTTP.pm view on Meta::CPAN
200 => 'OK',
201 => 'Created',
204 => 'No Content',
207 => 'Multi-Status',
304 => 'Not Modified',
400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
408 => 'Request Timeout',
413 => 'Content Too Large',
500 => 'Internal Server Error',
503 => 'Service Unavailable',
);
# message_complete($buffer, %args):
# Report how many bytes at the front of $buffer form one whole
# message.
#
# %args:
t/openhap/integration/hap-protocol.t view on Meta::CPAN
$response = $env->http_request('GET', '/accessories');
ok($response =~ /HTTP\/1\.[01]/, 'server uses HTTP/1.x');
# Test 9: Multiple concurrent connections work
my @sockets;
for (1..5) {
my $sock = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => $env->{hap_port},
Proto => 'tcp',
Timeout => 2,
);
push @sockets, $sock if defined $sock;
}
ok(@sockets >= 5, 'handles multiple concurrent connections');
$_->close for @sockets;
# Test 10: Connection persistence works
my $socket = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => $env->{hap_port},
Proto => 'tcp',
Timeout => 2,
);
ok(defined $socket, 'connection established');
# Make multiple requests on the same connection
print $socket "GET /accessories HTTP/1.1\r\n";
print $socket "Host: 127.0.0.1\r\n\r\n";
my $resp1 = '';
while (my $line = <$socket>) {
$resp1 .= $line;
last if $line =~ /^\r?\n$/;
t/openhap/integration/mdns.t view on Meta::CPAN
if ($lookup_output =~ /(\d{4,5})/) {
ok($lookup_output =~ /\b\Q$hap_port\E\b/,
'[HAP-mDNS §6] advertised port matches configured hap_port');
} else {
# The browse output carries no port. Make sure that the daemon
# listens on the configured port.
my $listening = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => $hap_port,
Proto => 'tcp',
Timeout => 2,
);
ok(defined $listening,
'[HAP-mDNS §6] daemon listens on the configured HAP port');
$listening->close if defined $listening;
}
# Test 10: sf=1 advertised while unpaired
my $txt_output = $env->browse_txt;
like($txt_output, qr/sf=1/,
'[HAP-mDNS §3.7] sf=1 advertised while unpaired');
t/openhap/integration/shutdown.t view on Meta::CPAN
my $hap_port = $env->get_config_value('hap_port') // 51827;
my $hap_name = $env->get_config_value('hap_name') // 'OpenHAP';
# port_open(): can anything connect to the HAP port right now
sub port_open ()
{
my $sock = IO::Socket::INET->new(
PeerAddr => '127.0.0.1',
PeerPort => $hap_port,
Proto => 'tcp',
Timeout => 2,
);
return 0 unless $sock;
$sock->close;
return 1;
}
die "mdnsd required for the withdraw assertion\n"
unless $env->ensure_mdnsd_running;
( run in 1.926 second using v1.01-cache-2.11-cpan-85d3896f969 )