From d7814ebbcd741fc8a9a827a9ce3f4f80e57a504f Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 14:56:08 -0700 Subject: [PATCH 1/7] fix unit tests --- tests/test_session.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/test_session.py b/tests/test_session.py index b61e715f..be91f310 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -21,32 +21,28 @@ def setup_method(self): agentops.init(api_key=self.api_key, max_wait_time=5, auto_start_session=False) def test_session(self, mock_req): - # Arrange agentops.start_session() - # Act agentops.record(ActionEvent(self.event_type)) - # Assert the session has been initiated and the id has been created on backend. + # We should have 1 requests (session start). The action event should still be in queue assert len(mock_req.request_history) == 1 - # Act agentops.record(ActionEvent(self.event_type)) time.sleep(0.1) - # Assert an event has been added - assert len(mock_req.request_history) == 2 + # We should have 3 requests (session and 2 events) + assert len(mock_req.request_history) == 3 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() assert request_json['events'][0]['event_type'] == self.event_type - # Act end_state = 'Success' agentops.end_session(end_state) time.sleep(0.1) - # Since a session has ended, no more events should be recorded, but end_session should be called - assert len(mock_req.request_history) == 3 + # We should have 4 requests (additional end session) + assert len(mock_req.request_history) == 4 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() assert request_json['session']['end_state'] == end_state From 46b373ccb43e48943522a5dcaa9d2665b7cf8199 Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 15:03:02 -0700 Subject: [PATCH 2/7] additional time --- tests/test_session.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_session.py b/tests/test_session.py index be91f310..152ef835 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -29,7 +29,7 @@ def test_session(self, mock_req): assert len(mock_req.request_history) == 1 agentops.record(ActionEvent(self.event_type)) - time.sleep(0.1) + time.sleep(0.5) # We should have 3 requests (session and 2 events) assert len(mock_req.request_history) == 3 @@ -39,7 +39,7 @@ def test_session(self, mock_req): end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.1) + time.sleep(0.5) # We should have 4 requests (additional end session) assert len(mock_req.request_history) == 4 @@ -55,7 +55,7 @@ def test_tags(self, mock_req): # Act agentops.record(ActionEvent(self.event_type)) - time.sleep(0.1) + time.sleep(0.5) # Assert 2 requests - 1 for session init, 1 for event assert len(mock_req.request_history) == 2 @@ -66,7 +66,7 @@ def test_tags(self, mock_req): # Act end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.1) + time.sleep(0.5) # Assert 3 requets, 1 for session init, 1 for event, 1 for end session assert len(mock_req.request_history) == 3 From cf8857fec5be9521678b809d720d428464b09e1e Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 15:28:16 -0700 Subject: [PATCH 3/7] change order around --- tests/test_session.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_session.py b/tests/test_session.py index 152ef835..d653777b 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -23,26 +23,26 @@ def setup_method(self): def test_session(self, mock_req): agentops.start_session() + agentops.record(ActionEvent(self.event_type)) agentops.record(ActionEvent(self.event_type)) - # We should have 1 requests (session start). The action event should still be in queue + # We should have 1 requests (session start). The action events should still be in queue assert len(mock_req.request_history) == 1 + time.sleep(0.1) - agentops.record(ActionEvent(self.event_type)) - time.sleep(0.5) - - # We should have 3 requests (session and 2 events) - assert len(mock_req.request_history) == 3 + # We should have 2 requests (session and 2 events combined into 1) + print(mock_req.last_request.json()) + assert len(mock_req.request_history) == 2 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() assert request_json['events'][0]['event_type'] == self.event_type end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.5) + time.sleep(0.1) - # We should have 4 requests (additional end session) - assert len(mock_req.request_history) == 4 + # We should have 3 requests (additional end session) + assert len(mock_req.request_history) == 3 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() assert request_json['session']['end_state'] == end_state @@ -58,6 +58,7 @@ def test_tags(self, mock_req): time.sleep(0.5) # Assert 2 requests - 1 for session init, 1 for event + print(mock_req.last_request.json()) assert len(mock_req.request_history) == 2 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() From 6a03da9ad22206b2b800bf90ee5695680961618d Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 15:29:50 -0700 Subject: [PATCH 4/7] looser timings --- tests/test_session.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_session.py b/tests/test_session.py index d653777b..f09575d3 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -18,7 +18,7 @@ class TestSessions: def setup_method(self): self.api_key = "random_api_key" self.event_type = 'test_event_type' - agentops.init(api_key=self.api_key, max_wait_time=5, auto_start_session=False) + agentops.init(api_key=self.api_key, max_wait_time=100, auto_start_session=False) def test_session(self, mock_req): agentops.start_session() @@ -28,7 +28,7 @@ def test_session(self, mock_req): # We should have 1 requests (session start). The action events should still be in queue assert len(mock_req.request_history) == 1 - time.sleep(0.1) + time.sleep(0.5) # We should have 2 requests (session and 2 events combined into 1) print(mock_req.last_request.json()) @@ -39,7 +39,7 @@ def test_session(self, mock_req): end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.1) + time.sleep(0.5) # We should have 3 requests (additional end session) assert len(mock_req.request_history) == 3 From 5bf42f45e6bec60466f101ee5ed00eb506d22ec7 Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 15:31:20 -0700 Subject: [PATCH 5/7] even looser --- tests/test_session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_session.py b/tests/test_session.py index f09575d3..abae7c2d 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -18,7 +18,7 @@ class TestSessions: def setup_method(self): self.api_key = "random_api_key" self.event_type = 'test_event_type' - agentops.init(api_key=self.api_key, max_wait_time=100, auto_start_session=False) + agentops.init(api_key=self.api_key, max_wait_time=200, auto_start_session=False) def test_session(self, mock_req): agentops.start_session() From 66f8c0e3e7805894081b897a6c646a359e9fa226 Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 16:02:56 -0700 Subject: [PATCH 6/7] actually looser timings --- tests/test_session.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_session.py b/tests/test_session.py index abae7c2d..5a42881a 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -18,17 +18,17 @@ class TestSessions: def setup_method(self): self.api_key = "random_api_key" self.event_type = 'test_event_type' - agentops.init(api_key=self.api_key, max_wait_time=200, auto_start_session=False) + self.config = agentops.Configuration(api_key=self.api_key, max_wait_time=50) def test_session(self, mock_req): - agentops.start_session() + agentops.start_session(config=self.config) agentops.record(ActionEvent(self.event_type)) agentops.record(ActionEvent(self.event_type)) - # We should have 1 requests (session start). The action events should still be in queue + # We should have 1 requests (session start). assert len(mock_req.request_history) == 1 - time.sleep(0.5) + time.sleep(2) # We should have 2 requests (session and 2 events combined into 1) print(mock_req.last_request.json()) @@ -39,7 +39,7 @@ def test_session(self, mock_req): end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.5) + time.sleep(0.2) # We should have 3 requests (additional end session) assert len(mock_req.request_history) == 3 @@ -51,11 +51,11 @@ def test_session(self, mock_req): def test_tags(self, mock_req): # Arrange tags = ['GPT-4'] - agentops.start_session(tags=tags) + agentops.start_session(tags=tags, config=self.config) # Act agentops.record(ActionEvent(self.event_type)) - time.sleep(0.5) + time.sleep(0.2) # Assert 2 requests - 1 for session init, 1 for event print(mock_req.last_request.json()) From 709e81e58a215677954bb14b294026b80cc7c7a9 Mon Sep 17 00:00:00 2001 From: Shawn Qiu Date: Thu, 4 Apr 2024 16:05:59 -0700 Subject: [PATCH 7/7] retighten timings --- tests/test_session.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_session.py b/tests/test_session.py index 5a42881a..2efe82a4 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -28,7 +28,7 @@ def test_session(self, mock_req): # We should have 1 requests (session start). assert len(mock_req.request_history) == 1 - time.sleep(2) + time.sleep(0.15) # We should have 2 requests (session and 2 events combined into 1) print(mock_req.last_request.json()) @@ -39,7 +39,7 @@ def test_session(self, mock_req): end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.2) + time.sleep(0.15) # We should have 3 requests (additional end session) assert len(mock_req.request_history) == 3 @@ -55,7 +55,7 @@ def test_tags(self, mock_req): # Act agentops.record(ActionEvent(self.event_type)) - time.sleep(0.2) + time.sleep(0.15) # Assert 2 requests - 1 for session init, 1 for event print(mock_req.last_request.json()) @@ -67,7 +67,7 @@ def test_tags(self, mock_req): # Act end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.5) + time.sleep(0.15) # Assert 3 requets, 1 for session init, 1 for event, 1 for end session assert len(mock_req.request_history) == 3