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
#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used)]
#![allow(unused_imports)]
use super::super::ast::Redirect;
use super::super::lexer::Lexer;
use super::super::parser::BashParser;
use super::super::semantic::SemanticAnalyzer;
use super::super::*;
#[test]
fn test_JOB_001_background_jobs_race_conditions() {
// DOCUMENTATION: Background job race conditions (5 critical race conditions)
//
// RACE 1: Output interleaving
// task1 &
// task2 &
// wait
// Output from task1 and task2 interleaves unpredictably
// PROBLEM: Cannot predict output order
//
// RACE 2: File access conflicts
// process file.txt &
// modify file.txt &
// wait
// Both jobs access file.txt simultaneously
// PROBLEM: Data corruption, race condition
//
// RACE 3: Resource contention
// heavy_task &
// heavy_task &
// heavy_task &
// wait
// All tasks compete for CPU/memory
// PROBLEM: Timing varies, non-deterministic performance
//
// RACE 4: Dependency violations
// generate_data &
// process_data & # Depends on generate_data output
// wait
// process_data may run before generate_data completes
// PROBLEM: Missing dependency, wrong results
//
// RACE 5: Exit status ambiguity
// task1 &
// task2 &
// wait
// If task1 fails, exit status is non-deterministic (depends on timing)
// PROBLEM: Cannot reliably check for errors
let race_conditions = r#"
# RACE 1: Output interleaving (non-deterministic)
echo "Task 1 starting" &
echo "Task 2 starting" &
wait
# Output order unpredictable:
# Task 1 starting
# Task 2 starting
# OR
# Task 2 starting
# Task 1 starting
# RACE 2: File access conflicts
{
echo "Process 1" >> output.txt
} &
{
echo "Process 2" >> output.txt
} &
wait
# output.txt content order unpredictable
# RACE 3: Resource contention
heavy_computation &
heavy_computation &
heavy_computation &
wait
# Timing varies based on system load
# RACE 4: Dependency violations
generate_input_data &
process_input_data & # Depends on generate_input_data!
wait
# process_input_data may run before data is ready
# RACE 5: Exit status ambiguity
false & # Fails immediately
true & # Succeeds
wait $! # Which job's exit status?
# Non-deterministic error handling
"#;
let mut lexer = Lexer::new(race_conditions);
if let Ok(tokens) = lexer.tokenize() {
assert!(
!tokens.is_empty(),
"Race conditions should tokenize successfully"
);
let _ = tokens;
}
// Background jobs introduce RACE CONDITIONS
// bashrs FORBIDS background jobs to prevent races
// CRITICAL: Sequential execution is deterministic
}
#[test]
fn test_JOB_001_background_jobs_testing_implications() {
// DOCUMENTATION: Background job testing implications (4 critical issues)
//
// ISSUE 1: Cannot assert on intermediate state
// test_background_job() {
// process_data &
// # Cannot assert on process_data state here (still running!)
// wait
// }
// PROBLEM: Test cannot check state while background job runs
//
// ISSUE 2: Flaky tests due to timing
// test_parallel_processing() {
// task1 & task2 & wait
// # Test may pass/fail depending on task completion order
// }
// PROBLEM: Tests are non-deterministic
//
// ISSUE 3: Cannot isolate failures
// test_multiple_jobs() {
// job1 & job2 & job3 & wait
// # If one job fails, which one? Cannot tell!
// }
// PROBLEM: Cannot debug failures
//
// ISSUE 4: Cleanup issues
// test_background_cleanup() {
// long_task &
// # Test exits before long_task completes
// # Background job becomes orphan
// }
// PROBLEM: Background jobs outlive tests, pollute environment
let testing_implications = r#"
# BAD TEST: Cannot assert on intermediate state
test_bad_intermediate_state() {
process_data &
# PROBLEM: Cannot check if process_data is working
# Job is still running, state is unknown
wait
}
# GOOD TEST: Foreground execution (deterministic)
test_good_foreground() {
process_data
# Can assert on result after completion
[ -f output.txt ] || exit 1
}
# BAD TEST: Flaky due to timing
test_flaky_parallel() {
task1 &
task2 &
wait
# PROBLEM: Order of completion is non-deterministic
# Test may pass sometimes, fail others
}
# GOOD TEST: Sequential (deterministic)
test_deterministic_sequential() {
task1
task2
# Order is guaranteed, reproducible
[ -f task1.out ] || exit 1
[ -f task2.out ] || exit 1
}
# BAD TEST: Cannot isolate failures
test_cannot_isolate() {
job1 &
job2 &
job3 &
wait
# PROBLEM: If wait fails, which job failed?
}
# GOOD TEST: Isolated failures
test_isolated() {
job1 || exit 1
job2 || exit 2
job3 || exit 3
# Each job checked individually
}
"#;
let mut lexer = Lexer::new(testing_implications);
if let Ok(tokens) = lexer.tokenize() {
assert!(
!tokens.is_empty(),
"Testing implications should tokenize successfully"
);
let _ = tokens;
}
// Background jobs make tests NON-REPRODUCIBLE and FLAKY
// bashrs enforces DETERMINISTIC testing (foreground execution)
// NEVER use background jobs in test code
}