Skip to content

Commit 9614950

Browse files
Update topology tests and schema for improved reliability
Extended wait times and retries in e2e tests to ensure stability and better error handling. Refactored edge creation logic to use dynamic node IDs, improving flexibility and accuracy. Removed primary key from `id` in topology schema to align with database requirements.
1 parent 0bf1d1b commit 9614950

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

keep/api/models/db/topology.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TopologyApplication(SQLModel, table=True):
5151

5252

5353
class TopologyService(SQLModel, table=True):
54-
id: UUID = Field(default_factory=uuid4, primary_key=True)
54+
id: UUID = Field(default_factory=uuid4)
5555
external_id: Optional[int]
5656
tenant_id: str = Field(sa_column=Column(ForeignKey("tenant.id")))
5757
source_provider_id: str = "unknown"

tests/e2e_tests/test_topology.py

+35-15
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_topology_manual(browser):
2424
# Open the Service Topology page
2525
browser.get_by_role("link", name="Service Topology").hover()
2626
browser.get_by_role("link", name="Service Topology").click()
27-
browser.wait_for_timeout(2000) # Added extra wait for page to fully load
27+
browser.wait_for_timeout(5000) # Added extra wait for page to fully load
2828

2929
max_retries = 5
3030
retries = 0
@@ -33,9 +33,11 @@ def test_topology_manual(browser):
3333
while retries <= max_retries:
3434
try:
3535
browser.get_by_role("button", name="Add Node", exact=True).click()
36+
browser.wait_for_timeout(2000)
3637
browser.get_by_placeholder("Enter service here...").fill("service_id_1")
3738
break
3839
except Exception:
40+
raise
3941
if retries == max_retries:
4042
raise
4143
retries += 1
@@ -89,9 +91,7 @@ def test_topology_manual(browser):
8991
browser.wait_for_timeout(2000)
9092

9193
# Improved edge connection with retries
92-
def connect_nodes(source_selector, target_selector, edge_label, max_attempts=3):
93-
source_handle = browser.locator(source_selector)
94-
target_handle = browser.locator(target_selector)
94+
def connect_nodes(source_handle, target_handle, edge_label, max_attempts=3):
9595

9696
for attempt in range(max_attempts):
9797
try:
@@ -151,14 +151,18 @@ def connect_nodes(source_selector, target_selector, edge_label, max_attempts=3):
151151
node_2 = browser.locator("div.react-flow__node-service").filter(has_text="SERVICE_ID_2")
152152
node_3 = browser.locator("div.react-flow__node-service").filter(has_text="SERVICE_ID_3")
153153

154+
node_1_id = node_1.get_attribute('data-id')
155+
node_2_id = node_2.get_attribute('data-id')
156+
node_3_id = node_3.get_attribute('data-id')
157+
154158
# Connect nodes by dragging source to target handles
155-
source_handle_1 = node_1.locator("div[data-handlepos='right']")
156-
target_handle_2 = node_2.locator("div[data-handlepos='left']")
157-
target_handle_3 = node_3.locator("div[data-handlepos='left']")
159+
source_handle_1 = node_1.locator(f"div[data-id='1-{node_1_id}-right-source']")
160+
target_handle_2 = node_2.locator(f"div[data-id='1-{node_2_id}-left-target']")
161+
target_handle_3 = node_3.locator(f"div[data-id='1-{node_3_id}-left-target']")
158162

159163
# Connect nodes with retry logic
160164
edge1_created = connect_nodes(
161-
source_handle_1, target_handle_2, "Edge from 1 to 2"
165+
source_handle_1, target_handle_2, f"Edge from {node_1_id} to {node_2_id}"
162166
)
163167
if not edge1_created:
164168
# Take diagnostic screenshots
@@ -167,7 +171,7 @@ def connect_nodes(source_selector, target_selector, edge_label, max_attempts=3):
167171
print("Failed to create edge from node 1 to node 2 after multiple attempts")
168172

169173
edge2_created = connect_nodes(
170-
source_handle_1, target_handle_3, "Edge from 1 to 3"
174+
source_handle_1, target_handle_3, f"Edge from {node_1_id} to {node_3_id}"
171175
)
172176
if not edge2_created:
173177
# Take diagnostic screenshots
@@ -177,9 +181,9 @@ def connect_nodes(source_selector, target_selector, edge_label, max_attempts=3):
177181

178182
# Validate edge connections with more flexible assertions
179183
browser.wait_for_timeout(2000)
180-
edge_1_to_2 = browser.locator("g.react-flow__edge").first
184+
edge_1_to_2 = browser.locator(f"g.react-flow__edge[aria-label='Edge from {node_1_id} to {node_2_id}']")
181185
expect(edge_1_to_2).to_have_count(1, timeout=10000) # Increased timeout
182-
edge_1_to_3 = browser.locator("g.react-flow__edge").last
186+
edge_1_to_3 = browser.locator(f"g.react-flow__edge[aria-label='Edge from {node_1_id} to {node_3_id}']")
183187
expect(edge_1_to_3).to_have_count(1, timeout=10000) # Increased timeout
184188

185189
# Continue with rest of the test...
@@ -193,10 +197,26 @@ def connect_nodes(source_selector, target_selector, edge_label, max_attempts=3):
193197

194198
# Ensure edge was deleted with retry
195199
for _ in range(5):
196-
if browser.locator("g.react-flow__edge").count() == 1:
197-
break
200+
if (
201+
browser.locator(
202+
f"g.react-flow__edge[aria-label='Edge from {node_1_id} to {node_2_id}']"
203+
).count()
204+
== 0
205+
):
206+
if browser.locator("g.react-flow__edge").count() == 1:
207+
break
198208
browser.wait_for_timeout(1000)
199209

210+
expect(
211+
browser.locator(f"g.react-flow__edge[aria-label='Edge {node_1_id} to {node_2_id}']")
212+
).to_have_count(0, timeout=5000)
213+
214+
# Ensure remaining edges are intact
215+
expect(
216+
browser.locator(f"g.react-flow__edge[aria-label='Edge from {node_1_id} to {node_3_id}']")
217+
).to_have_count(1, timeout=5000)
218+
browser.wait_for_timeout(2000)
219+
200220
# Delete a node and ensure related edges are removed
201221
node_to_delete = browser.locator("div.react-flow__node").filter(
202222
has_text="SERVICE_ID_1"
@@ -226,15 +246,15 @@ def connect_nodes(source_selector, target_selector, edge_label, max_attempts=3):
226246
for _ in range(5):
227247
if (
228248
browser.locator(
229-
"g.react-flow__edge[aria-label='Edge from 1 to 3']"
249+
f"g.react-flow__edge[aria-label='Edge from {node_1_id} to {node_3_id}']"
230250
).count()
231251
== 0
232252
):
233253
break
234254
browser.wait_for_timeout(1000)
235255

236256
expect(
237-
browser.locator("g.react-flow__edge")
257+
browser.locator(f"g.react-flow__edge[aria-label='Edge from {node_1_id} to {node_3_id}']")
238258
).to_have_count(0, timeout=5000)
239259

240260
# Update node name and verify the change

0 commit comments

Comments
 (0)