MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_logging

Function test_logging

tests/test_misc.py:1980–2041  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

1978
1979
1980def test_logging(node_factory):
1981 # Since we redirect, node.start() will fail: do manually.
1982 l1 = node_factory.get_node(options={'log-file': 'logfile'}, start=False)
1983 logpath = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'logfile')
1984 logpath_moved = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'logfile_moved')
1985 l1.daemon.start(wait_for_initialized=False)
1986
1987 wait_for(lambda: os.path.exists(logpath))
1988
1989 shutil.move(logpath, logpath_moved)
1990 l1.daemon.proc.send_signal(signal.SIGHUP)
1991 wait_for(lambda: os.path.exists(logpath_moved))
1992 wait_for(lambda: os.path.exists(logpath))
1993
1994 with open(logpath_moved) as f:
1995 log1 = f.readlines()
1996 assert log1[-1].endswith("Ending log due to SIGHUP\n")
1997
1998 def check_new_log():
1999 with open(logpath) as f:
2000 log2 = f.readlines()
2001 return len(log2) > 0 and log2[0].endswith("Started log due to SIGHUP\n")
2002 wait_for(check_new_log)
2003
2004 # Issue #4240
2005 # Repeated SIGHUP should just re-open the log file
2006 # and not terminate the daemon.
2007 logpath_moved_2 = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'logfile_moved_2')
2008 shutil.move(logpath, logpath_moved_2)
2009 l1.daemon.proc.send_signal(signal.SIGHUP)
2010 wait_for(lambda: os.path.exists(logpath_moved_2))
2011 wait_for(lambda: os.path.exists(logpath))
2012 wait_for(check_new_log)
2013
2014 # Multiple log files
2015 l2 = node_factory.get_node(options={'log-file': ['logfile1', 'logfile2']}, start=False)
2016 logpath1 = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, 'logfile1')
2017 logpath2 = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, 'logfile2')
2018 l2.daemon.start(wait_for_initialized=False)
2019
2020 wait_for(lambda: os.path.exists(logpath1))
2021 wait_for(lambda: os.path.exists(logpath2))
2022 wait_for(lambda: os.path.exists(os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, "lightning-rpc")))
2023 lines = subprocess.check_output(['cli/lightning-cli',
2024 '--network={}'.format(TEST_NETWORK),
2025 '--lightning-dir={}'
2026 .format(l2.daemon.lightning_dir),
2027 '-H',
2028 'listconfigs']).decode('utf-8').splitlines()
2029 # Arrays get split awkwardly by -H!
2030 assert 'log-file=values_str=logfile1' in lines
2031 assert 'logfile2' in lines
2032
2033 # Flat mode is better!
2034 lines = subprocess.check_output(['cli/lightning-cli',
2035 '--network={}'.format(TEST_NETWORK),
2036 '--lightning-dir={}'
2037 .format(l2.daemon.lightning_dir),

Callers

nothing calls this directly

Calls 5

wait_forFunction · 0.90
joinMethod · 0.80
get_nodeMethod · 0.45
startMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected