Skip to content

Commit 2960d7a

Browse files
authored
Merge pull request NixOS#12951 from Mic92/fix-race-condition
tests/functional/repl: fix race condition
2 parents 3ff19be + 1de951d commit 2960d7a

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

tests/functional/repl.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,32 @@ foo + baz
162162
# - Modify the flake
163163
# - Re-eval it
164164
# - Check that the result has changed
165-
replResult=$( (
166-
echo "changingThing"
167-
sleep 1 # Leave the repl the time to eval 'foo'
165+
mkfifo repl_fifo
166+
nix repl ./flake --experimental-features 'flakes' < repl_fifo > repl_output 2>&1 &
167+
repl_pid=$!
168+
exec 3>repl_fifo # Open fifo for writing
169+
echo "changingThing" >&3
170+
for i in $(seq 1 1000); do
171+
if grep -q "beforeChange" repl_output; then
172+
break
173+
fi
174+
cat repl_output
175+
sleep 0.1
176+
done
177+
if [[ "$i" -eq 100 ]]; then
178+
echo "Timed out waiting for beforeChange"
179+
exit 1
180+
fi
181+
168182
sed -i 's/beforeChange/afterChange/' flake/flake.nix
169-
echo ":reload"
170-
echo "changingThing"
171-
) | nix repl ./flake --experimental-features 'flakes')
172-
echo "$replResult" | grepQuiet -s beforeChange
173-
echo "$replResult" | grepQuiet -s afterChange
183+
184+
# Send reload and second command
185+
echo ":reload" >&3
186+
echo "changingThing" >&3
187+
echo "exit" >&3
188+
exec 3>&- # Close fifo
189+
wait $repl_pid # Wait for process to finish
190+
grep -q "afterChange" repl_output
174191

175192
# Test recursive printing and formatting
176193
# Normal output should print attributes in lexicographical order non-recursively

0 commit comments

Comments
 (0)