async def _test_failover(self, pg1, pg2, sd, debug=False): if debug: print("=" * 80) print("Initialize the State") con = await sd.connect() await con.execute("CREATE TYPE State { " " CREATE REQUIRED PROPERTY value -> int32;" "};") await con.execute("INSERT State { value := 1 };") self.assertEqual(await con.query_single("SELECT State.value LIMIT 1"), 1) if debug: print("=" * 80) print("Stop the master, failover to slave") await pg1.stop() if debug: print("=" * 80) print("Master stopped") async for tx in con.with_retry_options( edgedb.RetryOptions(60, lambda x: 1)).retrying_transaction(): async with tx: self.assertEqual( await tx.query_single("SELECT State.value LIMIT 1"), 1, ) await tx.execute("UPDATE State SET { value := 2 };") if debug: print("=" * 80) print("State updated to 2") self.assertEqual(await con.query_single("SELECT State.value LIMIT 1"), 2) if debug: print("=" * 80) print("Start the old master as slave") await pg1.start() if debug: print("=" * 80) print("Stop the new master, failover to old master again") await pg2.stop() if debug: print("=" * 80) print("State should still be 2") async for tx in con.with_retry_options( edgedb.RetryOptions(60, lambda x: 1)).retrying_transaction(): async with tx: self.assertEqual( await tx.query_single("SELECT State.value LIMIT 1"), 2, )
async def _wait_for_failover(self, con): async for tx in con.with_retry_options( edgedb.RetryOptions(60, lambda x: 1)).retrying_transaction(): async with tx: rv = await tx.query_single("SELECT 1") else: self.assertEqual(rv, 1)
async def connect(ctx): client = getattr(thread_data, 'client', None) if client is None: client = (edgedb.create_async_client( concurrency=ctx.concurrency).with_retry_options( edgedb.RetryOptions(attempts=10))) return client
def test_client_options(self): client = self.create_client(max_concurrency=1) client.with_transaction_options( edgedb.TransactionOptions(readonly=True)) client.with_retry_options( edgedb.RetryOptions(attempts=1, backoff=edgedb.default_backoff)) for tx in client.transaction(): with tx: self.assertEqual(tx.query_single("SELECT 7*8"), 56) client.close()
async def test_server_concurrent_conflict_no_retry_2(self): with self.assertRaises(edgedb.TransactionSerializationError): await self.execute_conflict_2( 'counter5', edgedb.RetryOptions(attempts=1, backoff=edgedb.default_backoff))