From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 13 Jul 2018 16:27:06 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] [PATCH 2/3] Syslog remote destination test Message-ID: <20180713132706.geifcml54stw73e7@esperanza> References: <20180713102938.31897-1-arkholga@tarantool.org> <20180713102938.31897-3-arkholga@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180713102938.31897-3-arkholga@tarantool.org> To: Olga Arkhangelskaia Cc: tarantool-patches@freelists.org List-ID: On Fri, Jul 13, 2018 at 01:29:37PM +0300, Olga Arkhangelskaia wrote: > Adds syslog remote destination test in app-tap. > Test creates server, sets appropriate log level and redirects logs to it. > If log level received by the server is the same - test passes. > > Usage: test-run.py syslog > > Signed-off-by: Olga Arkhangelskaia > --- > test/app-tap/syslog_remote.test.lua | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > create mode 100755 test/app-tap/syslog_remote.test.lua IMHO better add this test case, as well as the next one, to box-tap/cfg.test.lua. > > diff --git a/test/app-tap/syslog_remote.test.lua b/test/app-tap/syslog_remote.test.lua > new file mode 100755 > index 000000000..c7bb773fa > --- /dev/null > +++ b/test/app-tap/syslog_remote.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_remote") > + > +test:plan(1) > +local addr = '127.0.0.1' > +local port = 8888 The port may be busy. Better use a random one. For example, see https://github.com/tarantool/tarantool/blob/fbf8be12dbb041026fc7c81018ac5f02a9fc9d18/test/app/socket.test.lua#L357 > + > +local function start_server() > + test:diag("Starting server") > + local server = socket.tcp_server(addr, port, function() end) Why do you need a tcp server? AFAIU all you need is a udp socket bound to the specified port. > + > + local sc = socket('AF_INET', 'SOCK_DGRAM', 'udp') > + sc:bind('127.0.0.1', 8888) Should be (addr, port) > + return server, sc > +end > + > +local function find_log_level() > + local opt = 'syslog:server='..addr..':'..port..',identity=tarantool' There's string.format(), which usually results in cleaner code than string concatenation. > + box.cfg{log = opt, log_level = 7} > + local buf = sc:read(300) > + test:ok(buf:match('log level 7')) Better write a specific string to the log (see log.info) and match it. Matching 'log level 7' took me a while to understand. > +end > + > +server,sc = start_server() > + > +test:test('syslog_remote',find_log_level(test)) > +sc:close() > +server:shutdown() > +os.exit(test:check() == true)