#NEWLINE# def test_general_simple_task_one( worker ) : #NEWLINE# #INDENT# result = worker . send_task ( 'tests.tasks.general.Add' , { #NEWLINE# #INDENT# 'a' : 41 , #NEWLINE# 'b' : 1 , #NEWLINE# 'sleep' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( result == 42 ) #NEWLINE# time . sleep ( 0.1 ) #NEWLINE# db_workers = list ( worker . mongodb_jobs . mrq_workers . find ( ) ) #NEWLINE# assert ( len ( db_workers ) == 1 ) #NEWLINE# worker_report = worker . get_report ( ) #NEWLINE# assert ( worker_report [ 'status' ] in [ 'full' , 'wait' ] ) #NEWLINE# assert ( db_logs [ 'done_jobs' ] == 1 ) #NEWLINE# admin_worker = json . load ( urllib2 . urlopen ( 'http://localhost:20020' ) ) #NEWLINE# assert ( admin_worker [ '_id' ] == str ( db_workers [ 0 ] [ '_id' ] ) ) #NEWLINE# assert ( admin_worker [ 'status' ] == 'wait' ) #NEWLINE# worker . stop ( deps = False ) #NEWLINE# db_jobs = list ( worker . mongodb_jobs . mrq_jobs . find ( ) ) #NEWLINE# assert ( len ( db_jobs ) == 1 ) #NEWLINE# assert ( db_jobs [ 0 ] [ 'result' ] == 42 ) #NEWLINE# assert ( db_jobs [ 0 ] [ 'status' ] == 'success' ) #NEWLINE# assert ( db_jobs [ 0 ] [ 'queue' ] == 'default' ) #NEWLINE# assert db_jobs [ 0 ] [ 'worker' ] #NEWLINE# assert db_jobs [ 0 ] [ 'datestarted' ] #NEWLINE# assert db_jobs [ 0 ] [ 'dateupdated' ] #NEWLINE# assert ( db_jobs [ 0 ] [ 'totaltime' ] > 1 ) #NEWLINE# assert db_jobs [ 0 ] [ '_id' ] #NEWLINE# assert ( db_jobs [ 0 ] [ 'params' ] == { #NEWLINE# #INDENT# 'a' : 41 , #NEWLINE# 'b' : 1 , #NEWLINE# 'sleep' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( db_jobs [ 0 ] [ 'path' ] == 'tests.tasks.general.Add' ) #NEWLINE# assert ( db_jobs [ 0 ] [ 'time' ] < 0.5 ) #NEWLINE# assert ( db_jobs [ 0 ] [ 'switches' ] >= 1 ) #NEWLINE# from mrq.job import get_job_result #NEWLINE# assert ( get_job_result ( db_jobs [ 0 ] [ '_id' ] ) == { #NEWLINE# #INDENT# 'result' : 42 , #NEWLINE# 'status' : 'success' , #NEWLINE# #UNINDENT# } ) #NEWLINE# db_workers = list ( worker . mongodb_jobs . mrq_workers . find ( ) ) #NEWLINE# assert ( len ( db_workers ) == 1 ) #NEWLINE# assert ( db_workers [ 0 ] [ '_id' ] == db_jobs [ 0 ] [ 'worker' ] ) #NEWLINE# assert ( db_workers [ 0 ] [ 'status' ] == 'stop' ) #NEWLINE# assert ( db_workers [ 0 ] [ 'jobs' ] == [ ] ) #NEWLINE# assert ( db_workers [ 0 ] [ 'done_jobs' ] == 1 ) #NEWLINE# assert db_workers [ 0 ] [ 'config' ] #NEWLINE# assert db_workers [ 0 ] [ '_id' ] #NEWLINE# db_logs = list ( worker . mongodb_logs . mrq_logs . find ( { #NEWLINE# #INDENT# 'job' : db_jobs [ 0 ] [ '_id' ] , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# assert ( len ( db_logs ) == 1 ) #NEWLINE# assert ( 'adding' in db_logs [ 0 ] [ 'logs' ] ) #NEWLINE# db_logs = list ( worker . mongodb_logs . mrq_logs . find ( { #NEWLINE# #INDENT# 'worker' : db_workers [ 0 ] [ '_id' ] , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# assert ( len ( db_logs ) >= 1 ) #NEWLINE# worker . stop_deps ( )