summaryrefslogtreecommitdiffstats
path: root/test/async_test.py
blob: 9f70598c117fbde936e7c77490b210f0360b944d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from func.overlord.client import Client
import func.jobthing as jobthing
import time
import sys

TEST_SLEEP = 5
EXTRA_SLEEP = 5

def __tester(async):
   if async:
       client = Client("*",nforks=10,async=True)
       oldtime = time.time()
       print "asking minion to sleep for %s seconds" % TEST_SLEEP

       # job_id = client.test.sleep(TEST_SLEEP) # ok
       # job_id = client.hardware.info() # ok
       # job_id = client.test.explode() # doesn't work yet
       job_id = client.test.does_not_exist(1,2) # ditto

       print "job_id = %s" % job_id
       while True:
           status = client.job_status(job_id)
           (code, results) = status
           nowtime = time.time()
           delta = int(nowtime - oldtime)
           if nowtime > oldtime + TEST_SLEEP + EXTRA_SLEEP:
               print "time expired, test failed"
               sys.exit(1)
           if code == jobthing.JOB_ID_RUNNING:  
               print "task is still running, %s elapsed ..." % delta
           if code == jobthing.JOB_ID_PARTIAL:
               print "task reports partial status, %s elapsed, results = %s" % (delta, results)
                   
           elif code == jobthing.JOB_ID_FINISHED:
               print "task complete, %s elapsed, results = %s" % (delta, results)
               sys.exit(0)
           else:
               print "job not found: %s, %s elapased" % (code, delta)
           time.sleep(1)
   else:
       print Client("*",nforks=10,async=False).test.sleep(5)

# __tester(False)
__tester(True)