- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用带有多个处理器的 django-nose
来运行我们的测试套件,以减少运行时间。所有测试通过 1 个处理器,但使用多个处理器会产生 DatabaseError: server closed the connection unexpectedly
我发现两个测试在多个处理器上单独运行时 90% 的时间都失败了。 UserFactory
使用 accounts_user
,CustomerFactory
使用 accounts_customer
。请注意,在传递 日志中,accounts_customer
的最终UPDATE
在事务关闭之前完成。在 failing 日志中,此 UPDATE
到 accounts_customer
永远不会发生,因为事务已经关闭导致 DatabaseError:服务器关闭了连接意外地
我正在尝试确定导致问题的原因。我认为问题很可能出在 django 或 postgres 如何处理事务上,但也可能是以下任何一个。
通过 postgres 日志:
145 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: statement: SELECT * FROM "accounts_customer" INNER JOIN "accounts_user" ON ( "accounts_customer"."user_ptr_id" = "accounts_user"."id" ) WHERE "accounts_user"."email" = 'testJkQS.userUksx@example.com' LIMIT 21
146 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: duration: 1.927 ms
147 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: statement: SAVEPOINT "s140735112696576_x1"
148 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: duration: 0.041 ms
149 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: statement: SELECT (1) AS "a" FROM "accounts_customer" WHERE "accounts_customer"."account_number" = '87611264' LIMIT 1
150 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: duration: 0.187 ms
151 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: statement: INSERT INTO "accounts_user" ("password", "last_login", "email", "phone", "first_name", "last_name") VALUES ('', '2015-07-13 17:49:25.779534+00:00', 'testJkQS.userUksx@example.com', '', 'testJkQS', 'userUksx') RETURNING "accounts_user"."id"
152 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: duration: 0.382 ms
153 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: statement: INSERT INTO "accounts_customer" ("user_ptr_id", "advisor_id") VALUES (1, NULL)
154 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: duration: 0.199 ms
155 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: statement: RELEASE SAVEPOINT "s140735112696576_x1"
156 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: duration: 0.022 ms
157 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: statement: UPDATE "accounts_user" SET "password" = 'md5$LNepsrK4upi8$400710819735936b83344e0c47836251', "last_login" = '2015-07-13 17:49:25.779534+00:00', "is_superuser" = true, "email" = 'testJkQS.userUksx@example.com', "first_name" = 'testJkQS', "last_name" = 'userUksx' WHERE "accounts_user"."id" = 1
158 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: duration: 0.363 ms
****159 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: statement: UPDATE "accounts_customer" SET "advisor_id" = NULL WHERE "accounts_customer"."user_ptr_id" = 1
160 (PID: 44072, TID: 394680, Host: ::1(58134)) LOG: duration: 0.274 ms
161 (PID: 44072, TID: 0, Host: ::1(58134)) LOG: disconnection: session time: 0:00:00.156 user=rex database=test_db host=::1 port=58134
1 (PID: 44080, TID: 0, Host: ) LOG: connection received: host=::1 port=58135
失败 postgres 日志:
143 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: statement: BEGIN
145 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: statement: SELECT * FROM "accounts_customer" INNER JOIN "accounts_user" ON ( "accounts_customer"."user_ptr_id" = "accounts_user"."id" ) WHERE "accounts_user"."email" = 'testhTiJ.userRxki@example.com' LIMIT 21
146 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: duration: 1.368 ms
147 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: statement: SAVEPOINT "s140735112696576_x1"
149 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: statement: SELECT (1) AS "a" FROM "accounts_customer" WHERE "accounts_customer"."account_number" = '71017283' LIMIT 1
150 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: duration: 0.198 ms
151 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: statement: INSERT INTO "accounts_user" ("password", "last_login", "email", "phone", "first_name", "last_name",) VALUES ('', '2015-07-13 17:48:01.528782+00:00', 'testhTiJ.userRxki@example.com', '', 'testhTiJ', 'userRxki', ) RETURNING "accounts_user"."id"
152 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: duration: 0.351 ms
153 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: statement: INSERT INTO "accounts_customer" ("user_ptr_id", "advisor_id") VALUES (1, NULL)
154 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: duration: 0.176 ms
155 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: statement: RELEASE SAVEPOINT "s140735112696576_x1"
156 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: duration: 0.033 ms
157 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: statement: UPDATE "accounts_user" SET "password" = 'md5$xN2n3doGJJHs$388f6cf97aa7ddba7c317108a7d4d511', "last_login" = '2015-07-13 17:48:01.528782+00:00', "email" = 'testhTiJ.userRxki@example.com', "first_name" = 'testhTiJ', "last_name" = 'userRxki' WHERE "accounts_user"."id" = 1
158 (PID: 43828, TID: 394672, Host: ::1(58068)) LOG: duration: 0.291 ms
159 (PID: 43828, TID: 0, Host: ::1(58068)) LOG: disconnection: session time: 0:00:00.142 user=rex database=test_db host=::1 port=58068
1 (PID: 43833, TID: 0, Host: ) LOG: connection received: host=::1 port=58069
堆栈跟踪:
======================================================================
ERROR: test_my_test (website.apps.MyApp.tests.test_file.MyTestClass)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../tests/test_file.py", line 33, in test_my_test
customer1 = accounts_factories.CustomerFactory()
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/factory/base.py", line 81, in __call__
return cls.create(**kwargs)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/factory/base.py", line 559, in create
return cls._generate(True, attrs)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/factory/base.py", line 492, in _generate
cls._after_postgeneration(obj, create, results)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/factory/django.py", line 156, in _after_postgeneration
obj.save()
File "/Users/User/pkgs/MyProject/MyProject/website/apps/accounts/models.py", line 198, in save
return super(Customer, self).save(*args, **kwargs)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/base.py", line 679, in _save_table
forced_update)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/base.py", line 723, in _do_update
return filtered._update(values) > 0
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/query.py", line 600, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1005, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 787, in execute_sql
cursor.execute(sql, params)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/User/pkgs/MyProject/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
DatabaseError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
-------------------- >> begin captured logging << --------------------
factory.generate: DEBUG: BaseFactory: Preparing accounts.factories.CustomerFactory(extra={})
factory.generate: DEBUG: <class 'accounts.factories.CustomerFactory'>: Setting up next sequence (0)
factory.containers: DEBUG: LazyStub: Computing values for accounts.factories.CustomerFactory(first_name=<OrderedDeclarationWrapper for <factory.fuzzy.FuzzyText object at 0x10bf1b350>>, last_name=<OrderedDeclarationWrapper for <factory.fuzzy.FuzzyText object at 0x10bf1b390>>, email=<OrderedDeclarationWrapper for <factory.declarations.LazyAttribute object at 0x10bf1b3d0>>)
factory.generate: DEBUG: LazyAttribute: Evaluating <function <lambda> at 0x10bf1d500> on <LazyStub for accounts.factories.CustomerFactory>
factory.containers: DEBUG: LazyStub: Computed values, got accounts.factories.CustomerFactory(first_name=u'testhTiJ', last_name=u'userRxki', email='testhTiJ.userRxki@example.com')
factory.generate: DEBUG: BaseFactory: Generating accounts.factories.CustomerFactory(first_name=u'testhTiJ', last_name=u'userRxki', email='testhTiJ.userRxki@example.com')
factory.generate: DEBUG: PostGenerationMethodCall: Calling <Customer: testhTiJ.userRxki@example.com>.set_password('secret')
--------------------- >> end captured logging << ---------------------
最佳答案
在多个处理器上运行 django-nose 不能很好地处理数据库,或者更准确地说,django 事务/数据库连接器。
尝试使用这个包来拆分测试:nose-picker .查看此 tutorial 的最后一部分关于提高 Django 测试性能。
另外,Python 3.4 包含一个改进版本的 Sqlite3,它应该可以更好地处理并发性。 YMMV.
关于django - 将多个处理器与 django-nose 一起使用会产生 DatabaseError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31413944/
我在Trac / Bitten构建环境中的每个 checkin 中都有一些Selenium Webdriver GUI测试。由于种种愚蠢的原因,这些都是脆弱的,并且重新运行失败的测试总是可以的(除非它
我遇到了这个问题,这让我抓狂! 所以我正在开发我的第一个真正的 Google App Engine 应用程序,我总是喜欢在编写测试时发现新事物。 所以我有以下设置: 我有一个带有 nose、noseg
定义一个 Nose 测试方法test_circlearea_with_min_radius,它创建一个半径为0的圆c2并检查其计算面积是否与值0匹配 我已经编写了下面提到的代码,但仍然没有得到所需的输
它在文档中提到 ( http://nose.readthedocs.org/en/latest/api/core.html ) 但似乎没有任何示例,并且尝试它似乎在 cwd 中运行所有测试。 最佳答案
我正在尝试测试我的 django 项目,我有一个具有非常经典布局的应用程序,如下所示: project ├── __init__.py └── app ├── __init__.py
我正在编写一组测试用例,比如测试模块中的 Test1、Test2。 有没有办法使用命令 nose.main() 在该模块中跳过 Test1 或选择性地仅执行 Test2? 我的模块包含, 测试模块.p
我正在尝试实现一种完整而干净的测试 python 包的方法,一种适合以下要求的方法: 在干净的机器上执行测试而不设置它们 (virtualenv) 从 收集结果多平台 从 收集结果多个python解释
我刚刚开始进行测试开发,而且我正在努力理解要测试的内容。那里有很多 foobar 示例,但我很难知道如何测试我的项目单元。例如,使用这个简单地将文本文件的行作为列表返回的函数: def getLine
似乎是一个愚蠢的问题,但我一直无法弄清楚...... 我想使用 eclipse/pyunit 来运行我所有的测试。我已将测试运行器配置为 Nose 测试运行器。 现在我想让 pyunit 使用 Nos
是否有类似于 Nose 的 spec 的 py.test 插件(也是 pinocchio 的一部分)。我想看到测试运行器输出如下所示: Foobaz - behaves such and such
我已经安装了 django-nose 1.0 作为 Django 1.3.1 项目的测试运行器。我正在按照说明操作 on the pypi page关于仅测试模型。 这是我的 settings.py
如何为所有 Nose 测试用例创建一个仅在初始化期间调用一次的设置函数?我有一个只需要设置一次的全局配置,我觉得向每个模块添加以下内容(甚至为每个模块调用设置函数)有点多余: def setUp(se
我将 nose、django-nose、nose-exclude、coverage 添加到我的 buildout.cfg 中,并且跑了扩建。此外,我将 TEST_RUNNER 和 NOSE_ARGS
我正在为一个函数编写一个测试,该函数使用 Twisted 从 url 下载数据(我知道twisted.web.client.getPage,但是这个函数添加了一些额外的功能)。不管怎样,我想使用nos
我正在尝试使用nosetests 运行目录中的所有pyunit 测试。问题是我在这个目录中有 4 个测试,而 notests 只运行其中之一。如果我单独运行其他三个测试,例如: nosetests -
我有动态量的测试,所以我想使用 for 循环我会尝试这样的事情: from nose.tools import istest, nottest from nose.tools import eq_ i
我刚刚向我的一个 Python 模块添加了一个单元测试,但 nose 拒绝接收。测试看起来像这样: class TestMargin(unittest.TestCase): def setUp
当我运行 nosetests 时出现奇怪的错误: ====================================================================== ERRO
想象一下您有一个 BASE_CLASS 的情况。几个类继承自该类:CHILD_A、CHILD_B、CHILD_C。 现在让我们编写单元测试,但仅限于 CHILD_A、CHILD_B、CHILD_C。我
有没有办法在不运行它们的情况下获取 nose 当前识别的所有测试的列表? 根据文档--collect-only 启用collect-only:只收集和输出测试名称,不运行任何测试。 [COLLECT_
我是一名优秀的程序员,十分优秀!