File size: 4,798 Bytes
a963d65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
"""
Quick test to verify batch processing fixes
Tests the threading/asyncio conflict resolution
"""

import sys
import os
import time
import asyncio

# Add src to path for imports
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

def test_batch_processing_fix():
    """Test the fixed batch processing implementation"""
    print("๐Ÿ” TESTING BATCH PROCESSING FIXES")
    print("=" * 50)
    
    try:
        from src.heavy_workload_demo import RealTimeBatchProcessor
        print("โœ… Successfully imported RealTimeBatchProcessor")
        
        # Initialize processor
        processor = RealTimeBatchProcessor()
        print("โœ… Processor initialized successfully")
        
        # Test 1: Check datasets are available
        print(f"\n๐Ÿ“‹ Available datasets: {len(processor.medical_datasets)}")
        for name, docs in processor.medical_datasets.items():
            print(f"   {name}: {len(docs)} documents")
        
        # Test 2: Start small batch processing test
        print(f"\n๐Ÿ”ฌ Starting test batch processing (3 documents)...")
        success = processor.start_processing(
            workflow_type="clinical_fhir",
            batch_size=3,
            progress_callback=None
        )
        
        if success:
            print("โœ… Batch processing started successfully")
            
            # Monitor progress for 15 seconds
            for i in range(15):
                status = processor.get_status()
                print(f"Status: {status['status']} - {status.get('processed', 0)}/{status.get('total', 0)}")
                
                if status['status'] in ['completed', 'cancelled']:
                    break
                    
                time.sleep(1)
            
            # Final status
            final_status = processor.get_status()
            print(f"\n๐Ÿ“Š Final Status: {final_status['status']}")
            print(f"   Processed: {final_status.get('processed', 0)}/{final_status.get('total', 0)}")
            print(f"   Results: {len(final_status.get('results', []))}")
            
            if final_status['status'] == 'completed':
                print("๐ŸŽ‰ Batch processing completed successfully!")
                print("โœ… Threading/AsyncIO conflict RESOLVED")
            else:
                processor.stop_processing()
                print("โš ๏ธ Processing didn't complete in test time - but no threading errors!")
                
        else:
            print("โŒ Failed to start batch processing")
            return False
            
        return True
        
    except Exception as e:
        print(f"โŒ Test failed with error: {e}")
        import traceback
        traceback.print_exc()
        return False

def test_frontend_integration():
    """Test frontend timer integration"""
    print(f"\n๐ŸŽฎ TESTING FRONTEND INTEGRATION")
    print("=" * 50)
    
    try:
        from frontend_ui import update_batch_status_realtime, create_empty_results_summary
        print("โœ… Successfully imported frontend functions")
        
        # Test empty status
        status, log, results = update_batch_status_realtime()
        print(f"โœ… Real-time status function works: {status[:30]}...")
        
        # Test empty results
        empty_results = create_empty_results_summary()
        print(f"โœ… Empty results structure: {list(empty_results.keys())}")
        
        return True
        
    except Exception as e:
        print(f"โŒ Frontend test failed: {e}")
        return False

if __name__ == "__main__":
    print("๐Ÿ”ฅ FHIRFLAME BATCH PROCESSING FIX VERIFICATION")
    print("=" * 60)
    
    # Run tests
    batch_test = test_batch_processing_fix()
    frontend_test = test_frontend_integration()
    
    print(f"\n" + "=" * 60)
    print("๐Ÿ“‹ TEST RESULTS SUMMARY")
    print("=" * 60)
    print(f"Batch Processing Fix: {'โœ… PASS' if batch_test else 'โŒ FAIL'}")
    print(f"Frontend Integration: {'โœ… PASS' if frontend_test else 'โŒ FAIL'}")
    
    if batch_test and frontend_test:
        print(f"\n๐ŸŽ‰ ALL TESTS PASSED!")
        print("โœ… Threading/AsyncIO conflicts resolved")
        print("โœ… Real-time UI updates implemented")
        print("โœ… Batch processing should now work correctly")
        print("\n๐Ÿš€ Ready to test in the UI!")
    else:
        print(f"\nโš ๏ธ Some tests failed - check implementation")
        
    print(f"\nTo test in UI:")
    print(f"1. Start the app: python app.py")
    print(f"2. Go to 'Batch Processing Demo' tab")
    print(f"3. Set batch size to 5-10 documents")
    print(f"4. Click 'Start Live Processing'")
    print(f"5. Watch for real-time progress updates every 2 seconds")