shlist

share and manage lists between multiple people
Log | Files | Refs

commit f368775432d5330eee067f8b2fd4519c13ac728b
parent 7b80981985d1e8c83583ea9f455f0aa031743219
Author: kyle <kyle@0x30.net>
Date:   Wed, 10 Feb 2016 20:15:07 -0700

sl/tests: add testd, a dummy notification daemon

- this daemon is used by the test suite
- the main server sends its notifications messages there when -t is given
- switch server socket from testd.socket to ../testd.socket

Diffstat:
Mserver/run_tests.sh | 5+++++
Mserver/sl | 2+-
Aserver/testd | 43+++++++++++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/server/run_tests.sh b/server/run_tests.sh @@ -16,6 +16,9 @@ fi perl -T sl -p $PORT -t > server.log & server_pid=$! +perl testd & +testd_pid=$! + ok=0 test_failed=0 diff_failed=0 @@ -48,8 +51,10 @@ for t in `LC_ALL=C ls tests/*/Makefile`; do ok=$((ok + 1)) done +kill $testd_pid kill $server_pid wait 2>/dev/null +rm testd.log rm server.log printf "\n%i ok, %i test + %i diff fail " $ok $test_failed $diff_failed diff --git a/server/sl b/server/sl @@ -129,7 +129,7 @@ while (my $client_socket = $server_socket->accept()) { # Try to send to various messaging daemons send_unix("../apnd.socket", $msg, $msg_len) unless ($args{t}); send_unix("../gcmd.socket", $msg, $msg_len) unless ($args{t}); - send_unix("testd.socket", $msg, $msg_len) if ($args{t}); + send_unix("../testd.socket", $msg, $msg_len) if ($args{t}); } } diff --git a/server/testd b/server/testd @@ -0,0 +1,43 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Data::Dumper; +use IO::Socket::UNIX; +use JSON::XS; + +my $socket_path = "../testd.socket"; + +my $server = IO::Socket::UNIX->new( + Type => SOCK_STREAM(), + Local => $socket_path, + Listen => 1, +); +unless ($server) { + print "error: couldn't create socket: $!\n"; + exit 1; +} + +$SIG{INT} = \&unlink_socket; +$SIG{TERM} = \&unlink_socket; + +sub unlink_socket { + unlink $socket_path; +} + +while (my $client = $server->accept()) { + $client->read(my $data, 4096); + my $notify = decode_json($data); + + my $num_devices = @{ $notify->{devices} }; + next if ($num_devices == 0); + + print "testd: message type '$notify->{msg_type}'\n"; + # print "testd: payload is '" . Dumper($notify->{payload}) . "'\n"; + + for (@{ $notify->{devices} }) { + #print Dumper($_); + my ($os, $push_token) = @$_; + print "testd: sending to '$push_token' os '$os'\n"; + } +}