编程语言
首页 > 编程语言> > python-测试失败的ndb事务

python-测试失败的ndb事务

作者:互联网

我想单元测试从模型调用put函数时,如果ndb中的事务失败,会发生什么情况.
是否有可能使交易故意失败?

解决方法:

docs

If the function raises an exception, the transaction is immediately aborted and NDB re-raises the exception so that the calling code sees it. You can force a transaction to fail silently by raising the ndb.Rollback exception (the function call returns None in this case). There is no mechanism to force a retry.

您可以在单元测试中引发异常,而不是put()例程来模拟该事件,并且它应该模拟相同的结果-因为放置失败会导致事务中的所有数据存储事件始终回滚.

您可能会发现交易异常these kinds

You can receive Timeout, TransactionFailedError, or InternalError exceptions in cases where transactions have been committed and eventually will be applied successfully.

标签:app-engine-ndb,google-app-engine,transactions,python
来源: https://codeday.me/bug/20191123/2064331.html