美好的一天。在pymongo中測試組的潛伏期
我所面臨的python2.7
使用pymongo==2.1.1
以下問題與mongo 2.4.8
我曾嘗試使用谷歌和堆棧溢出來找到解決,但失敗了。
這是什麼問題?
我有以下功能
from bson.code import Code
def read(groupped_by=None):
reducer = Code("""
function(obj, prev){
prev.count++;
}
""")
client = Connection('localhost', 27017)
db = client.urlstats_database
results = db.http_requests.group(key={k:1 for k in groupped_by},
condition={},
initial={"count": 0},
reduce=reducer)
groupped_by = list(groupped_by) + ['count']
result = [tuple(res[col] for col in groupped_by) for res in results]
return sorted(result)
然後我試圖寫的測試此功能
class UrlstatsViewsTestCase(TestCase):
test_data = {'data%s' % i : 'data%s' % i for i in range(6)}
def test_one_criterium(self):
client = Connection('localhost', 27017)
db = client.urlstats_database
for column in self.test_data:
db.http_requests.remove()
db.http_requests.insert(self.test_data)
response = read([column])
self.assertEqual(response, [(self.test_data[column], 1)])
這個測試,因爲我理解,因爲延遲有時會失敗。正如我可以看到響應沒有清除其中的數據
如果我添加延遲後刪除測試通過所有的時間。
是否有任何正確的方法來測試此功能?
在此先感謝。
你應該檢查你的服務器在寫作方面有什麼樣的行爲。如果您必須添加延遲,可能是您的服務器速度很慢或超負荷,並且您的移除需要比平均時間更長的時間並觸發超時。如果您在本地運行服務器時嘗試在寫入問題中使用w:0,那麼您的機器可能可能處理多個請求,並且無法寫入觸發錯誤,請將w:0用於測試目的。 –