askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/tests/integration/test_realtime_with_task.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
test_realtime_with_task.py · 4.2 KB · 130 lines
1#!/usr/bin/env python3
2"""
3Test Real-time Monitor with actual tasks to verify visibility
4"""
5
6from selenium import webdriver
7from selenium.webdriver.common.by import By
8from selenium.webdriver.support.ui import WebDriverWait
9from selenium.webdriver.support import expected_conditions as EC
10from selenium.webdriver.chrome.options import Options
11import time
12import sys
13import requests
14import threading
15
16def run_background_tasks():
17 """Generate some API calls to create events"""
18 time.sleep(2) # Wait for browser to load
19
20 # Make some API calls to generate events
21 base_url = 'http://localhost:8003'
22
23 try:
24 # Config browser request
25 requests.get(f'{base_url}/config')
26 time.sleep(0.5)
27
28 # View a specific config
29 requests.get(f'{base_url}/api/config/shipping_config_example.yaml')
30 time.sleep(0.5)
31
32 # Another config
33 requests.get(f'{base_url}/api/config/dashboard_config.yaml')
34 time.sleep(0.5)
35
36 # Main dashboard
37 requests.get(base_url)
38
39 print('📡 Background tasks sent')
40 except Exception as e:
41 print(f'❌ Error sending tasks: {e}')
42
43def test_with_live_tasks(headless=True):
44 # Setup Chrome
45 options = Options()
46 if headless:
47 options.add_argument('--headless=new')
48 options.add_argument('--no-sandbox')
49 options.add_argument('--disable-dev-shm-usage')
50 options.add_argument('--window-size=1920,1080')
51
52 driver = webdriver.Chrome(options=options)
53
54 try:
55 print('🚀 Starting Real-time Monitor test with live tasks')
56 print('=' * 50)
57
58 # Open Real-time Monitor
59 driver.get('http://localhost:8004')
60 wait = WebDriverWait(driver, 10)
61
62 # Wait for initial load
63 time.sleep(2)
64
65 # Check initial state
66 events_container = driver.find_element(By.ID, 'stream-content')
67 initial_events = events_container.find_elements(By.CLASS_NAME, 'stream-entry')
68 print(f'📊 Initial events count: {len(initial_events)}')
69
70 # Start background task thread
71 task_thread = threading.Thread(target=run_background_tasks)
72 task_thread.start()
73
74 # Wait for events to appear
75 print('⏳ Waiting for new events to appear...')
76 time.sleep(4)
77
78 # Check for new events
79 new_events = events_container.find_elements(By.CLASS_NAME, 'stream-entry')
80 print(f'📊 Events after tasks: {len(new_events)}')
81
82 if len(new_events) > len(initial_events):
83 print(f'✅ SUCCESS: {len(new_events) - len(initial_events)} new events appeared!')
84
85 # Show details of new events
86 print('\n📝 New events details:')
87 for i in range(len(initial_events), min(len(new_events), len(initial_events) + 5)):
88 event = new_events[i]
89 # Just print the event text since structure may vary
90 print(f' Event: {event.text[:100]}...')
91 else:
92 print('⚠️ No new events detected')
93
94 # Check WebSocket status
95 ws_state = driver.execute_script("""
96 if (window.ws) {
97 return {
98 readyState: window.ws.readyState,
99 readyStateText: ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'][window.ws.readyState]
100 };
101 }
102 return null;
103 """)
104
105 if ws_state:
106 print(f'WebSocket state: {ws_state.get("readyStateText")}')
107
108 # Take screenshot
109 driver.save_screenshot('realtime_with_tasks.png')
110 print(f'\n📸 Screenshot saved: realtime_with_tasks.png')
111
112 # Wait for thread to complete
113 task_thread.join()
114
115 print('\n' + '=' * 50)
116 print('✅ Test completed!')
117 return len(new_events) > len(initial_events)
118
119 except Exception as e:
120 print(f'\n❌ Error: {e}')
121 driver.save_screenshot('realtime_error.png')
122 return False
123
124 finally:
125 driver.quit()
126
127if __name__ == "__main__":
128 headless = '--headless' in sys.argv
129 success = test_with_live_tasks(headless=headless)
130 sys.exit(0 if success else 1)