From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 13 Jul 2018 16:34:25 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] [PATCH 3/3] Syslog destination test unix socket Message-ID: <20180713133424.iezi4kdy4v7t3imj@esperanza> References: <20180713102938.31897-1-arkholga@tarantool.org> <20180713102938.31897-4-arkholga@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180713102938.31897-4-arkholga@tarantool.org> To: Olga Arkhangelskaia Cc: tarantool-patches@freelists.org List-ID: On Fri, Jul 13, 2018 at 01:29:38PM +0300, Olga Arkhangelskaia wrote: > Adds syslog destination unix test in app-tap. > Test redirects logs to newly created unix socket and sets appropriate > log level. If log receives the same level - test passes. > Usage: test-run.py syslog > > Signed-off-by: Olga Arkhangelskaia > --- > test/app-tap/syslog_socket.test.lua | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > create mode 100755 test/app-tap/syslog_socket.test.lua > > diff --git a/test/app-tap/syslog_socket.test.lua b/test/app-tap/syslog_socket.test.lua > new file mode 100755 > index 000000000..bc65ffd5e > --- /dev/null > +++ b/test/app-tap/syslog_socket.test.lua > @@ -0,0 +1,33 @@ > +#!/usr/bin/env tarantool > + > +local tap = require('tap') > +local socket = require('socket') > +local os = require('os') > +local test = tap.test("syslog_unix") > + > +test:plan(1) > +local function start_server(test, sock_addr) > + test:diag("Create unix socket") > + local destination = 'unix:'.. sock_addr > + local unix_socket = socket('AF_UNIX', 'SOCK_DGRAM',0) You don't need datagrams here. Please use SOCK_STREAM. > + unix_socket:bind('unix/', sock_addr) > + socket.tcp_connect('unix', sock_addr) > + unix_socket:listen() > + return unix_socket, destination > +end > + > +local function find_log_level (test, socket, destination) > + local buf > + local opt = 'syslog:server='..destination..',identity=tarantool' > + box.cfg{log = opt, log_level = 7} > + buf = socket:read(300) > + test:ok(buf:match('log level 7')) > +end > + > +path = '/tmp/syslog_test.sock' Better create the socket in the current directory to avoid conflicts. For example, see https://github.com/tarantool/tarantool/blob/fbf8be12dbb041026fc7c81018ac5f02a9fc9d18/test/app-tap/console.test.lua#L14 > +sock, dst = start_server(test, path) > + > +test:test('syslog_unix',find_log_level(test, sock, dst)) > +sock:close() > +os.remove(path) > +os.exit(test:check() == true) Please also check that an invalid address is handled properly so as to cover error paths. The same's fair for the previous test case too.