-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_servers.rb
More file actions
354 lines (299 loc) · 11.2 KB
/
test_servers.rb
File metadata and controls
354 lines (299 loc) · 11.2 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env ruby
# Script de test des serveurs STORM en mode minimal
require 'socket'
require 'json'
require 'thread'
class ServerTester
def initialize
@test_results = []
puts "=== STORM Server Testing ==="
puts "Testing server functionality without external dependencies\n\n"
end
def test_message_server_basic
puts "1. Testing Message Server (WebSocket) basic structure..."
# Test if the file can be loaded without dependencies
begin
# Read the file and check structure
content = File.read('srv_message.rb')
if content.include?('TCPServer.new')
puts " ✓ TCPServer initialization found"
@test_results << { test: "Message Server Structure", status: "PASS" }
else
puts " ✗ TCPServer initialization not found"
@test_results << { test: "Message Server Structure", status: "FAIL" }
end
if content.include?('WebSocket::Driver')
puts " ✓ WebSocket driver usage found"
else
puts " ! WebSocket driver not found (may need gem)"
end
if content.include?('ChatController')
puts " ✓ ChatController integration found"
else
puts " ✗ ChatController integration not found"
end
rescue => e
puts " ✗ Error reading message server file: #{e.message}"
@test_results << { test: "Message Server Structure", status: "ERROR", error: e.message }
end
puts
end
def test_auth_server_basic
puts "2. Testing Auth Server (Sinatra) basic structure..."
begin
content = File.read('auth_app.rb')
if content.include?('require \'sinatra\'')
puts " ✓ Sinatra framework usage found"
@test_results << { test: "Auth Server Structure", status: "PASS" }
else
puts " ✗ Sinatra framework not found"
@test_results << { test: "Auth Server Structure", status: "FAIL" }
end
if content.include?('post \'/upload\'')
puts " ✓ Upload endpoint found"
else
puts " ! Upload endpoint not found"
end
if content.include?('set :port')
port_match = content.match(/set :port, (\d+)/)
if port_match
puts " ✓ Server port configured: #{port_match[1]}"
else
puts " ! Server port configuration unclear"
end
end
rescue => e
puts " ✗ Error reading auth server file: #{e.message}"
@test_results << { test: "Auth Server Structure", status: "ERROR", error: e.message }
end
puts
end
def test_upload_server_basic
puts "3. Testing Upload Server basic structure..."
begin
content = File.read('srv_upload.rb')
if content.include?('class App < Sinatra::Base')
puts " ✓ Sinatra application class found"
@test_results << { test: "Upload Server Structure", status: "PASS" }
else
puts " ✗ Sinatra application class not found"
@test_results << { test: "Upload Server Structure", status: "FAIL" }
end
if content.include?('FileHelpers')
puts " ✓ File helpers integration found"
else
puts " ! File helpers not found"
end
if content.include?('MetadataHelpers')
puts " ✓ Metadata helpers integration found"
else
puts " ! Metadata helpers not found"
end
rescue => e
puts " ✗ Error reading upload server file: #{e.message}"
@test_results << { test: "Upload Server Structure", status: "ERROR", error: e.message }
end
puts
end
def test_chat_controller
puts "4. Testing ChatController functionality..."
begin
content = File.read('Message/controllers/chat_controller.rb')
# Check for singleton pattern
if content.include?('instance') && content.include?('@@instance')
puts " ✓ Singleton pattern implemented"
@test_results << { test: "ChatController Singleton", status: "PASS" }
else
puts " ! Singleton pattern not clearly implemented"
@test_results << { test: "ChatController Singleton", status: "WARNING" }
end
# Check for room management
if content.include?('create_room')
puts " ✓ Room creation functionality found"
else
puts " ✗ Room creation functionality not found"
end
# Check for user management
if content.include?('add_user') || content.include?('join_room')
puts " ✓ User management functionality found"
else
puts " ! User management functionality unclear"
end
# Check for message handling
if content.include?('broadcast') || content.include?('send_message')
puts " ✓ Message broadcasting functionality found"
else
puts " ! Message broadcasting functionality unclear"
end
rescue => e
puts " ✗ Error reading ChatController: #{e.message}"
@test_results << { test: "ChatController", status: "ERROR", error: e.message }
end
puts
end
def test_command_handler
puts "5. Testing Command Handler..."
begin
content = File.read('Message/controllers/command_handler.rb')
if content.include?('def handle') || content.include?('def process')
puts " ✓ Command handling method found"
@test_results << { test: "Command Handler", status: "PASS" }
else
puts " ✗ Command handling method not found"
@test_results << { test: "Command Handler", status: "FAIL" }
end
# Check for command registration/mapping
if content.include?('commands') || content.include?('register')
puts " ✓ Command registration system found"
else
puts " ! Command registration system unclear"
end
rescue => e
puts " ✗ Error reading Command Handler: #{e.message}"
@test_results << { test: "Command Handler", status: "ERROR", error: e.message }
end
puts
end
def test_database_setup
puts "6. Testing Database Setup..."
# Check if database files exist
db_files = ['chat.db', 'users.db', 'storm.db']
db_found = false
db_files.each do |db_file|
if File.exist?(db_file)
puts " ✓ Database file found: #{db_file}"
db_found = true
end
end
unless db_found
puts " ! No database files found (will be created on first run)"
end
# Check for database initialization in code
files_to_check = ['auth_app.rb', 'srv_upload.rb']
files_to_check.each do |file|
if File.exist?(file)
content = File.read(file)
if content.include?('SQLite3::Database') || content.include?('sqlite3')
puts " ✓ SQLite3 database usage found in #{file}"
@test_results << { test: "Database Setup #{file}", status: "PASS" }
else
puts " ! SQLite3 usage not found in #{file}"
end
end
end
puts
end
def test_file_upload_structure
puts "7. Testing File Upload Structure..."
upload_dirs = ['Upload/controllers', 'Upload/helpers', 'Upload/config']
upload_dirs.each do |dir|
if Dir.exist?(dir)
files = Dir.glob("#{dir}/*.rb")
puts " ✓ #{dir}: #{files.length} files"
@test_results << { test: "Upload #{dir}", status: "PASS", count: files.length }
else
puts " ✗ #{dir} not found"
@test_results << { test: "Upload #{dir}", status: "FAIL" }
end
end
# Check for upload directory
if Dir.exist?('uploads') || Dir.exist?('public/uploads')
puts " ✓ Upload directory structure found"
else
puts " ! Upload directory not found (will be created)"
end
puts
end
def simulate_basic_functionality
puts "8. Simulating Basic Functionality..."
# Test port binding simulation
test_ports = [3630, 4567, 3000]
test_ports.each do |port|
begin
server = TCPServer.new('localhost', port)
puts " ✓ Port #{port} can be bound (available)"
server.close
@test_results << { test: "Port #{port} Binding", status: "PASS" }
rescue Errno::EADDRINUSE
puts " ! Port #{port} is in use"
@test_results << { test: "Port #{port} Binding", status: "IN_USE" }
rescue => e
puts " ✗ Port #{port} binding error: #{e.message}"
@test_results << { test: "Port #{port} Binding", status: "ERROR" }
end
end
# Test basic JSON handling
begin
test_data = { command: '/help', user: 'test', room: 'Main' }
json_string = test_data.to_json
parsed_data = JSON.parse(json_string)
if parsed_data['command'] == '/help'
puts " ✓ JSON serialization/deserialization works"
@test_results << { test: "JSON Handling", status: "PASS" }
else
puts " ✗ JSON handling failed"
@test_results << { test: "JSON Handling", status: "FAIL" }
end
rescue => e
puts " ✗ JSON handling error: #{e.message}"
@test_results << { test: "JSON Handling", status: "ERROR" }
end
puts
end
def generate_server_report
puts "=== SERVER TEST SUMMARY ==="
total_tests = @test_results.length
passed = @test_results.count { |r| r[:status] == "PASS" }
warnings = @test_results.count { |r| r[:status] == "WARNING" }
failed = @test_results.count { |r| r[:status] == "FAIL" }
errors = @test_results.count { |r| r[:status] == "ERROR" }
in_use = @test_results.count { |r| r[:status] == "IN_USE" }
puts "Total server tests: #{total_tests}"
puts "✓ Passed: #{passed}"
puts "! Warnings: #{warnings}"
puts "✗ Failed: #{failed}"
puts "⚠ Errors: #{errors}"
puts "🔒 Ports in use: #{in_use}"
puts
server_score = ((passed + warnings * 0.7) / total_tests * 100).round(1)
puts "Server readiness score: #{server_score}%"
if server_score >= 85
puts "🟢 Servers are ready for deployment"
puts "\n=== DEPLOYMENT RECOMMENDATIONS ==="
puts "1. Install missing gems: bundle install (with proper Ruby version)"
puts "2. Start message server: ruby srv_message.rb"
puts "3. Start auth server: ruby auth_app.rb"
puts "4. Start upload server: ruby srv_upload.rb"
puts "5. Test with WebSocket client connections"
elsif server_score >= 70
puts "🟡 Servers need minor fixes before deployment"
else
puts "🔴 Servers need significant work before deployment"
end
puts "\n=== TESTING CHECKLIST ==="
puts "□ WebSocket connection establishment"
puts "□ User registration and login"
puts "□ Room creation and joining"
puts "□ Message broadcasting"
puts "□ Command execution (/help, /list, /info, etc.)"
puts "□ File upload functionality"
puts "□ User management (ban, kick, etc.)"
puts "□ Appearance customization"
puts "□ Direct messaging"
puts "□ Friend system"
end
def run_all_tests
test_message_server_basic
test_auth_server_basic
test_upload_server_basic
test_chat_controller
test_command_handler
test_database_setup
test_file_upload_structure
simulate_basic_functionality
generate_server_report
end
end
# Run the server tests
tester = ServerTester.new
tester.run_all_tests