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

Method start

tests/db.py:141–170  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

139 raise ValueError("Could not find `postgres` and `initdb` in any of the possible paths: {}".format(candidates.values()))
140
141 def start(self):
142 passfile = os.path.join(self.directory, "pgpass.txt")
143 self.pgdir = os.path.join(self.directory, 'pgsql')
144 # Need to write a tiny file containing the password so `initdb` can pick it up
145 with open(passfile, 'w') as f:
146 f.write('cltest\n')
147
148 initdb, postgres = self.locate_path()
149 subprocess.check_call([
150 initdb,
151 '--pwfile={}'.format(passfile),
152 '--pgdata={}'.format(self.pgdir),
153 '--auth=trust',
154 '--username=postgres',
155 ])
156 self.port = reserve()
157 self.proc = subprocess.Popen([
158 postgres,
159 '-k', '/tmp/', # So we don't use /var/lib/...
160 '-D', self.pgdir,
161 '-p', str(self.port),
162 '-F',
163 '-i',
164 ])
165 # Hacky but seems to work ok (might want to make the postgres proc a TailableProc as well if too flaky).
166 time.sleep(1)
167 self.conn = psycopg2.connect("dbname=template1 user=postgres host=localhost port={}".format(self.port))
168
169 # Required for CREATE DATABASE to work
170 self.conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
171
172 def get_db(self, node_directory, testname, node_id):
173 # Random suffix to avoid collisions on repeated tests

Callers

nothing calls this directly

Calls 4

locate_pathMethod · 0.95
joinMethod · 0.80
writeMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected