Django 测试在没有互联网连接的情况下运行得更快 [英] Django Tests run faster with no internet connection
问题描述
我有一个 django 测试套件,它从一个 400 行的夹具文件构建一个数据库.不幸的是它运行缓慢.每次测试几秒钟.
I have a django test suite that builds a DB from a 400 line fixture file. It runs unfortunately slow. Several seconds per test.
昨天我在火车上开发时没有连接互联网,关闭了 wifi,我注意到我的测试在没有互联网的情况下运行速度快了 10 倍.他们肯定运行正确.
I was on the train yesterday developing without internet access, with my wifi turned off, and I noticed my tests ran literally 10x faster without internet. And they are definitely running correctly.
一切都是本地的,在没有互联网连接的情况下一切正常.测试本身不会命中任何 API 或建立任何其他连接,所以它似乎必须是别的东西.
Everything is local, it all runs fine without an internet connection. The tests themselves do not hit any APIs or make any other connections, so it seems it must be something else.
推荐答案
这很可能意味着您安装了一些正在尝试建立网络连接的组件.可能是监控或统计数据收集的东西?
This most likely means you've got some component installed which is trying to make network connections. Possibly something that does monitoring or statistics gathering?
找出发生了什么的最简单方法是使用 tcpdump 捕获您的网络流量并查看发生了什么.要做到这一点:
The simplest way to figure out what's going on is to use tcpdump to capture your network traffic and see what's going on. To do that:
- 运行
tcpdump -i any
(或者tcpdump -i en1
如果你使用的是 mac;机场通常是en1
,但是你可以用ifconfig
) 仔细检查 - 观察交通状况以了解正常情况
- 运行您的测试套件
- 观察
tcpdump
打印的流量,看看是否有任何明显的东西向您跳出
- Run
tcpdump -i any
(ortcpdump -i en1
if you're on a mac; the airport is usuallyen1
, but you can double check withifconfig
) - Watch the traffic to get some idea what's normal
- Run your test suite
- Watch the traffic printed by
tcpdump
to see if anything obviously jumps out at you
这篇关于Django 测试在没有互联网连接的情况下运行得更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!