def test_request_and_reply(): conn = gym_connect.GymConnector("test_gym") ctx, sock = create_reply("test_gym") t = fill_reply(sock) assert(conn.step(1000) is not None) assert(conn.step(1000) is None) t.join()
def test_base(): proc = gym_process.GymProcess(gym_id="test_gym", report_interval_ms=60, duration_time_ms=1000) conn = gym_connect.GymConnector(gym_id="test_gym") all_stats = [] while True: stats = conn.step(1e9) if stats == None: break all_stats += stats # stats shouldn't be empty assert (all_stats) for stats in all_stats: assert (isinstance(stats, dict)) assert (proc.wait() == 0)
def test_trace(): trace_path = os.path.join(os.path.dirname(__file__), "data", "trace_example.json") proc = gym_process.GymProcess(gym_id="test_gym", trace_path=trace_path, report_interval_ms=60, duration_time_ms=0) conn = gym_connect.GymConnector(gym_id="test_gym") all_stats = [] while True: stats = conn.step(1e9) if stats == None: break all_stats += stats # stats shouldn't be empty assert (all_stats) for stats in all_stats: assert (isinstance(stats, dict)) assert (proc.wait() == 0)
def reset(self, trace_path: str = "", report_interval_ms: int = 60, duration_time_ms: int = 3000): """ Reset gym environment, this function will destroy the old context and create a new one for next step. Parameters trace_path: a path to indicate a trace file with json format. The following is an exmaple of trace file { "type": "video", "downlink": {}, "uplink": { "trace_pattern": [ { "duration": 60000, # duration time "capacity": 300, # link bandwidth (kbps) "loss": 0.1, # loss rate (0.0~0.1) "rtt" : 85, # round trip delay (ms) "jitter": 0, # not supported in current version }, ... ] } } report_interfal_ms: to indicate the report interval. It indicates the a step's duration, the unit is Millisecond. duration_time_ms: to indicate the duration for an epoch. If this value is None or 0, the duration will be caculated according to the trace file. """ if self.gym_conn: del self.gym_conn if self.gym_process: del self.gym_process self.gym_process = gym_process.GymProcess(self.gym_id, trace_path, report_interval_ms, duration_time_ms) self.gym_conn = gym_connect.GymConnector(self.gym_id)