This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python | ||
# -*- encoding: utf-8 -*- | ||
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8: | ||
# Author: Binux<i@binux.me> | ||
# http://binux.me | ||
# Created on 2014-11-11 20:52:53 | ||
|
||
import os | ||
import time | ||
import unittest2 as unittest | ||
import logging.config | ||
logging.config.fileConfig("logging.conf") | ||
|
||
import shutil | ||
from multiprocessing import Queue | ||
from database.sqlite import resultdb | ||
from result.result_worker import ResultWorker | ||
from libs.utils import run_in_subprocess, run_in_thread | ||
class TestProcessor(unittest.TestCase): | ||
resultdb_path = './test/data/result.db' | ||
|
||
@classmethod | ||
def setUpClass(self): | ||
shutil.rmtree('./test/data/', ignore_errors=True) | ||
os.makedirs('./test/data/') | ||
|
||
def get_resultdb(): | ||
return resultdb.ResultDB(self.resultdb_path) | ||
self.resultdb = get_resultdb() | ||
self.inqueue = Queue(10) | ||
|
||
def run_result_worker(): | ||
self.result_worker = ResultWorker(get_resultdb(), self.inqueue) | ||
self.result_worker.run() | ||
self.process = run_in_thread(run_result_worker) | ||
time.sleep(1) | ||
|
||
@classmethod | ||
def tearDownClass(self): | ||
if self.process.is_alive(): | ||
self.result_worker.quit() | ||
self.process.join(2) | ||
assert not self.process.is_alive() | ||
shutil.rmtree('./test/data/', ignore_errors=True) | ||
|
||
def test_10_bad_result(self): | ||
self.inqueue.put(({'project': 'test_project'}, {})) | ||
self.resultdb._list_project() | ||
self.assertEqual(len(self.resultdb.projects), 0) | ||
self.assertEqual(self.resultdb.count('test_project'), 0) | ||
|
||
def test_20_insert_result(self): | ||
data = { | ||
'a': 'b' | ||
} | ||
self.inqueue.put(({ | ||
'project': 'test_project', | ||
'taskid': 'id1', | ||
'url': 'url1' | ||
}, data)) | ||
time.sleep(0.1) | ||
self.resultdb._list_project() | ||
self.assertEqual(len(self.resultdb.projects), 1) | ||
self.assertEqual(self.resultdb.count('test_project'), 1) | ||
|
||
result = self.resultdb.get('test_project', 'id1') | ||
self.assertEqual(result['result'], data) | ||
|
||
def test_30_overwrite(self): | ||
self.inqueue.put(({ | ||
'project': 'test_project', | ||
'taskid': 'id1', | ||
'url': 'url1' | ||
}, "abc")) | ||
time.sleep(0.1) | ||
result = self.resultdb.get('test_project', 'id1') | ||
self.assertEqual(result['result'], "abc") | ||
|
||
def test_40_insert_list(self): | ||
self.inqueue.put(({ | ||
'project': 'test_project', | ||
'taskid': 'id2', | ||
'url': 'url1' | ||
}, ['a', 'b'])) | ||
time.sleep(0.1) | ||
result = self.resultdb.get('test_project', 'id2') | ||
self.assertEqual(result['result'], ['a', 'b']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters