-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstress_tests.rs
More file actions
610 lines (503 loc) · 16.4 KB
/
stress_tests.rs
File metadata and controls
610 lines (503 loc) · 16.4 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
#![allow(deprecated)]
#![allow(clippy::empty_line_after_doc_comments)]
#![allow(clippy::doc_lazy_continuation)]
mod common;
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
use std::time::{Duration, Instant};
// Stress tests for extreme conditions
//
// These tests verify the tool can handle:
// - 10,000+ translation keys
// - 100+ locales
// - 1MB+ translation files
// - Rapid file changes in watch mode
//
// Run with: cargo test --ignored
// ====================================================================================
// Large Dataset Tests
// ====================================================================================
/// Tests building with 10,000 translation keys
#[test]
#[ignore] // Run with --ignored flag
fn test_10k_translations() {
let temp = common::create_test_project();
// Generate 10,000 translations
let mut translations = serde_json::Map::new();
for i in 0..10000 {
let category = format!("category_{}", i / 100);
let subcategory = format!("subcategory_{}", i / 10);
let key = format!("key_{}", i);
let value = format!("Translation value number {}", i);
if !translations.contains_key(&category) {
translations.insert(
category.clone(),
serde_json::Value::Object(serde_json::Map::new()),
);
}
if let Some(serde_json::Value::Object(cat_map)) = translations.get_mut(&category) {
if !cat_map.contains_key(&subcategory) {
cat_map.insert(
subcategory.clone(),
serde_json::Value::Object(serde_json::Map::new()),
);
}
if let Some(serde_json::Value::Object(subcat_map)) = cat_map.get_mut(&subcategory) {
subcat_map.insert(key, serde_json::Value::String(value));
}
}
}
let json = serde_json::to_string_pretty(&translations).unwrap();
fs::write(temp.path().join("translations/en.json"), &json).unwrap();
// Measure build time
let start = Instant::now();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success()
.stdout(predicate::str::contains("Parsed en"));
let duration = start.elapsed();
// Verify output generated
common::assert_file_exists(&temp.path().join("output/Translations.lua"));
common::assert_file_exists(&temp.path().join("output/roblox_upload.csv"));
// Performance assertions - relaxed to 7s for debug builds
assert!(
duration < Duration::from_secs(7),
"Build took {:?}, expected <10s (debug build)",
duration
);
println!("✓ Built 10,000 translations in {:?}", duration);
}
/// Tests building with 17 locales
/// NOTE: Roblox only supports 17 locales, so we test with all 17 repeated
/// Target: Complete successfully without crashes
#[test]
#[ignore]
fn test_100_locales() {
let temp = tempfile::TempDir::new().unwrap();
// Use actual Roblox locales (17 total), repeat them to get more
let roblox_locales = vec![
"en", "es", "fr", "de", "it", "pt", "ru", "ja", "ko", "zh-cn", "zh-tw", "id", "tr", "vi",
"th", "pl", "uk",
];
// Create config with all 17 Roblox locales
let config = format!(
r#"base_locale: en
supported_locales:
{}
input_directory: translations
output_directory: output
"#,
roblox_locales
.iter()
.map(|l| format!(" - {}", l))
.collect::<Vec<_>>()
.join("\n")
);
fs::write(temp.path().join("slang-roblox.yaml"), config).unwrap();
fs::create_dir(temp.path().join("translations")).unwrap();
// Create translation files for each locale
let json = r#"{"ui": {"button": "Buy"}}"#;
for locale in &roblox_locales {
fs::write(
temp.path().join(format!("translations/{}.json", locale)),
json,
)
.unwrap();
}
// Build
let start = Instant::now();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
let duration = start.elapsed();
// Verify output
common::assert_file_exists(&temp.path().join("output/Translations.lua"));
println!(
"✓ Built {} Roblox locales in {:?}",
roblox_locales.len(),
duration
);
}
/// Tests parsing a 1MB+ translation file
/// Target: Complete without memory issues
#[test]
#[ignore]
fn test_1mb_translation_file() {
let temp = common::create_test_project();
// Generate large translation file (>1MB)
let mut translations = serde_json::Map::new();
// Create many translations with long values
for i in 0..5000 {
let key = format!("key_{}", i);
// Each value is ~200 characters
let value = format!(
"This is a very long translation value number {} that contains a lot of text \
to make the file size larger. Lorem ipsum dolor sit amet, consectetur adipiscing \
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
i
);
translations.insert(key, serde_json::Value::String(value));
}
let json = serde_json::to_string_pretty(&translations).unwrap();
let file_size = json.len();
assert!(
file_size > 1_000_000,
"File size is {} bytes, expected >1MB",
file_size
);
fs::write(temp.path().join("translations/en.json"), &json).unwrap();
// Build
let start = Instant::now();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
let duration = start.elapsed();
println!(
"✓ Parsed {:.2}MB file in {:?}",
file_size as f64 / 1_000_000.0,
duration
);
}
/// Tests with deeply nested structure (20 levels)
/// Target: Complete without stack overflow
#[test]
#[ignore]
fn test_very_deep_nesting() {
let temp = common::create_test_project();
// Create 20-level deep nesting
let mut json = String::from("{");
for i in 0..20 {
json.push_str(&format!("\"level_{}\": {{", i));
}
json.push_str("\"final\": \"Deep value\"");
for _ in 0..20 {
json.push('}');
}
json.push('}');
fs::write(temp.path().join("translations/en.json"), json).unwrap();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
println!("✓ Handled 20-level deep nesting");
}
// ====================================================================================
// Rapid Operations Tests
// ====================================================================================
/// Tests rapid file changes in watch mode
/// Target: Handle 100 rapid changes without crashes
#[test]
#[ignore]
fn test_rapid_file_changes() {
use std::process::{Command as StdCommand, Stdio};
let temp = common::create_test_project_with_translations();
// Get the binary path
let bin_path = assert_cmd::cargo::cargo_bin("roblox-slang");
// Start watch mode in background using std::process::Command
let mut child = StdCommand::new(bin_path)
.current_dir(&temp)
.arg("build")
.arg("--watch")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("Failed to start watch mode");
// Wait for watch mode to start
std::thread::sleep(Duration::from_secs(2));
// Make 100 rapid file changes
for i in 0..100 {
let json = format!(r#"{{"ui": {{"button": "Buy {}"}}}}"#, i);
fs::write(temp.path().join("translations/en.json"), json).unwrap();
// Small delay between changes
std::thread::sleep(Duration::from_millis(50));
}
// Wait for final rebuild
std::thread::sleep(Duration::from_secs(2));
// Stop watch mode
child.kill().expect("Failed to kill watch process");
child.wait().expect("Failed to wait for process");
// Verify final output exists
common::assert_file_exists(&temp.path().join("output/Translations.lua"));
println!("✓ Handled 100 rapid file changes");
}
/// Tests building multiple times in succession
/// Target: Consistent performance across builds
#[test]
#[ignore]
fn test_repeated_builds() {
let temp = common::create_test_project_with_translations();
let mut durations = Vec::new();
// Build 10 times
for i in 0..10 {
let start = Instant::now();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
let duration = start.elapsed();
durations.push(duration);
println!("Build {}: {:?}", i + 1, duration);
}
// Calculate average
let avg = durations.iter().sum::<Duration>() / durations.len() as u32;
// Check consistency (no build should be >2x average)
for (i, duration) in durations.iter().enumerate() {
assert!(
*duration < avg * 2,
"Build {} took {:?}, more than 2x average {:?}",
i + 1,
duration,
avg
);
}
println!("✓ Average build time: {:?}", avg);
}
// ====================================================================================
// Memory Stress Tests
// ====================================================================================
/// Tests with many translation files (all 17 Roblox locales)
/// Target: Handle multiple files efficiently
#[test]
#[ignore]
fn test_many_small_files() {
let temp = tempfile::TempDir::new().unwrap();
// Use all 17 Roblox locales
let locales = vec![
"en", "es", "fr", "de", "it", "pt", "ru", "ja", "ko", "zh-cn", "zh-tw", "id", "tr", "vi",
"th", "pl", "uk",
];
let config = format!(
r#"base_locale: en
supported_locales:
{}
input_directory: translations
output_directory: output
"#,
locales
.iter()
.map(|l| format!(" - {}", l))
.collect::<Vec<_>>()
.join("\n")
);
fs::write(temp.path().join("slang-roblox.yaml"), config).unwrap();
fs::create_dir(temp.path().join("translations")).unwrap();
// Create translation files for all locales
for locale in &locales {
let json = r#"{"ui": {"button": "Buy"}}"#;
fs::write(
temp.path().join(format!("translations/{}.json", locale)),
json,
)
.unwrap();
}
let start = Instant::now();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
let duration = start.elapsed();
println!(
"✓ Processed {} Roblox locale files in {:?}",
locales.len(),
duration
);
}
/// Tests with very long keys (500 characters)
/// Target: Handle without truncation or errors
#[test]
#[ignore]
fn test_very_long_keys() {
let temp = common::create_test_project();
// Create key with 500 characters
let long_key = "a".repeat(500);
let json = format!(
r#"{{
"{}": "Value"
}}"#,
long_key
);
fs::write(temp.path().join("translations/en.json"), json).unwrap();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
// Verify key in output
let luau = fs::read_to_string(temp.path().join("output/Translations.lua")).unwrap();
assert!(luau.len() > 500, "Output should contain long key");
println!("✓ Handled 500-character key");
}
/// Tests with very long values (10,000 characters)
/// Target: Handle without truncation or errors
#[test]
#[ignore]
fn test_very_long_values() {
let temp = common::create_test_project();
// Create value with 10,000 characters
let long_value = "Lorem ipsum ".repeat(1000);
let json = format!(
r#"{{
"ui": {{
"long_text": "{}"
}}
}}"#,
long_value
);
fs::write(temp.path().join("translations/en.json"), json).unwrap();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
// Verify value in output - check that output is large enough to contain the value
let luau = fs::read_to_string(temp.path().join("output/Translations.lua")).unwrap();
assert!(
luau.len() > 5000,
"Output should be large (contains long value), got {} bytes",
luau.len()
);
println!(
"✓ Handled 10,000-character value (output: {} bytes)",
luau.len()
);
}
// ====================================================================================
// Concurrent Operations Tests
// ====================================================================================
/// Tests building multiple projects concurrently
/// Target: No race conditions or conflicts
#[test]
#[ignore]
fn test_concurrent_builds() {
use std::thread;
let handles: Vec<_> = (0..10)
.map(|i| {
thread::spawn(move || {
let temp = common::create_test_project_with_translations();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
println!("✓ Concurrent build {} completed", i);
})
})
.collect();
// Wait for all builds to complete
for handle in handles {
handle.join().expect("Thread panicked");
}
println!("✓ All 10 concurrent builds completed");
}
// ====================================================================================
// Edge Case Combinations
// ====================================================================================
/// Tests combination of large dataset + many locales
/// Target: Complete without memory exhaustion
#[test]
#[ignore]
fn test_large_dataset_many_locales() {
let temp = tempfile::TempDir::new().unwrap();
// Use all 17 Roblox locales
let locales = vec![
"en", "es", "fr", "de", "it", "pt", "ru", "ja", "ko", "zh-cn", "zh-tw", "id", "tr", "vi",
"th", "pl", "uk",
];
let config = format!(
r#"base_locale: en
supported_locales:
{}
input_directory: translations
output_directory: output
"#,
locales
.iter()
.map(|l| format!(" - {}", l))
.collect::<Vec<_>>()
.join("\n")
);
fs::write(temp.path().join("slang-roblox.yaml"), config).unwrap();
fs::create_dir(temp.path().join("translations")).unwrap();
// 1000 translations per locale
let mut translations = serde_json::Map::new();
for i in 0..1000 {
let key = format!("key_{}", i);
let value = format!("Value {}", i);
translations.insert(key, serde_json::Value::String(value));
}
let json = serde_json::to_string_pretty(&translations).unwrap();
for locale in &locales {
fs::write(
temp.path().join(format!("translations/{}.json", locale)),
&json,
)
.unwrap();
}
let start = Instant::now();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
let duration = start.elapsed();
println!(
"✓ Built {} locales × 1000 translations = {} total in {:?}",
locales.len(),
locales.len() * 1000,
duration
);
}
/// Tests all features combined (overrides + plurals + params + contexts)
/// Target: All features work together correctly
#[test]
#[ignore]
fn test_all_features_combined() {
let temp = common::create_test_project();
// Complex translations with all features
let json = r#"{
"ui": {
"greeting": "Hello {name}!",
"items(plural)": {
"zero": "No items",
"one": "One item",
"other": "{count} items"
},
"button(context=save)": "Save",
"button(context=cancel)": "Cancel"
}
}"#;
fs::write(temp.path().join("translations/en.json"), json).unwrap();
// Overrides
let overrides = r#"overrides:
ui.greeting:
en: "Hi {name}!"
"#;
fs::write(temp.path().join("overrides.yaml"), overrides).unwrap();
Command::cargo_bin("roblox-slang")
.unwrap()
.current_dir(&temp)
.arg("build")
.assert()
.success();
println!("✓ All features combined successfully");
}