MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / setup_cluster

Method setup_cluster

asyncpg/_testbase/__init__.py:459–501  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

457
458 @classmethod
459 def setup_cluster(cls):
460 cls.master_cluster = cls.new_cluster(pg_cluster.TempCluster)
461 cls.start_cluster(
462 cls.master_cluster,
463 server_settings={
464 'max_wal_senders': 10,
465 'wal_level': 'hot_standby'
466 }
467 )
468
469 con = None
470
471 try:
472 con = cls.loop.run_until_complete(
473 cls.master_cluster.connect(
474 database='postgres', user='postgres', loop=cls.loop))
475
476 cls.loop.run_until_complete(
477 con.execute('''
478 CREATE ROLE replication WITH LOGIN REPLICATION
479 '''))
480
481 cls.master_cluster.trust_local_replication_by('replication')
482
483 conn_spec = cls.master_cluster.get_connection_spec()
484
485 cls.standby_cluster = cls.new_cluster(
486 pg_cluster.HotStandbyCluster,
487 cluster_kwargs={
488 'master': conn_spec,
489 'replication_user': 'replication'
490 }
491 )
492 cls.start_cluster(
493 cls.standby_cluster,
494 server_settings={
495 'hot_standby': True
496 }
497 )
498
499 finally:
500 if con is not None:
501 cls.loop.run_until_complete(con.close())
502
503 @classmethod
504 def get_cluster_connection_spec(cls, cluster, kwargs={}):

Callers

nothing calls this directly

Calls 7

new_clusterMethod · 0.80
start_clusterMethod · 0.80
connectMethod · 0.45
executeMethod · 0.45
get_connection_specMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected