22import time
33
44from exabyte_api_client .endpoints .jobs import JobEndpoints
5- from tests .integration .entity import EntityIntegrationTest
5+ from tests .py .integration .entity import EntityIntegrationTest
6+
7+ KNOWN_COMPLETED_JOB_ID = "9gyhfncWDhnSyzALv"
8+ JOB_NAME_PREFIX = "API-CLIENT TEST JOB"
9+ DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
10+ DEFAULT_NODES = 1
11+ DEFAULT_NOTIFY = "n"
12+ DEFAULT_PPN = 1
13+ DEFAULT_QUEUE = "D"
14+ DEFAULT_TIME_LIMIT = "00:05:00"
15+ TEST_TIME_LIMIT = "00:10:00"
16+ TEST_NOTIFY = "abe"
17+ JOB_STATUS_SUBMITTED = "submitted"
18+ JOB_STATUS_FINISHED = "finished"
19+ JOB_WAIT_TIMEOUT = 900
20+ JOB_WAIT_SLEEP_INTERVAL = 5
21+ JOB_TIMEOUT_ERROR = "job with ID {} did not finish within {} seconds"
622
723
824class JobEndpointsIntegrationTest (EntityIntegrationTest ):
925 """
1026 Job endpoints integration tests.
1127 """
1228
13- KNOWN_COMPLETED_JOB_ID = "9gyhfncWDhnSyzALv"
14-
1529 def __init__ (self , * args , ** kwargs ):
1630 super (JobEndpointsIntegrationTest , self ).__init__ (* args , ** kwargs )
1731 self .endpoints = JobEndpoints (** self .endpoint_kwargs )
@@ -21,10 +35,10 @@ def get_default_config(self):
2135 Returns the default entity config.
2236 Override upon inheritance.
2337 """
24- now_time = datetime .datetime .today ().strftime ("%Y-%m-%d %H:%M:%S" )
25- return {"name" : "API-CLIENT TEST JOB {}" . format ( now_time ) }
38+ now_time = datetime .datetime .today ().strftime (DATETIME_FORMAT )
39+ return {"name" : f" { JOB_NAME_PREFIX } { now_time } " }
2640
27- def get_compute_params (self , nodes = 1 , notify = "n" , ppn = 1 , queue = "D" , time_limit = "00:05:00" ):
41+ def get_compute_params (self , nodes = DEFAULT_NODES , notify = DEFAULT_NOTIFY , ppn = DEFAULT_PPN , queue = DEFAULT_QUEUE , time_limit = DEFAULT_TIME_LIMIT ):
2842 return {"nodes" : nodes , "notify" : notify , "ppn" : ppn , "queue" : queue , "timeLimit" : time_limit }
2943
3044 def test_list_jobs (self ):
@@ -42,34 +56,33 @@ def test_delete_job(self):
4256 def test_update_job (self ):
4357 self .update_entity_test ()
4458
45- def _wait_for_job_to_finish (self , id_ , timeout = 900 ):
59+ def _wait_for_job_to_finish (self , id_ , timeout = JOB_WAIT_TIMEOUT ):
4660 end = time .time () + timeout
4761 while time .time () < end :
4862 job = self .endpoints .get (id_ )
49- if job ["status" ] == "finished" :
63+ if job ["status" ] == JOB_STATUS_FINISHED :
5064 return
51- time .sleep (5 )
52- raise BaseException ("job with ID {} did not finish within {} seconds" .format (id_ , timeout ))
65+ time .sleep (JOB_WAIT_SLEEP_INTERVAL )
66+ raise BaseException (JOB_TIMEOUT_ERROR .format (id_ , timeout ))
5367
5468 def test_submit_job_and_wait_to_finish (self ):
5569 job = self .create_entity ()
5670 self .endpoints .submit (job ["_id" ])
57- self .assertEqual ("submitted" , self .endpoints .get (job ["_id" ])["status" ])
71+ self .assertEqual (JOB_STATUS_SUBMITTED , self .endpoints .get (job ["_id" ])["status" ])
5872 self ._wait_for_job_to_finish (job ["_id" ])
5973
6074 def test_create_job_timeLimit (self ):
61- time_limit = "00:10:00"
62- job = self .create_entity ({"compute" : self .get_compute_params (time_limit = time_limit )})
75+ job = self .create_entity ({"compute" : self .get_compute_params (time_limit = TEST_TIME_LIMIT )})
6376 self .assertEqual (self .endpoints .get (job ["_id" ])["_id" ], job ["_id" ])
64- self .assertEqual (self .endpoints .get (job ["_id" ])["compute" ]["timeLimit" ], time_limit )
77+ self .assertEqual (self .endpoints .get (job ["_id" ])["compute" ]["timeLimit" ], TEST_TIME_LIMIT )
6578
6679 def test_create_job_notify (self ):
67- job = self .create_entity ({"compute" : self .get_compute_params (notify = "abe" )})
80+ job = self .create_entity ({"compute" : self .get_compute_params (notify = TEST_NOTIFY )})
6881 self .assertEqual (self .endpoints .get (job ["_id" ])["_id" ], job ["_id" ])
69- self .assertEqual (self .endpoints .get (job ["_id" ])["compute" ]["notify" ], "abe" )
82+ self .assertEqual (self .endpoints .get (job ["_id" ])["compute" ]["notify" ], TEST_NOTIFY )
7083
7184 def test_list_files (self ):
72- http_response_data = self .endpoints .list_files (self . KNOWN_COMPLETED_JOB_ID )
85+ http_response_data = self .endpoints .list_files (KNOWN_COMPLETED_JOB_ID )
7386 self .assertIsInstance (http_response_data , list )
7487 self .assertGreater (len (http_response_data ), 0 )
7588 self .assertIsInstance (http_response_data [0 ], dict )
0 commit comments