Commit 5b4ca2cd authored by Levin Zimmermann's avatar Levin Zimmermann

client_test/NEOSrv += LogContent for better debug

If tests fail we may want to check NEO logs. The new function LogContent
of the NEOSrv interface provides an API to fetch the relevant parts of
the log file of a NEO server. This API can be used by test code in order
to automatically print relevant server log information if a test fails.
parent 4c9414ea
......@@ -27,6 +27,7 @@ import (
"net/url"
"os"
"os/exec"
"strings"
"testing"
"time"
......@@ -54,6 +55,8 @@ type NEOSrv interface {
// BugEncFixed reports whether server, instead of autodetection,
// supports only fixed encoding, and, if yes, which one.
BugEncFixed() (bool, proto.Encoding)
LogContent() (string, error) // content of log files
}
// NEOSrvOptions represents options for a NEO server.
......@@ -90,6 +93,7 @@ func (_ *NEOPySrv) BugEncFixed() (bool, proto.Encoding) {
return true, 'N' // NEO/py 1.12
}
// StartNEOPySrv starts NEO/py server specified by options.
func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
workdir := opt.workdir
......@@ -174,6 +178,37 @@ func (n *NEOPySrv) URL() string {
return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), n.masterAddr, n.clusterName())
}
func (n *NEOPySrv) LogContent() (string, error) {
scontent, err := n.logFileContent("storage_0.log")
if err != nil {
return "", err
}
mcontent, err := n.logFileContent("master_0.log")
if err != nil {
return "", err
}
return scontent + "\n\n" + mcontent, nil
}
func (n *NEOPySrv) logFileContent(logfilename string) (string, error) {
c := xexec.Command("./py/neolog", fmt.Sprintf("%s/%s", n.opt.workdir, logfilename))
o, err := c.Output()
if err != nil {
return "", err
}
return fmt.Sprintf("log file '%s' content:\n\n", logfilename) + tail(string(o)), nil
}
func tail(s string) (string) {
sslice := strings.Split(s, "\n")
icount := len(sslice)
tailsize := 20
if icount < tailsize {
tailsize = icount
}
return strings.Join(sslice[icount - tailsize:], "\n")
}
func (n *NEOPySrv) Close() (err error) {
defer xerr.Contextf(&err, "stop neo/py %s", n.opt.workdir)
......@@ -281,6 +316,10 @@ func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) {
return n, nil
}
func (n *NEOGoSrv) LogContent() (string, error) {
return "", nil
}
func (n *NEOGoSrv) Close() (err error) {
defer xerr.Contextf(&err, "stop neo/go %s", n.opt.workdir)
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
from neo.scripts.neolog import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment